Class: OpzWorks::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/opzworks/config.rb', line 15

def initialize
  aws_config_file = ENV['AWS_CONFIG_FILE'] || "#{ENV['HOME']}/.aws/config"
  opzworks_config_file = ENV['OPZWORKS_CONFIG_FILE'] || "#{ENV['HOME']}/.opzworks/config"

  # abort unless required conditions are met
  abort "AWS config file #{aws_config_file} not found, exiting!".foreground(:red) unless File.exist? aws_config_file
  abort "Opzworks config file #{opzworks_config_file} not found, exiting!".foreground(:red) unless File.exist? opzworks_config_file
  aws_ini = IniFile.load(aws_config_file)
  opzworks_ini = IniFile.load(opzworks_config_file)

  @opzworks_profile = ENV['OPZWORKS_PROFILE'] || 'default'
  abort "Could not find [#{@opzworks_profile}] config block in #{opzworks_config_file}, exiting!".foreground(:red) if opzworks_ini[@opzworks_profile].empty?

  # set the region and the profile we want to pick up from ~/.aws/credentials
  @aws_profile = ENV['AWS_PROFILE'] || 'default'
  abort "Could not find [#{@aws_profile}] config block in #{aws_config_file}, exiting!".foreground(:red) if aws_ini[@aws_profile].empty?
  @aws_region = ENV['AWS_REGION'] || aws_ini[@aws_profile]['region']

  @ssh_user_name =
    opzworks_ini[@opzworks_profile]['ssh-user-name'].strip unless opzworks_ini[@opzworks_profile]['ssh-user-name'].nil?
  @berks_repository_path =
    opzworks_ini[@opzworks_profile]['berks-repository-path'].strip unless opzworks_ini[@opzworks_profile]['berks-repository-path'].nil?
  @berks_base_path =
    opzworks_ini[@opzworks_profile]['berks-base-path'].strip unless opzworks_ini[@opzworks_profile]['berks-base-path'].nil?
  @berks_s3_bucket =
    opzworks_ini[@opzworks_profile]['berks-s3-bucket'].strip unless opzworks_ini[@opzworks_profile]['berks-s3-bucket'].nil?
  @berks_tarball_name =
    opzworks_ini[@opzworks_profile]['berks-tarball-name'].strip unless opzworks_ini[@opzworks_profile]['berks-tarball-name'].nil?
  @berks_github_org =
    opzworks_ini[@opzworks_profile]['berks-github-org'].strip unless opzworks_ini[@opzworks_profile]['berks-github-org'].nil?
end

Instance Attribute Details

#aws_profileObject (readonly)

Returns the value of attribute aws_profile.



12
13
14
# File 'lib/opzworks/config.rb', line 12

def aws_profile
  @aws_profile
end

#aws_regionObject (readonly)

Returns the value of attribute aws_region.



12
13
14
# File 'lib/opzworks/config.rb', line 12

def aws_region
  @aws_region
end

#berks_base_pathObject (readonly)

Returns the value of attribute berks_base_path.



12
13
14
# File 'lib/opzworks/config.rb', line 12

def berks_base_path
  @berks_base_path
end

#berks_github_orgObject (readonly)

Returns the value of attribute berks_github_org.



12
13
14
# File 'lib/opzworks/config.rb', line 12

def berks_github_org
  @berks_github_org
end

#berks_repository_pathObject (readonly)

Returns the value of attribute berks_repository_path.



12
13
14
# File 'lib/opzworks/config.rb', line 12

def berks_repository_path
  @berks_repository_path
end

#berks_s3_bucketObject (readonly)

Returns the value of attribute berks_s3_bucket.



12
13
14
# File 'lib/opzworks/config.rb', line 12

def berks_s3_bucket
  @berks_s3_bucket
end

#berks_tarball_nameObject (readonly)

Returns the value of attribute berks_tarball_name.



12
13
14
# File 'lib/opzworks/config.rb', line 12

def berks_tarball_name
  @berks_tarball_name
end

#ssh_user_nameObject (readonly)

Returns the value of attribute ssh_user_name.



12
13
14
# File 'lib/opzworks/config.rb', line 12

def ssh_user_name
  @ssh_user_name
end