Class: OpenStudio::Aws::Config
- Inherits:
-
Object
- Object
- OpenStudio::Aws::Config
- Includes:
- Logging
- Defined in:
- lib/openstudio/aws/config.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
-
#initialize(yml_config_file = nil) ⇒ Config
constructor
A new instance of Config.
Methods included from Logging
configure_logger_for, #logger, logger_for
Constructor Details
#initialize(yml_config_file = nil) ⇒ Config
Returns a new instance of Config.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/openstudio/aws/config.rb', line 44 def initialize(yml_config_file = nil) # If the AWS keys are set in the env variable and the yml_config_file is nil, then use those keys @access_key = ENV['AWS_ACCESS_KEY_ID'] if ENV['AWS_ACCESS_KEY_ID'] @secret_key = ENV['AWS_SECRET_ACCESS_KEY'] if ENV['AWS_SECRET_ACCESS_KEY'] if @access_key && @secret_key && yml_config_file.nil? logger.info 'Using AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from environment variables' else # Otherwise read the file logger.info 'Reading AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from aws config file' @yml_config_file = yml_config_file @config = nil @yml_config_file = File.join(File.('~'), 'aws_config.yml') if @yml_config_file.nil? unless File.exist?(@yml_config_file) write_config_file raise "Config file not found. A template has been added, please edit and save: #{@yml_config_file}" exit 1 end begin @config = YAML.load(File.read(@yml_config_file)) # always convert to symbolized hash @config = @config.inject({}) { |a, (k, v)| a[k.to_sym] = v; a } @access_key = @config[:access_key_id] @secret_key = @config[:secret_access_key] rescue StandardError raise "Couldn't read config file #{@yml_config_file}. Delete file then recreate by rerunning script" end end end |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
41 42 43 |
# File 'lib/openstudio/aws/config.rb', line 41 def access_key @access_key end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
42 43 44 |
# File 'lib/openstudio/aws/config.rb', line 42 def secret_key @secret_key end |