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'.

Direct Known Subclasses

Autoscaling::Base, Cloudwatch::Base, EC2::Base, ELB::Base, RDS::Base

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Object) initialize(options = {})

Returns the object.

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:



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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/AWS.rb', line 124

def initialize( options = {} )

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

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

  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

- (Object) port (readonly)

Returns the value of attribute port



116
117
118
# File 'lib/AWS.rb', line 116

def port
  @port
end

- (Object) proxy_server (readonly)

Returns the value of attribute proxy_server



116
117
118
# File 'lib/AWS.rb', line 116

def proxy_server
  @proxy_server
end

- (Object) server (readonly)

Returns the value of attribute server



116
117
118
# File 'lib/AWS.rb', line 116

def server
  @server
end

- (Object) use_ssl (readonly)

Returns the value of attribute use_ssl



116
117
118
# File 'lib/AWS.rb', line 116

def use_ssl
  @use_ssl
end

Instance Method Details

- (Object) extract_user_data(options = {})

If :user_data is passed in then URL escape and Base64 encode it as needed. Need for URL Escape + Base64 encoding is determined by :base64_encoded param.



177
178
179
180
181
182
183
184
185
186
# File 'lib/AWS.rb', line 177

def extract_user_data( options = {} )
  return unless options[:user_data]
  if options[:user_data]
    if options[:base64_encoded]
      Base64.encode64(options[:user_data]).gsub(/\n/, "").strip()
    else
      options[:user_data]
    end
  end
end