Class: KnapsackPro::Config::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack_pro/config/env.rb

Constant Summary collapse

LOG_LEVELS =
{
  'fatal'  => ::Logger::FATAL,
  'error'  => ::Logger::ERROR,
  'warn'  => ::Logger::WARN,
  'info'  => ::Logger::INFO,
  'debug' => ::Logger::DEBUG,
}

Class Method Summary collapse

Class Method Details

.branchObject



54
55
56
57
# File 'lib/knapsack_pro/config/env.rb', line 54

def branch
  ENV['KNAPSACK_PRO_BRANCH'] ||
    ci_env_for(:branch)
end

.branch_encryptedObject



147
148
149
# File 'lib/knapsack_pro/config/env.rb', line 147

def branch_encrypted
  ENV['KNAPSACK_PRO_BRANCH_ENCRYPTED']
end

.branch_encrypted?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/knapsack_pro/config/env.rb', line 151

def branch_encrypted?
  branch_encrypted == 'true'
end

.ci?Boolean

Returns:

  • (Boolean)


286
287
288
289
# File 'lib/knapsack_pro/config/env.rb', line 286

def ci?
  ENV.fetch('CI', 'false').downcase == 'true' ||
    detected_ci != KnapsackPro::Config::CI::Base
end

.ci_env_for(env_name) ⇒ Object



252
253
254
# File 'lib/knapsack_pro/config/env.rb', line 252

def ci_env_for(env_name)
  detected_ci.new.send(env_name)
end

.ci_node_build_idObject



27
28
29
30
31
32
# File 'lib/knapsack_pro/config/env.rb', line 27

def ci_node_build_id
  env_name = 'KNAPSACK_PRO_CI_NODE_BUILD_ID'
  ENV[env_name] ||
    ci_env_for(:node_build_id) ||
    raise("Missing environment variable #{env_name}. Read more at #{KnapsackPro::Urls::KNAPSACK_PRO_CI_NODE_BUILD_ID}")
end

.ci_node_indexObject



21
22
23
24
25
# File 'lib/knapsack_pro/config/env.rb', line 21

def ci_node_index
  (ENV['KNAPSACK_PRO_CI_NODE_INDEX'] ||
    ci_env_for(:node_index) ||
    0).to_i
end

.ci_node_retry_countObject



34
35
36
37
38
39
40
# File 'lib/knapsack_pro/config/env.rb', line 34

def ci_node_retry_count
  (
    ENV['KNAPSACK_PRO_CI_NODE_RETRY_COUNT'] ||
    ci_env_for(:node_retry_count) ||
    0
  ).to_i
end

.ci_node_totalObject



15
16
17
18
19
# File 'lib/knapsack_pro/config/env.rb', line 15

def ci_node_total
  (ENV['KNAPSACK_PRO_CI_NODE_TOTAL'] ||
    ci_env_for(:node_total) ||
    1).to_i
end

.ci_providerObject



266
267
268
# File 'lib/knapsack_pro/config/env.rb', line 266

def ci_provider
  detected_ci.new.ci_provider
end

.commit_hashObject



49
50
51
52
# File 'lib/knapsack_pro/config/env.rb', line 49

def commit_hash
  ENV['KNAPSACK_PRO_COMMIT_HASH'] ||
    ci_env_for(:commit_hash)
end

.cucumber_queue_prefixObject



200
201
202
# File 'lib/knapsack_pro/config/env.rb', line 200

def cucumber_queue_prefix
  ENV.fetch('KNAPSACK_PRO_CUCUMBER_QUEUE_PREFIX', 'bundle exec')
end

.detected_ciObject



256
257
258
259
260
261
262
263
264
# File 'lib/knapsack_pro/config/env.rb', line 256

def detected_ci
  detected = KnapsackPro::Config::CI.constants.map do |constant|
    Object.const_get("KnapsackPro::Config::CI::#{constant}").new.detected
  end
    .compact
    .first

  detected || KnapsackPro::Config::CI::Base
end

.endpointObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/knapsack_pro/config/env.rb', line 159

def endpoint
  env_name = 'KNAPSACK_PRO_ENDPOINT'
  return ENV[env_name] if ENV[env_name]

  case mode
  when :development
    'http://api.knapsackpro.test:3000'
  when :test
    'https://api-staging.knapsackpro.com'
  when :production
    'https://api.knapsackpro.com'
  else
    required_env(env_name)
  end
end

.fallback_mode_enabledObject



131
132
133
# File 'lib/knapsack_pro/config/env.rb', line 131

def fallback_mode_enabled
  ENV.fetch('KNAPSACK_PRO_FALLBACK_MODE_ENABLED', true)
end

.fallback_mode_enabled?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/knapsack_pro/config/env.rb', line 135

def fallback_mode_enabled?
  fallback_mode_enabled.to_s == 'true'
end

.fixed_queue_splitObject



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/knapsack_pro/config/env.rb', line 183

def fixed_queue_split
  @fixed_queue_split ||= begin
    env_name = 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT'
    computed = ENV.fetch(env_name, ci_env_for(:fixed_queue_split)).to_s

    if !ENV.key?(env_name)
      KnapsackPro.logger.info("#{env_name} is not set. Using default value: #{computed}. Learn more at #{KnapsackPro::Urls::FIXED_QUEUE_SPLIT}")
    end

    computed
  end
end

.fixed_queue_split?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/knapsack_pro/config/env.rb', line 196

def fixed_queue_split?
  fixed_queue_split.to_s == 'true'
end

.fixed_test_suite_splitObject



175
176
177
# File 'lib/knapsack_pro/config/env.rb', line 175

def fixed_test_suite_split
  ENV.fetch('KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT', true)
end

.fixed_test_suite_split?Boolean

Returns:

  • (Boolean)


179
180
181
# File 'lib/knapsack_pro/config/env.rb', line 179

def fixed_test_suite_split?
  fixed_test_suite_split.to_s == 'true'
end

.log_dirObject



274
275
276
# File 'lib/knapsack_pro/config/env.rb', line 274

def log_dir
  ENV['KNAPSACK_PRO_LOG_DIR']
end

.log_levelObject



270
271
272
# File 'lib/knapsack_pro/config/env.rb', line 270

def log_level
  LOG_LEVELS[ENV['KNAPSACK_PRO_LOG_LEVEL'].to_s.downcase] || ::Logger::INFO
end

.masked_user_seatObject



69
70
71
72
73
# File 'lib/knapsack_pro/config/env.rb', line 69

def masked_user_seat
  return unless user_seat

  KnapsackPro::MaskString.call(user_seat)
end

.max_request_retriesObject



42
43
44
45
46
47
# File 'lib/knapsack_pro/config/env.rb', line 42

def max_request_retries
  number = ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES']
  if number
    number.to_i
  end
end

.modeObject



241
242
243
244
245
246
247
248
249
250
# File 'lib/knapsack_pro/config/env.rb', line 241

def mode
  mode = ENV['KNAPSACK_PRO_MODE']
  return :production if mode.nil?
  mode = mode.to_sym
  if [:development, :test, :production].include?(mode)
    mode
  else
    raise ArgumentError.new('Wrong mode name')
  end
end

.project_dirObject



59
60
61
62
# File 'lib/knapsack_pro/config/env.rb', line 59

def project_dir
  ENV['KNAPSACK_PRO_PROJECT_DIR'] ||
    ci_env_for(:project_dir)
end

.queue_idObject



123
124
125
# File 'lib/knapsack_pro/config/env.rb', line 123

def queue_id
  ENV['KNAPSACK_PRO_QUEUE_ID'] || raise('Missing Queue ID')
end

.queue_recording_enabledObject



115
116
117
# File 'lib/knapsack_pro/config/env.rb', line 115

def queue_recording_enabled
  ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED']
end

.queue_recording_enabled?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/knapsack_pro/config/env.rb', line 119

def queue_recording_enabled?
  queue_recording_enabled == 'true'
end

.recording_enabledObject



103
104
105
# File 'lib/knapsack_pro/config/env.rb', line 103

def recording_enabled
  ENV['KNAPSACK_PRO_RECORDING_ENABLED']
end

.recording_enabled?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/knapsack_pro/config/env.rb', line 107

def recording_enabled?
  recording_enabled == 'true'
end

.regular_mode?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/knapsack_pro/config/env.rb', line 111

def regular_mode?
  recording_enabled?
end

.repository_adapterObject



99
100
101
# File 'lib/knapsack_pro/config/env.rb', line 99

def repository_adapter
  ENV['KNAPSACK_PRO_REPOSITORY_ADAPTER']
end

.rspec_split_by_test_examplesObject



204
205
206
# File 'lib/knapsack_pro/config/env.rb', line 204

def rspec_split_by_test_examples
  ENV.fetch('KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES', false)
end

.rspec_split_by_test_examples?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/knapsack_pro/config/env.rb', line 208

def rspec_split_by_test_examples?
  rspec_split_by_test_examples.to_s == 'true'
end

.rspec_test_example_detector_prefixObject



212
213
214
# File 'lib/knapsack_pro/config/env.rb', line 212

def rspec_test_example_detector_prefix
  ENV.fetch('KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIX', 'bundle exec')
end

.saltObject



155
156
157
# File 'lib/knapsack_pro/config/env.rb', line 155

def salt
  required_env('KNAPSACK_PRO_SALT')
end

.set_test_runner_adapter(adapter_class) ⇒ Object



282
283
284
# File 'lib/knapsack_pro/config/env.rb', line 282

def set_test_runner_adapter(adapter_class)
  ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER'] = adapter_class.to_s.split('::').last
end

.slow_test_file_patternObject



79
80
81
# File 'lib/knapsack_pro/config/env.rb', line 79

def slow_test_file_pattern
  ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN']
end

.subset_queue_idObject



127
128
129
# File 'lib/knapsack_pro/config/env.rb', line 127

def subset_queue_id
  ENV['KNAPSACK_PRO_SUBSET_QUEUE_ID'] || raise('Missing Subset Queue ID')
end

.test_dirObject



95
96
97
# File 'lib/knapsack_pro/config/env.rb', line 95

def test_dir
  ENV['KNAPSACK_PRO_TEST_DIR']
end

.test_file_exclude_patternObject



83
84
85
# File 'lib/knapsack_pro/config/env.rb', line 83

def test_file_exclude_pattern
  ENV['KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN']
end

.test_file_listObject



87
88
89
# File 'lib/knapsack_pro/config/env.rb', line 87

def test_file_list
  ENV['KNAPSACK_PRO_TEST_FILE_LIST']
end

.test_file_list_source_fileObject



91
92
93
# File 'lib/knapsack_pro/config/env.rb', line 91

def test_file_list_source_file
  ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE']
end

.test_file_patternObject



75
76
77
# File 'lib/knapsack_pro/config/env.rb', line 75

def test_file_pattern
  ENV['KNAPSACK_PRO_TEST_FILE_PATTERN']
end

.test_files_encryptedObject



139
140
141
# File 'lib/knapsack_pro/config/env.rb', line 139

def test_files_encrypted
  ENV['KNAPSACK_PRO_TEST_FILES_ENCRYPTED']
end

.test_files_encrypted?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/knapsack_pro/config/env.rb', line 143

def test_files_encrypted?
  test_files_encrypted == 'true'
end

.test_runner_adapterObject



278
279
280
# File 'lib/knapsack_pro/config/env.rb', line 278

def test_runner_adapter
  ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER']
end

.test_suite_tokenObject



216
217
218
219
# File 'lib/knapsack_pro/config/env.rb', line 216

def test_suite_token
  env_name = 'KNAPSACK_PRO_TEST_SUITE_TOKEN'
  ENV[env_name] || raise("Missing environment variable #{env_name}. You should set environment variable like #{env_name}_RSPEC (note there is suffix _RSPEC at the end). knapsack_pro gem will set #{env_name} based on #{env_name}_RSPEC value. If you use other test runner than RSpec then use proper suffix.")
end

.test_suite_token_cucumberObject



233
234
235
# File 'lib/knapsack_pro/config/env.rb', line 233

def test_suite_token_cucumber
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER']
end

.test_suite_token_minitestObject



225
226
227
# File 'lib/knapsack_pro/config/env.rb', line 225

def test_suite_token_minitest
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST']
end

.test_suite_token_rspecObject



221
222
223
# File 'lib/knapsack_pro/config/env.rb', line 221

def test_suite_token_rspec
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC']
end

.test_suite_token_spinachObject



237
238
239
# File 'lib/knapsack_pro/config/env.rb', line 237

def test_suite_token_spinach
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH']
end

.test_suite_token_test_unitObject



229
230
231
# File 'lib/knapsack_pro/config/env.rb', line 229

def test_suite_token_test_unit
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT']
end

.user_seatObject



64
65
66
67
# File 'lib/knapsack_pro/config/env.rb', line 64

def user_seat
  ENV['KNAPSACK_PRO_USER_SEAT'] ||
    ci_env_for(:user_seat)
end