Class: AwsAuditor::AWSSDK

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_auditor/aws.rb

Constant Summary collapse

FILE_NAMES =
%w[.aws.yml]

Class Method Summary collapse

Class Method Details

.config_pathObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/aws_auditor/aws.rb', line 35

def self.config_path
  if filepath = FILE_NAMES.detect {|filename| File.exists?(filename)}
    File.join(Dir.pwd, filepath)
  else
    old_dir = Dir.pwd
    Dir.chdir('..')
    if old_dir != Dir.pwd
      config_path
    else
      puts "Could not find #{FILE_NAMES.join(' or ')}"; exit
    end
  end
end

.configuration(environment) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/aws_auditor/aws.rb', line 13

def self.configuration(environment)
  @environment = environment
  load_config
  AWS.config({
    :access_key_id => @config[:access_key_id],
    :secret_access_key => @config[:secret_access_key],
    :region => @config[:region]
  })
end

.load_configObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/aws_auditor/aws.rb', line 23

def self.load_config
  return @config if @config
  @config = AwsConfig[YAML.load_file(config_path)]
  if @config.has_key? @environment
    @config = @config[@environment]
  else
    puts "Could not find AWS credentials for #{@environment} environment"; exit
  end
  @config[:region] ||= 'us-east-1'
  @config
end