Class: Bosh::AwsCliPlugin::AwsConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh_cli_plugin_aws/aws_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, env = ENV) ⇒ AwsConfig

Returns a new instance of AwsConfig.



8
9
10
11
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 8

def initialize(filename, env = ENV)
  @filename = filename
  @env = env
end

Instance Method Details

#aws_access_key_idObject



28
29
30
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 28

def aws_access_key_id
  fetch_from_env("BOSH_AWS_ACCESS_KEY_ID")
end

#aws_regionObject



32
33
34
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 32

def aws_region
  @env.fetch('BOSH_AWS_REGION', 'us-east-1')
end

#aws_secret_access_keyObject



24
25
26
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 24

def aws_secret_access_key
  fetch_from_env("BOSH_AWS_SECRET_ACCESS_KEY")
end

#cache_access_key_idObject



114
115
116
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 114

def cache_access_key_id
  @env["BOSH_CACHE_ACCESS_KEY_ID"]
end

#cache_bucket_nameObject



126
127
128
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 126

def cache_bucket_name
  @env.fetch("BOSH_CACHE_BUCKET_NAME", "bosh-global-package-cache")
end

#cache_secret_access_keyObject



118
119
120
121
122
123
124
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 118

def cache_secret_access_key
  unless has_package_cache_configuration?
    raise ConfigurationInvalid, "Missing ENV variable BOSH_CACHE_ACCESS_KEY_ID"
  end

  fetch_from_env("BOSH_CACHE_SECRET_ACCESS_KEY")
end

#configurationObject



13
14
15
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 13

def configuration
  load_configuration(File.read(@filename))
end

#director_ssl_cert_fileObject



106
107
108
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 106

def director_ssl_cert_file
  @env.fetch("BOSH_DIRECTOR_SSL_CERT", "director.pem")
end

#director_ssl_key_fileObject



102
103
104
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 102

def director_ssl_key_file
  @env.fetch("BOSH_DIRECTOR_SSL_KEY", "director.key")
end

#elb_ssl_cert_chain_fileObject



98
99
100
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 98

def elb_ssl_cert_chain_file
  @env["BOSH_AWS_ELB_SSL_CHAIN"]
end

#elb_ssl_cert_fileObject



94
95
96
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 94

def elb_ssl_cert_file
  @env.fetch("BOSH_AWS_ELB_SSL_CERT", "elb-cfrouter.pem")
end

#elb_ssl_key_fileObject



90
91
92
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 90

def elb_ssl_key_file
  @env.fetch("BOSH_AWS_ELB_SSL_KEY", "elb-cfrouter.key")
end

#fetch_from_env(key, msg = nil) ⇒ Object



17
18
19
20
21
22
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 17

def fetch_from_env(key, msg=nil)
  @env.fetch(key) {
    msg ||= "Missing ENV variable #{key}"
    raise(ConfigurationInvalid, msg)
  }
end

#has_package_cache_configuration?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 110

def has_package_cache_configuration?
  cache_access_key_id
end

#has_vpc_domain?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 66

def has_vpc_domain?
  vpc_domain && vpc_domain != ""
end

#has_vpc_subdomain?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 70

def has_vpc_subdomain?
  vpc_subdomain && vpc_subdomain != ""
end

#key_pair_nameObject



82
83
84
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 82

def key_pair_name
  @env.fetch("BOSH_KEY_PAIR_NAME", "bosh")
end

#key_pair_pathObject



86
87
88
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 86

def key_pair_path
  @env.fetch("BOSH_KEY_PATH", "#{@env['HOME']}/.ssh/id_rsa_bosh")
end

#load_configuration(yaml) ⇒ Object



134
135
136
137
138
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 134

def load_configuration(yaml)
  renderer = ERB.new(yaml, 0, '<>%-')

  YAML.load(renderer.result(binding))
end

#production_resources?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 130

def production_resources?
  @env['BOSH_PRODUCTION_RESOURCES']
end

#vpc_deployment_nameObject



44
45
46
47
48
49
50
51
52
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 44

def vpc_deployment_name
  if has_vpc_subdomain?
    vpc_subdomain
  elsif has_vpc_domain?
    vpc_domain.gsub('.', '-')
  else
    "deployment"
  end
end

#vpc_domainObject



36
37
38
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 36

def vpc_domain
  @env["BOSH_VPC_DOMAIN"]
end

#vpc_generated_domainObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 54

def vpc_generated_domain
  if has_vpc_domain? && has_vpc_subdomain?
    "#{vpc_subdomain}.#{vpc_domain}"
  elsif has_vpc_subdomain?
    "#{vpc_subdomain}.cf-app.com"
  elsif has_vpc_domain?
    vpc_domain
  else
    raise(ConfigurationInvalid, "No domain and subdomain are defined.")
  end
end

#vpc_primary_azObject



74
75
76
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 74

def vpc_primary_az
  fetch_from_env("BOSH_VPC_PRIMARY_AZ")
end

#vpc_secondary_azObject



78
79
80
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 78

def vpc_secondary_az
  fetch_from_env("BOSH_VPC_SECONDARY_AZ")
end

#vpc_subdomainObject



40
41
42
# File 'lib/bosh_cli_plugin_aws/aws_config.rb', line 40

def vpc_subdomain
  @env["BOSH_VPC_SUBDOMAIN"]
end