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:



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

def initialize( options = {} )

  options = { :access_key_id => "",
              :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

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#proxy_serverObject (readonly)

Returns the value of attribute proxy_server.



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

def proxy_server
  @proxy_server
end

#serverObject (readonly)

Returns the value of attribute server.



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

def server
  @server
end

#use_sslObject (readonly)

Returns the value of attribute use_ssl.



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

def use_ssl
  @use_ssl
end

Instance Method Details

#extract_user_data(options = {}) ⇒ Object

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.



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

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