Module: Gitlab::QA::Runtime::Env

Extended by:
Env
Included in:
Env
Defined in:
lib/gitlab/qa/runtime/env.rb

Constant Summary collapse

ENV_VARIABLES =
{
  'GITLAB_USERNAME' => :user_username,
  'GITLAB_PASSWORD' => :user_password,
  'GITLAB_LDAP_USERNAME' => :ldap_username,
  'GITLAB_LDAP_PASSWORD' => :ldap_password,
  'GITLAB_USER_TYPE' => :user_type,
  'GITLAB_SANDBOX_NAME' => :gitlab_sandbox_name,
  'GITLAB_QA_ACCESS_TOKEN' => :qa_access_token,
  'GITHUB_ACCESS_TOKEN' => :github_access_token,
  'GITLAB_URL' => :gitlab_url,
  'EE_LICENSE' => :ee_license,
  'GCLOUD_ACCOUNT_EMAIL' => :gcloud_account_email,
  'GCLOUD_ACCOUNT_KEY' => :gcloud_account_key,
  'CLOUDSDK_CORE_PROJECT' => :cloudsdk_core_project,
  'GCLOUD_ZONE' => :gcloud_zone
}.freeze

Instance Method Summary collapse

Instance Method Details

#dev_access_token_variable ⇒ Object



38
39
40
# File 'lib/gitlab/qa/runtime/env.rb', line 38

def dev_access_token_variable
  env_value_if_defined('GITLAB_QA_DEV_ACCESS_TOKEN')
end

#host_artifacts_dir ⇒ Object



42
43
44
# File 'lib/gitlab/qa/runtime/env.rb', line 42

def host_artifacts_dir
  @host_artifacts_dir ||= File.join(ENV['QA_ARTIFACTS_DIR'] || '/tmp/gitlab-qa', Runtime::Env.run_id)
end

#qa_access_token ⇒ Object



34
35
36
# File 'lib/gitlab/qa/runtime/env.rb', line 34

def qa_access_token
  ENV['GITLAB_QA_ACCESS_TOKEN']
end

#require_kubernetes_environment! ⇒ Object



77
78
79
80
81
# File 'lib/gitlab/qa/runtime/env.rb', line 77

def require_kubernetes_environment!
  %w[GCLOUD_ACCOUNT_EMAIL GCLOUD_ACCOUNT_KEY CLOUDSDK_CORE_PROJECT GCLOUD_ZONE].each do |env_key|
    raise ArgumentError, "Environment variable #{env_key} must be set to run kubernetes specs" unless ENV.key?(env_key)
  end
end

#require_license! ⇒ Object

Raises:

  • (ArgumentError)


59
60
61
62
63
# File 'lib/gitlab/qa/runtime/env.rb', line 59

def require_license!
  return if ENV.include?('EE_LICENSE')

  raise ArgumentError, 'GitLab License is not available. Please load a license into EE_LICENSE env variable.'
end

#require_no_license! ⇒ Object

Raises:

  • (ArgumentError)


65
66
67
68
69
# File 'lib/gitlab/qa/runtime/env.rb', line 65

def require_no_license!
  return unless ENV.include?('EE_LICENSE')

  raise ArgumentError, "Unexpected EE_LICENSE provided. Please unset it to continue."
end

#require_qa_access_token! ⇒ Object

Raises:

  • (ArgumentError)


71
72
73
74
75
# File 'lib/gitlab/qa/runtime/env.rb', line 71

def require_qa_access_token!
  return unless ENV['GITLAB_QA_ACCESS_TOKEN'].to_s.strip.empty?

  raise ArgumentError, "Please provide GITLAB_QA_ACCESS_TOKEN"
end

#run_id ⇒ Object



30
31
32
# File 'lib/gitlab/qa/runtime/env.rb', line 30

def run_id
  @run_id ||= "gitlab-qa-run-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}-#{SecureRandom.hex(4)}"
end

#variables ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gitlab/qa/runtime/env.rb', line 46

def variables
  vars = {}

  ENV_VARIABLES.each do |name, attribute|
    # Variables that are overriden in the environment take precedence
    # over the defaults specified by the QA runtime.
    value = env_value_if_defined(name) || send(attribute) # rubocop:disable GitlabSecurity/PublicSend
    vars[name] = value if value
  end

  vars
end