Class: AWS::Base

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

Overview

This class provides all the methods for using the EC2 or ELB service including the handling of header signing and other security concerns. This class uses the Net::HTTP library to interface with the AWS Query API interface. You should not instantiate this directly, instead you should setup an instance of ‘AWS::EC2::Base’ or ‘AWS::ELB::Base’.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Object

Returns the object.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :access_key_id (String) — default: ""

    The user’s AWS Access Key ID

  • :secret_access_key (String) — default: ""

    The user’s AWS Secret Access Key

  • :use_ssl (Boolean) — default: true

    Connect using SSL?

  • :server (String) — default: "ec2.amazonaws.com"

    The server API endpoint host

  • :proxy_server (String) — default: nil

    An HTTP proxy server FQDN

Raises:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/AWS.rb', line 102

def initialize( options = {} )

  options = { :access_key_id => "",
              :secret_access_key => "",
              :use_ssl => true,
              :server => default_host,
              :proxy_server => nil
              }.merge(options)

  @server = options[:server]
  @proxy_server = options[:proxy_server]
  @use_ssl = options[:use_ssl]

  raise ArgumentError, "No :access_key_id provided" if options[:access_key_id].nil? || options[:access_key_id].empty?
  raise ArgumentError, "No :secret_access_key provided" if options[:secret_access_key].nil? || options[:secret_access_key].empty?
  raise ArgumentError, "No :use_ssl value provided" if options[:use_ssl].nil?
  raise ArgumentError, "Invalid :use_ssl value provided, only 'true' or 'false' allowed" unless options[:use_ssl] == true || options[:use_ssl] == false
  raise ArgumentError, "No :server provided" if options[:server].nil? || options[:server].empty?

  if options[:port]
    # user-specified port
    @port = options[:port]
  elsif @use_ssl
    # https
    @port = 443
  else
    # http
    @port = 80
  end

  @access_key_id = options[:access_key_id]
  @secret_access_key = options[:secret_access_key]

  # Use proxy server if defined
  # Based on patch by Mathias Dalheimer.  20070217
  proxy = @proxy_server ? URI.parse(@proxy_server) : OpenStruct.new
  @http = Net::HTTP::Proxy( proxy.host,
                            proxy.port,
                            proxy.user,
                            proxy.password).new(options[:server], @port)

  @http.use_ssl = @use_ssl

  # Don't verify the SSL certificates.  Avoids SSL Cert warning in log on every GET.
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE

end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#proxy_serverObject (readonly)

Returns the value of attribute proxy_server.



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

def proxy_server
  @proxy_server
end

#serverObject (readonly)

Returns the value of attribute server.



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

def server
  @server
end

#use_sslObject (readonly)

Returns the value of attribute use_ssl.



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

def use_ssl
  @use_ssl
end