Class: Awscli::Connection
- Inherits:
-
Object
- Object
- Awscli::Connection
- Defined in:
- lib/awscli/connection.rb
Instance Method Summary collapse
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #request_as ⇒ Object
- #request_dynamo(region = nil) ⇒ Object
- #request_ec2(region = nil) ⇒ Object
- #request_emr(region = nil) ⇒ Object
- #request_iam ⇒ Object
- #request_s3(region = nil) ⇒ Object
Constructor Details
#initialize ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/awscli/connection.rb', line 6 def initialize #load env variable AWSCLI_CONFIG_FILE @aws_config_file = ENV['AWSCLI_CONFIG_FILE'] if @aws_config_file.nil? puts 'Cannot find config file environment variable' Awscli::Errors.missing_environment_variable end @aws_config_file_path = File.(@aws_config_file) unless File.exist?(@aws_config_file_path) puts "Cannot locate file #{@aws_config_file}" Awscli::Errors.missing_config_file end @config = YAML.load(File.read(@aws_config_file_path)) unless @config.kind_of?(Hash) puts 'Parse Error' Awscli::Errors.missing_credentials end end |
Instance Method Details
#request_as ⇒ Object
51 52 53 54 |
# File 'lib/awscli/connection.rb', line 51 def request_as # => returns AWS Auto Scaling connection object Fog::AWS::AutoScaling.new(@config) end |
#request_dynamo(region = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/awscli/connection.rb', line 74 def request_dynamo(region=nil) # => returns AWS DynamoDB object if region Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(region) @config.reject!{ |key| key == 'region' } if @config['region'] @config.merge!(:region => region) else Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(@config['region']) if @config['region'] end Fog::AWS::DynamoDB.new(@config) end |
#request_ec2(region = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/awscli/connection.rb', line 25 def request_ec2(region=nil) # => returns AWS Compute connection object @config.merge!(:provider => 'AWS') if region #if user passes a region optionally Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(region) @config.reject!{ |key| key == 'region' } if @config['region'] @config.merge!(:region => region) else Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(@config['region']) if @config['region'] end Fog::Compute.new(@config) end |
#request_emr(region = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/awscli/connection.rb', line 62 def request_emr(region=nil) # => returns AWS EMR object if region Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(region) @config.reject!{ |key| key == 'region' } if @config['region'] @config.merge!(:region => region) else Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(@config['region']) if @config['region'] end Fog::AWS::EMR.new(@config) end |
#request_iam ⇒ Object
56 57 58 59 60 |
# File 'lib/awscli/connection.rb', line 56 def request_iam # => returns AWS IAM object @config.reject!{ |key| key == 'region' } if @config['region'] Fog::AWS::IAM.new(@config) end |
#request_s3(region = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/awscli/connection.rb', line 39 def request_s3(region=nil) # => returns S3 connection object @config.merge!(:provider => 'AWS') @config.reject!{ |key| key == 'region' } if @config['region'] #parse optionally passing region if region Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(region) @config.merge!(:region => region) end Fog::Storage.new(@config) end |