Module: Moonshot::EnvironmentParser

Defined in:
lib/moonshot/environment_parser.rb

Overview

This module supports massaging of the incoming environment.

Class Method Summary collapse

Class Method Details

.parse(log) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/moonshot/environment_parser.rb', line 6

def self.parse(log)
  log.debug('Starting to parse environment.')

  # Ops Bastion servers export AWS_CREDENTIAL_FILE, instead of key and
  # secret keys, so we support both here. We then set them as environment
  # variables which will be respected by aws-sdk.
  parse_credentials_file if ENV.key?('AWS_CREDENTIAL_FILE')

  # Ensure the aws-sdk is able to find a set of credentials.
  creds = Aws::CredentialProviderChain.new(OpenStruct.new).resolve

  raise 'Unable to find AWS credentials!' unless creds

  log.debug('Environment parsing complete.')
end

.parse_credentials_fileObject



22
23
24
25
26
27
28
29
30
# File 'lib/moonshot/environment_parser.rb', line 22

def self.parse_credentials_file
  File.open(ENV.fetch('AWS_CREDENTIAL_FILE')).each_line do |line|
    key, val = line.chomp.split('=')
    case key
    when 'AWSAccessKeyId' then ENV['AWS_ACCESS_KEY_ID'] = val
    when 'AWSSecretKey'   then ENV['AWS_SECRET_ACCESS_KEY'] = val
    end
  end
end