Class: SdbDal::S3::QueryStringAuthGenerator

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

Overview

This interface mirrors the AWSAuthConnection class, but instead of performing the operations, this class simply returns a url that can be used to perform the operation with the query string authentication parameters set. PLEASE NOTE - For security reasons, it is HIGHLY RECOMMENDED to avoid using product tokens in signed urls. Please see the README for further details.

Constant Summary collapse

DEFAULT_EXPIRES_IN =

by default, expire in 1 minute

60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_access_key_id, aws_secret_access_key, tokens = Array.new, is_secure = true, server = DEFAULT_HOST, port = PORTS_BY_SECURITY[is_secure], format = CallingFormat::REGULAR) ⇒ QueryStringAuthGenerator

Returns a new instance of QueryStringAuthGenerator.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 25

def initialize(aws_access_key_id, aws_secret_access_key, tokens=Array.new,
        is_secure=true, 
               server=DEFAULT_HOST, port=PORTS_BY_SECURITY[is_secure], 
               format=CallingFormat::REGULAR)
  @aws_access_key_id = aws_access_key_id
  @aws_secret_access_key = aws_secret_access_key
  @protocol = is_secure ? 'https' : 'http'
  @server = server
  @port = port
  @calling_format = format 
  @tokens = tokens 
  # by default expire
  @expires_in = DEFAULT_EXPIRES_IN
  
 
end

Instance Attribute Details

#calling_formatObject

Returns the value of attribute calling_format.



16
17
18
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 16

def calling_format
  @calling_format
end

#expiresObject

Returns the value of attribute expires.



17
18
19
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 17

def expires
  @expires
end

#expires_inObject

Returns the value of attribute expires_in.



18
19
20
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 18

def expires_in
  @expires_in
end

#portObject (readonly)

Returns the value of attribute port.



20
21
22
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 20

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



19
20
21
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 19

def server
  @server
end

Instance Method Details

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



59
60
61
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 59

def create_bucket(bucket, headers={})
  return generate_url('PUT', bucket, '', {}, headers)
end

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



88
89
90
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 88

def delete(bucket, key, headers={})
  return generate_url('DELETE', bucket, CGI::escape(key), {}, headers)
end

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



72
73
74
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 72

def delete_bucket(bucket, headers={})
  return generate_url('DELETE', bucket, '', {}, headers)
end

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



84
85
86
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 84

def get(bucket, key, headers={})
  return generate_url('GET', bucket, CGI::escape(key), {}, headers)
end

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



100
101
102
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 100

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

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



104
105
106
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 104

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

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



92
93
94
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 92

def get_bucket_logging(bucket, headers={})
  return generate_url('GET', bucket, '', {'logging' => nil}, headers)
end

#list_all_my_buckets(headers = {}) ⇒ Object



118
119
120
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 118

def list_all_my_buckets(headers={})
  return generate_url('GET', '', '', {}, headers)
end

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

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



64
65
66
67
68
69
70
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 64

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

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

don’t really care what object data is. it’s just for conformance with the other interface. If this doesn’t work, check tcpdump to see if the client is putting a Content-Type header on the wire.



79
80
81
82
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 79

def put(bucket, key, object=nil, headers={})
  object = S3Object.new(object) if not object.instance_of? S3Object
  return generate_url('PUT', bucket, CGI::escape(key), {}, merge_meta(headers, object))
end

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

don’t really care what acl_xml_doc is. again, check the wire for Content-Type if this fails.



110
111
112
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 110

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

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



114
115
116
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 114

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



96
97
98
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 96

def put_bucket_logging(bucket, logging_xml_doc, headers={})
  return generate_url('PUT', bucket, '', {'logging' => nil}, headers)
end

#tokensObject



41
42
43
# File 'lib/sdb_dal/query_string_auth_generator.rb', line 41

def tokens
    @tokens
end