Class: S3::AWSAuthConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/s3sync/S3.rb,
lib/s3sync/S3_s3sync_mod.rb

Overview

uses Net::HTTP to interface with S3. note that this interface should only be used for smaller objects, as it does not stream the data. if you were to download a 1gb file, it would require 1gb of memory. also, this class creates a new http connection each time. it would be greatly improved with some connection pooling.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_access_key_id, aws_secret_access_key, is_secure = true, server = DEFAULT_HOST, port = , calling_format = CallingFormat::REGULAR) ⇒ AWSAuthConnection

Returns a new instance of AWSAuthConnection.



139
140
141
142
143
144
145
146
147
148
# File 'lib/s3sync/S3.rb', line 139

def initialize(aws_access_key_id, aws_secret_access_key, is_secure=true,
               server=DEFAULT_HOST, port=PORTS_BY_SECURITY[is_secure],
               calling_format=CallingFormat::REGULAR)
  @aws_access_key_id = aws_access_key_id
  @aws_secret_access_key = aws_secret_access_key
  @server = server
  @is_secure = is_secure
  @calling_format = calling_format
  @port = port
end

Instance Attribute Details

#ca_fileObject

Returns the value of attribute ca_file.



125
126
127
# File 'lib/s3sync/S3_s3sync_mod.rb', line 125

def ca_file
  @ca_file
end

#ca_pathObject

Returns the value of attribute ca_path.



124
125
126
# File 'lib/s3sync/S3_s3sync_mod.rb', line 124

def ca_path
  @ca_path
end

#calling_formatObject

Returns the value of attribute calling_format.



137
138
139
# File 'lib/s3sync/S3.rb', line 137

def calling_format
  @calling_format
end

#verify_modeObject

allow ssl validation



123
124
125
# File 'lib/s3sync/S3_s3sync_mod.rb', line 123

def verify_mode
  @verify_mode
end

Instance Method Details

#__make_request__Object

add support for streaming the response body to an IO stream



60
# File 'lib/s3sync/S3_s3sync_mod.rb', line 60

alias __make_request__ make_request

#create_bucket(bucket, headers = {}) ⇒ Object



108
109
110
111
112
113
# File 'lib/s3sync/S3_s3sync_mod.rb', line 108

def create_bucket(bucket, object)
   object = S3Object.new(object) if not object.instance_of? S3Object
   return Response.new(
      make_request('PUT', bucket, '', {}, {}, object.data, object.)
   )
end

#delete(bucket, key, headers = {}) ⇒ Object



185
186
187
# File 'lib/s3sync/S3.rb', line 185

def delete(bucket, key, headers={})
  return Response.new(make_request('DELETE', bucket, CGI::escape(key), {}, headers))
end

#delete_bucket(bucket, headers = {}) ⇒ Object



164
165
166
# File 'lib/s3sync/S3.rb', line 164

def delete_bucket(bucket, headers={})
  return Response.new(make_request('DELETE', bucket, '', {}, headers))
end

#get(bucket, key, headers = {}) ⇒ Object



181
182
183
# File 'lib/s3sync/S3.rb', line 181

def get(bucket, key, headers={})
  return GetResponse.new(make_request('GET', bucket, CGI::escape(key), {}, headers))
end

#get_acl(bucket, key, headers = {}) ⇒ Object

returns an xml document representing the access control list. this could be parsed into an object.



207
208
209
# File 'lib/s3sync/S3.rb', line 207

def get_acl(bucket, key, headers={})
  return GetResponse.new(make_request('GET', bucket, CGI::escape(key), {'acl' => nil}, headers))
end

#get_bucket_acl(bucket, headers = {}) ⇒ Object



201
202
203
# File 'lib/s3sync/S3.rb', line 201

def get_bucket_acl(bucket, headers={})
  return get_acl(bucket, '', headers)
end

#get_bucket_logging(bucket, headers = {}) ⇒ Object



193
194
195
# File 'lib/s3sync/S3.rb', line 193

def get_bucket_logging(bucket, headers={})
  return GetResponse.new(make_request('GET', bucket, '', {'logging' => nil}, headers))
end

#get_query_stream(bucket, key, path_args = {}, headers = {}, streamOut = nil) ⇒ Object

a “get” operation that sends the body to an IO stream



100
101
102
# File 'lib/s3sync/S3_s3sync_mod.rb', line 100

def get_query_stream(bucket, key, path_args={}, headers={}, streamOut=nil)
       return GetResponse.new(make_request('GET', bucket, CGI::escape(key), path_args, headers, '', {}, streamOut))
end

#get_stream(bucket, key, headers = {}, streamOut = nil) ⇒ Object

a “get” operation that sends the body to an IO stream



95
96
97
# File 'lib/s3sync/S3_s3sync_mod.rb', line 95

def get_stream(bucket, key, headers={}, streamOut=nil)
       return GetResponse.new(make_request('GET', bucket, CGI::escape(key), {}, headers, '', {}, streamOut))
end

#head(bucket, key, headers = {}) ⇒ Object



104
105
106
# File 'lib/s3sync/S3_s3sync_mod.rb', line 104

def head(bucket, key=nil, headers={})
       return GetResponse.new(make_request('HEAD', bucket, CGI::escape(key), {}, headers, '', {}))
end

#list_all_my_buckets(headers = {}) ⇒ Object



223
224
225
# File 'lib/s3sync/S3.rb', line 223

def list_all_my_buckets(headers={})
  return ListAllMyBucketsResponse.new(make_request('GET', '', '', {}, headers))
end

#list_bucket(bucket, options = {}, headers = {}) ⇒ Object

takes options :prefix, :marker, :max_keys, and :delimiter



155
156
157
158
159
160
161
162
# File 'lib/s3sync/S3.rb', line 155

def list_bucket(bucket, options={}, headers={})
  path_args = {}
  options.each { |k, v|
    path_args[k] = v.to_s
  }

  return ListBucketResponse.new(make_request('GET', bucket, '', path_args, headers))
end

#make_http(bucket = '', host = '', proxy_host = nil, proxy_port = nil, proxy_user = nil, proxy_pass = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/s3sync/S3_s3sync_mod.rb', line 30

def make_http(bucket='', host='', proxy_host=nil, proxy_port=nil, proxy_user=nil, proxy_pass=nil)

   # build the domain based on the calling format
   server = ''
   if host != ''
     server = host           
   elsif bucket.empty?
     # for a bucketless request (i.e. list all buckets)
     # revert to regular domain case since this operation
     # does not make sense for vanity domains
     server = @server
   elsif @calling_format == CallingFormat::SUBDOMAIN
     server = "#{bucket}.#{@server}" 
   elsif @calling_format == CallingFormat::VANITY
     server = bucket 
   else
     server = @server
   end
   # automatically does the right thing when no proxy
   http = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).new(server, @port)
   #http = Net::HTTP.new(server, @port)
   http.use_ssl = @is_secure
   http.verify_mode=@verify_mode
   http.ca_file=@ca_file
   http.ca_path=@ca_path
   http.start
   return http
end

#put(bucket, key, object = nil, headers = {}) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/s3sync/S3.rb', line 168

def put(bucket, key, object=nil, headers={})
  if object == nil
    req = make_request('PUT', bucket, CGI::escape(key), {}, headers)
  else
    if not object.instance_of? S3Object
      object = S3Object.new(object)
    end
    req = make_request('PUT', bucket, CGI::escape(key), {}, headers, object.data, object.)
  end

  return Response.new(req)
end

#put_acl(bucket, key, acl_xml_doc, headers = {}) ⇒ Object

sets the access control policy for the given resource. acl_xml_doc must be a string in the acl xml format.



217
218
219
220
221
# File 'lib/s3sync/S3.rb', line 217

def put_acl(bucket, key, acl_xml_doc, headers={})
  return Response.new(
                      make_request('PUT', bucket, CGI::escape(key), {'acl' => nil}, headers, acl_xml_doc, {})
                      )
end

#put_bucket_acl(bucket, acl_xml_doc, headers = {}) ⇒ Object



211
212
213
# File 'lib/s3sync/S3.rb', line 211

def put_bucket_acl(bucket, acl_xml_doc, headers={})
  return put_acl(bucket, '', acl_xml_doc, headers)
end

#put_bucket_logging(bucket, logging_xml_doc, headers = {}) ⇒ Object



197
198
199
# File 'lib/s3sync/S3.rb', line 197

def put_bucket_logging(bucket, logging_xml_doc, headers={})
  return Response.new(make_request('PUT', bucket, '', {'logging' => nil}, headers, logging_xml_doc))
end