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



52
53
54
55
# File 'lib/knapsack_pro/config/env.rb', line 52

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

.branch_encryptedObject



153
154
155
# File 'lib/knapsack_pro/config/env.rb', line 153

def branch_encrypted
  ENV['KNAPSACK_PRO_BRANCH_ENCRYPTED']
end

.branch_encrypted?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/knapsack_pro/config/env.rb', line 157

def branch_encrypted?
  branch_encrypted == 'true'
end

.ci_env_for(env_name) ⇒ Object



258
259
260
# File 'lib/knapsack_pro/config/env.rb', line 258

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

.ci_node_build_idObject



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

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



19
20
21
22
23
# File 'lib/knapsack_pro/config/env.rb', line 19

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

.ci_node_retry_countObject



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

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



13
14
15
16
17
# File 'lib/knapsack_pro/config/env.rb', line 13

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

.commit_hashObject



47
48
49
50
# File 'lib/knapsack_pro/config/env.rb', line 47

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

.cucumber_queue_prefixObject



206
207
208
# File 'lib/knapsack_pro/config/env.rb', line 206

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

.detected_ciObject



262
263
264
265
266
267
268
269
270
# File 'lib/knapsack_pro/config/env.rb', line 262

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



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/knapsack_pro/config/env.rb', line 165

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



129
130
131
# File 'lib/knapsack_pro/config/env.rb', line 129

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

.fallback_mode_enabled?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/knapsack_pro/config/env.rb', line 133

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

.fixed_queue_splitObject



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/knapsack_pro/config/env.rb', line 189

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)


202
203
204
# File 'lib/knapsack_pro/config/env.rb', line 202

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

.fixed_test_suite_splitObject



181
182
183
# File 'lib/knapsack_pro/config/env.rb', line 181

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

.fixed_test_suite_split?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/knapsack_pro/config/env.rb', line 185

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

.log_dirObject



276
277
278
# File 'lib/knapsack_pro/config/env.rb', line 276

def log_dir
  ENV['KNAPSACK_PRO_LOG_DIR']
end

.log_levelObject



272
273
274
# File 'lib/knapsack_pro/config/env.rb', line 272

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

.masked_user_seatObject



67
68
69
70
71
# File 'lib/knapsack_pro/config/env.rb', line 67

def masked_user_seat
  return unless user_seat

  KnapsackPro::MaskString.call(user_seat)
end

.max_request_retriesObject



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

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

.modeObject



247
248
249
250
251
252
253
254
255
256
# File 'lib/knapsack_pro/config/env.rb', line 247

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

.modify_default_rspec_formattersObject



145
146
147
# File 'lib/knapsack_pro/config/env.rb', line 145

def modify_default_rspec_formatters
  ENV.fetch('KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS', true)
end

.modify_default_rspec_formatters?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/knapsack_pro/config/env.rb', line 149

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

.project_dirObject



57
58
59
60
# File 'lib/knapsack_pro/config/env.rb', line 57

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

.queue_idObject



121
122
123
# File 'lib/knapsack_pro/config/env.rb', line 121

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

.queue_recording_enabledObject



113
114
115
# File 'lib/knapsack_pro/config/env.rb', line 113

def queue_recording_enabled
  ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED']
end

.queue_recording_enabled?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/knapsack_pro/config/env.rb', line 117

def queue_recording_enabled?
  queue_recording_enabled == 'true'
end

.recording_enabledObject



101
102
103
# File 'lib/knapsack_pro/config/env.rb', line 101

def recording_enabled
  ENV['KNAPSACK_PRO_RECORDING_ENABLED']
end

.recording_enabled?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/knapsack_pro/config/env.rb', line 105

def recording_enabled?
  recording_enabled == 'true'
end

.regular_mode?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/knapsack_pro/config/env.rb', line 109

def regular_mode?
  recording_enabled?
end

.repository_adapterObject



97
98
99
# File 'lib/knapsack_pro/config/env.rb', line 97

def repository_adapter
  ENV['KNAPSACK_PRO_REPOSITORY_ADAPTER']
end

.rspec_split_by_test_examplesObject



210
211
212
# File 'lib/knapsack_pro/config/env.rb', line 210

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)


214
215
216
# File 'lib/knapsack_pro/config/env.rb', line 214

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

.rspec_test_example_detector_prefixObject



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

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

.saltObject



161
162
163
# File 'lib/knapsack_pro/config/env.rb', line 161

def salt
  required_env('KNAPSACK_PRO_SALT')
end

.set_test_runner_adapter(adapter_class) ⇒ Object



284
285
286
# File 'lib/knapsack_pro/config/env.rb', line 284

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

.slow_test_file_patternObject



77
78
79
# File 'lib/knapsack_pro/config/env.rb', line 77

def slow_test_file_pattern
  ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN']
end

.subset_queue_idObject



125
126
127
# File 'lib/knapsack_pro/config/env.rb', line 125

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

.test_dirObject



93
94
95
# File 'lib/knapsack_pro/config/env.rb', line 93

def test_dir
  ENV['KNAPSACK_PRO_TEST_DIR']
end

.test_file_exclude_patternObject



81
82
83
# File 'lib/knapsack_pro/config/env.rb', line 81

def test_file_exclude_pattern
  ENV['KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN']
end

.test_file_listObject



85
86
87
# File 'lib/knapsack_pro/config/env.rb', line 85

def test_file_list
  ENV['KNAPSACK_PRO_TEST_FILE_LIST']
end

.test_file_list_source_fileObject



89
90
91
# File 'lib/knapsack_pro/config/env.rb', line 89

def test_file_list_source_file
  ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE']
end

.test_file_patternObject



73
74
75
# File 'lib/knapsack_pro/config/env.rb', line 73

def test_file_pattern
  ENV['KNAPSACK_PRO_TEST_FILE_PATTERN']
end

.test_files_encryptedObject



137
138
139
# File 'lib/knapsack_pro/config/env.rb', line 137

def test_files_encrypted
  ENV['KNAPSACK_PRO_TEST_FILES_ENCRYPTED']
end

.test_files_encrypted?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/knapsack_pro/config/env.rb', line 141

def test_files_encrypted?
  test_files_encrypted == 'true'
end

.test_runner_adapterObject



280
281
282
# File 'lib/knapsack_pro/config/env.rb', line 280

def test_runner_adapter
  ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER']
end

.test_suite_tokenObject



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

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



239
240
241
# File 'lib/knapsack_pro/config/env.rb', line 239

def test_suite_token_cucumber
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER']
end

.test_suite_token_minitestObject



231
232
233
# File 'lib/knapsack_pro/config/env.rb', line 231

def test_suite_token_minitest
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST']
end

.test_suite_token_rspecObject



227
228
229
# File 'lib/knapsack_pro/config/env.rb', line 227

def test_suite_token_rspec
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC']
end

.test_suite_token_spinachObject



243
244
245
# File 'lib/knapsack_pro/config/env.rb', line 243

def test_suite_token_spinach
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH']
end

.test_suite_token_test_unitObject



235
236
237
# File 'lib/knapsack_pro/config/env.rb', line 235

def test_suite_token_test_unit
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT']
end

.user_seatObject



62
63
64
65
# File 'lib/knapsack_pro/config/env.rb', line 62

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