Class: S3::AWSAuthConnection
- Inherits:
-
Object
- Object
- S3::AWSAuthConnection
- 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
-
#ca_file ⇒ Object
Returns the value of attribute ca_file.
-
#ca_path ⇒ Object
Returns the value of attribute ca_path.
-
#calling_format ⇒ Object
Returns the value of attribute calling_format.
-
#verify_mode ⇒ Object
allow ssl validation.
Instance Method Summary collapse
-
#__make_request__ ⇒ Object
add support for streaming the response body to an IO stream.
- #create_bucket(bucket, headers = {}) ⇒ Object
- #delete(bucket, key, headers = {}) ⇒ Object
- #delete_bucket(bucket, headers = {}) ⇒ Object
- #get(bucket, key, headers = {}) ⇒ Object
-
#get_acl(bucket, key, headers = {}) ⇒ Object
returns an xml document representing the access control list.
- #get_bucket_acl(bucket, headers = {}) ⇒ Object
- #get_bucket_logging(bucket, headers = {}) ⇒ Object
-
#get_query_stream(bucket, key, path_args = {}, headers = {}, streamOut = nil) ⇒ Object
a “get” operation that sends the body to an IO stream.
-
#get_stream(bucket, key, headers = {}, streamOut = nil) ⇒ Object
a “get” operation that sends the body to an IO stream.
- #head(bucket, key, headers = {}) ⇒ Object
-
#initialize(aws_access_key_id, aws_secret_access_key, is_secure = true, server = DEFAULT_HOST, port = , calling_format = CallingFormat::REGULAR) ⇒ AWSAuthConnection
constructor
A new instance of AWSAuthConnection.
- #list_all_my_buckets(headers = {}) ⇒ Object
-
#list_bucket(bucket, options = {}, headers = {}) ⇒ Object
takes options :prefix, :marker, :max_keys, and :delimiter.
- #make_http(bucket = '', host = '', proxy_host = nil, proxy_port = nil, proxy_user = nil, proxy_pass = nil) ⇒ Object
- #put(bucket, key, object, headers = {}) ⇒ Object
-
#put_acl(bucket, key, acl_xml_doc, headers = {}) ⇒ Object
sets the access control policy for the given resource.
- #put_bucket_acl(bucket, acl_xml_doc, headers = {}) ⇒ Object
- #put_bucket_logging(bucket, logging_xml_doc, headers = {}) ⇒ Object
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_file ⇒ Object
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_path ⇒ Object
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_format ⇒ Object
Returns the value of attribute calling_format.
137 138 139 |
# File 'lib/s3sync/S3.rb', line 137 def calling_format @calling_format end |
#verify_mode ⇒ Object
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
180 181 182 |
# File 'lib/s3sync/S3.rb', line 180 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
176 177 178 |
# File 'lib/s3sync/S3.rb', line 176 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.
202 203 204 |
# File 'lib/s3sync/S3.rb', line 202 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
196 197 198 |
# File 'lib/s3sync/S3.rb', line 196 def get_bucket_acl(bucket, headers={}) return get_acl(bucket, '', headers) end |
#get_bucket_logging(bucket, headers = {}) ⇒ Object
188 189 190 |
# File 'lib/s3sync/S3.rb', line 188 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
218 219 220 |
# File 'lib/s3sync/S3.rb', line 218 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, ={}, headers={}) path_args = {} .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, headers = {}) ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/s3sync/S3.rb', line 168 def put(bucket, key, object, headers={}) object = S3Object.new(object) if not object.instance_of? S3Object return Response.new( make_request('PUT', bucket, CGI::escape(key), {}, headers, object.data, object.) ) 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.
212 213 214 215 216 |
# File 'lib/s3sync/S3.rb', line 212 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
206 207 208 |
# File 'lib/s3sync/S3.rb', line 206 def put_bucket_acl(bucket, acl_xml_doc, headers={}) return put_acl(bucket, '', acl_xml_doc, headers) end |