Class: Awscli::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/awscli/connection.rb

Instance Method Summary collapse

Constructor Details

#initializeConnection

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.expand_path(@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_asObject



52
53
54
55
# File 'lib/awscli/connection.rb', line 52

def request_as
  # => returns AWS Auto Scaling connection object
  Fog::AWS::AutoScaling.new(@config)
end

#request_cloudwatch(region = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/awscli/connection.rb', line 75

def request_cloudwatch(region=nil)
  # => returns AWS CloudWatch 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::CloudWatch.new(@config)
end

#request_dynamo(region = nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/awscli/connection.rb', line 87

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



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/awscli/connection.rb', line 63

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_iamObject



57
58
59
60
61
# File 'lib/awscli/connection.rb', line 57

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
50
# File 'lib/awscli/connection.rb', line 39

def request_s3(region=nil)
  # => returns S3 connection object
  @config.merge!(:provider => 'AWS')
  @config.merge!(:path_style => true)
  @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