aws 2.2.6 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -86,24 +86,116 @@ module Aws
86
86
  string_to_sign = "#{http_verb.to_s.upcase}\n#{host.downcase}\n#{uri}\n#{canonical_string}"
87
87
  # sign the string
88
88
  signature = escape_sig(Base64.encode64(OpenSSL::HMAC.digest(digest, aws_secret_access_key, string_to_sign)).strip)
89
- "#{canonical_string}&Signature=#{signature}"
89
+ ret = "#{canonical_string}&Signature=#{signature}"
90
+ # puts 'full=' + ret.inspect
91
+ ret
92
+ end
93
+
94
+ HEX = [
95
+ "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
96
+ "%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F",
97
+ "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
98
+ "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F",
99
+ "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27",
100
+ "%28", "%29", "%2A", "%2B", "%2C", "%2D", "%2E", "%2F",
101
+ "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37",
102
+ "%38", "%39", "%3A", "%3B", "%3C", "%3D", "%3E", "%3F",
103
+ "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47",
104
+ "%48", "%49", "%4A", "%4B", "%4C", "%4D", "%4E", "%4F",
105
+ "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57",
106
+ "%58", "%59", "%5A", "%5B", "%5C", "%5D", "%5E", "%5F",
107
+ "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67",
108
+ "%68", "%69", "%6A", "%6B", "%6C", "%6D", "%6E", "%6F",
109
+ "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77",
110
+ "%78", "%79", "%7A", "%7B", "%7C", "%7D", "%7E", "%7F",
111
+ "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
112
+ "%88", "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F",
113
+ "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
114
+ "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F",
115
+ "%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7",
116
+ "%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF",
117
+ "%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7",
118
+ "%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF",
119
+ "%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7",
120
+ "%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF",
121
+ "%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7",
122
+ "%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF",
123
+ "%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7",
124
+ "%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF",
125
+ "%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7",
126
+ "%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF"
127
+ ]
128
+ TO_REMEMBER = 'AZaz09 -_.!~*\'()'
129
+ ASCII = {} # {'A'=>65, 'Z'=>90, 'a'=>97, 'z'=>122, '0'=>48, '9'=>57, ' '=>32, '-'=>45, '_'=>95, '.'=>}
130
+ TO_REMEMBER.each_char do |c| #unpack("c*").each do |c|
131
+ ASCII[c] = c.unpack("c")[0]
90
132
  end
133
+ # puts 'ascii=' + ASCII.inspect
91
134
 
92
135
  # Escape a string accordingly Amazon rulles
93
136
  # http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?REST_RESTAuth.html
94
137
  def self.amz_escape(param)
138
+
139
+ param = param.to_s
140
+ # param = param.force_encoding("UTF-8")
141
+
142
+ e = "x" # escape2(param.to_s)
143
+ # puts 'ESCAPED=' + e.inspect
144
+
145
+
95
146
  #return CGI.escape(param.to_s).gsub("%7E", "~").gsub("+", "%20") # from: http://umlaut.rubyforge.org/svn/trunk/lib/aws_product_sign.rb
96
147
 
97
148
  #param.to_s.gsub(/([^a-zA-Z0-9._~-]+)/n) do
98
149
  # '%' + $1.unpack('H2' * $1.size).join('%').upcase
99
150
  #end
100
- e = CGI.escape(param.to_s)
101
- e = e.gsub("%7E", "~")
102
- e = e.gsub("+", "%20")
103
- e = e.gsub("*", "%2A")
104
151
 
105
- end
152
+ # puts 'e in=' + e.inspect
153
+ # converter = Iconv.new('ASCII', 'UTF-8')
154
+ # e = converter.iconv(e) #.unpack('U*').select{ |cp| cp < 127 }.pack('U*')
155
+ # puts 'e out=' + e.inspect
156
+
157
+ e2 = CGI.escape(param)
158
+ e2 = e2.gsub("%7E", "~")
159
+ e2 = e2.gsub("+", "%20")
160
+ e2 = e2.gsub("*", "%2A")
161
+
162
+ # puts 'E2=' + e2.inspect
163
+ # puts e == e2.to_s
164
+
165
+ e2
166
+
167
+ end
168
+
169
+ def self.escape2(s)
170
+ # home grown
171
+ ret = ""
172
+ s.unpack("U*") do |ch|
173
+ # puts 'ch=' + ch.inspect
174
+ if ASCII['A'] <= ch && ch <= ASCII['Z'] # A to Z
175
+ ret << ch
176
+ elsif ASCII['a'] <= ch && ch <= ASCII['z'] # a to z
177
+ ret << ch
178
+ elsif ASCII['0'] <= ch && ch <= ASCII['9'] # 0 to 9
179
+ ret << ch
180
+ elsif ch == ASCII[' '] # space
181
+ ret << "%20" # "+"
182
+ elsif ch == ASCII['-'] || ch == ASCII['_'] || ch == ASCII['.'] || ch == ASCII['~']
183
+ ret << ch
184
+ elsif ch <= 0x007f # other ascii
185
+ ret << HEX[ch]
186
+ elsif ch <= 0x07FF # non-ascii
187
+ ret << HEX[0xc0 | (ch >> 6)]
188
+ ret << HEX[0x80 | (ch & 0x3F)]
189
+ else
190
+ ret << HEX[0xe0 | (ch >> 12)]
191
+ ret << HEX[0x80 | ((ch >> 6) & 0x3F)]
192
+ ret << HEX[0x80 | (ch & 0x3F)]
193
+ end
106
194
 
195
+ end
196
+ ret
197
+
198
+ end
107
199
 
108
200
  def self.escape_sig(raw)
109
201
  e = CGI.escape(raw)
@@ -275,6 +367,9 @@ module Aws
275
367
  def generate_request2(aws_access_key, aws_secret_key, action, api_version, lib_params, user_params={}) #:nodoc:
276
368
  # remove empty params from request
277
369
  user_params.delete_if {|key, value| value.nil? }
370
+ # user_params.each_pair do |k,v|
371
+ # user_params[k] = v.force_encoding("UTF-8")
372
+ # end
278
373
  #params_string = params.to_a.collect{|key,val| key + "=#{CGI::escape(val.to_s)}" }.join("&")
279
374
  # prepare service data
280
375
  service = lib_params[:service]
@@ -571,10 +666,10 @@ module Aws
571
666
  end
572
667
 
573
668
 
574
- # Exception class to signal any Amazon errors. All errors occuring during calls to Amazon's
575
- # web services raise this type of error.
576
- # Attribute inherited by RuntimeError:
577
- # message - the text of the error, generally as returned by AWS in its XML response.
669
+ # Exception class to signal any Amazon errors. All errors occuring during calls to Amazon's
670
+ # web services raise this type of error.
671
+ # Attribute inherited by RuntimeError:
672
+ # message - the text of the error, generally as returned by AWS in its XML response.
578
673
  class AwsError < RuntimeError
579
674
 
580
675
  # either an array of errors where each item is itself an array of [code, message]),
@@ -647,7 +742,7 @@ module Aws
647
742
 
648
743
  end
649
744
 
650
- # Simplified version
745
+ # Simplified version
651
746
  class AwsError2 < RuntimeError
652
747
  # Request id (if exists)
653
748
  attr_reader :request_id
@@ -851,7 +946,7 @@ module Aws
851
946
  end
852
947
 
853
948
 
854
- #-----------------------------------------------------------------
949
+ #-----------------------------------------------------------------
855
950
 
856
951
  class RightSaxParserCallback #:nodoc:
857
952
  def self.include_callback
@@ -1018,9 +1113,9 @@ module Aws
1018
1113
  end
1019
1114
  end
1020
1115
 
1021
- #-----------------------------------------------------------------
1022
- # PARSERS: Errors
1023
- #-----------------------------------------------------------------
1116
+ #-----------------------------------------------------------------
1117
+ # PARSERS: Errors
1118
+ #-----------------------------------------------------------------
1024
1119
 
1025
1120
  #<Error>
1026
1121
  # <Code>TemporaryRedirect</Code>
@@ -1056,8 +1151,8 @@ module Aws
1056
1151
  end
1057
1152
  end
1058
1153
 
1059
- # Dummy parser - does nothing
1060
- # Returns the original params back
1154
+ # Dummy parser - does nothing
1155
+ # Returns the original params back
1061
1156
  class RightDummyParser # :nodoc:
1062
1157
  attr_accessor :result
1063
1158
 
@@ -169,7 +169,8 @@ module Aws
169
169
  # Convert a Ruby language value to a SDB value by replacing Ruby nil with the user's chosen string representation of nil.
170
170
  # Non-nil values are unaffected by this filter.
171
171
  def ruby_to_sdb(value)
172
- value.nil? ? @nil_rep : value
172
+ # puts "value #{value} is frozen? #{value.frozen?}"
173
+ value.nil? ? @nil_rep : ((value.frozen? || !value.is_a?(String)) ? value : value.force_encoding("UTF-8"))
173
174
  end
174
175
 
175
176
  # Convert a SDB value to a Ruby language value by replacing the user's chosen string representation of nil with Ruby nil.
@@ -92,13 +92,13 @@ class TestSdb < Test::Unit::TestCase
92
92
  ids = clients.map{|client| client.id }[0..1]
93
93
  assert_equal @clients.size + 1, clients.size
94
94
  # retrieve all presidents (must find: Bush, Putin, Medvedev)
95
- assert_equal 3, Client.find(:all, :conditions => ["[?=?]",'post','president']).size
95
+ assert_equal 3, Client.find(:all, :conditions => ["post=?",'president']).size
96
96
  # retrieve all russian presidents (must find: Putin, Medvedev)
97
- assert_equal 2, Client.find(:all, :conditions => ["['post'=?] intersection ['country'=?]",'president', 'Russia']).size
97
+ assert_equal 2, Client.find(:all, :conditions => ["post=? and country=?",'president', 'Russia']).size
98
98
  # retrieve all russian presidents and all women (must find: Putin, Medvedev, 2 Maries and Sandy)
99
- assert_equal 5, Client.find(:all, :conditions => ["['post'=?] intersection ['country'=?] union ['gender'=?]",'president', 'Russia','female']).size
99
+ assert_equal 5, Client.find(:all, :conditions => ["post=? and country=? or gender=?",'president', 'Russia','female']).size
100
100
  # find all rissian presidents Bushes
101
- assert_equal 0, Client.find(:all, :conditions => ["['post'=?] intersection ['country'=?] intersection ['name'=?]",'president', 'Russia','Bush']).size
101
+ assert_equal 0, Client.find(:all, :conditions => ["post=? and country=? and name=?",'president', 'Russia','Bush']).size
102
102
  # --- find by ids
103
103
  # must find 1 rec (by rec id) and return it
104
104
  assert_equal ids.first, Client.find(ids.first).id
@@ -103,45 +103,16 @@ class TestSdb < Test::Unit::TestCase
103
103
  wait SDB_DELAY, 'after adding attributes'
104
104
  # get attributes ('girls' and 'vodka' must be there)
105
105
  values = @sdb.get_attributes(@domain, @item)[:attributes]['Volodya'].to_a.sort
106
- assert_equal values, ['girls', 'vodka']
106
+ assert_equal ['girls', 'vodka'], values
107
107
  # delete an item
108
108
  @sdb.delete_attributes @domain, @item
109
+ sleep 1
109
110
  # get attributes (values must be empty)
110
111
  values = @sdb.get_attributes(@domain, @item)[:attributes]['Volodya']
111
- assert_equal values, nil
112
- end
113
-
114
- def test_08_query
115
- # not applicable anymore
116
- end
117
-
118
- def test_09_signature_version_0
119
- sdb = Aws::SdbInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
120
- item = 'toys'
121
- # TODO: need to change the below test. I think Juergen's intention was to include some umlauts in the values
122
- # put attributes
123
- # mhhh... Not sure how to translate this: hölzchehn klötzchen grÃŒnspan buße... Lets assume this is:
124
- attributes = { 'Jurgen' => %w{kitten puppy chickabiddy piglet} }
125
- assert sdb.put_attributes(@domain, item, attributes)
126
- wait SDB_DELAY, 'after putting attributes'
127
- # get attributes
128
- values = sdb.get_attributes(@domain, item)[:attributes]['Jurgen'].to_a.sort
129
- # compare to original list
130
- assert_equal values, attributes['Jurgen'].sort
131
- # check that the request has correct signature version
132
- assert sdb.last_request.path.include?('SignatureVersion=0')
112
+ assert_nil values
133
113
  end
134
114
 
135
- def test_10_signature_version_1
136
- sdb = Aws::SdbInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '1')
137
- domains = nil
138
- assert_nothing_thrown "Failed to use signature V1" do
139
- domains = sdb.list_domains
140
- end
141
- assert domains
142
- end
143
-
144
- def test_11_signature_version_1
115
+ def test_11_signature_version_2
145
116
  sdb = Aws::SdbInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '2')
146
117
  domains = nil
147
118
  assert_nothing_thrown "Failed to use signature V2" do
@@ -150,26 +121,46 @@ class TestSdb < Test::Unit::TestCase
150
121
  assert domains
151
122
  end
152
123
 
153
- def test_12_array_of_attrs
124
+ def test_12_unicode
125
+
126
+ # This was creating a bad signature
127
+ s = ''
128
+ File.open("unicode.txt", "r") { |f|
129
+ s = f.read
130
+ }
131
+ # s = s.force_encoding("UTF-8")
132
+ puts 's=' + s.inspect
133
+ puts "encoding? " + s.encoding.name
134
+ # s = s.encode("ASCII")
135
+ # todo: I'm thinking just iterate through characters and swap out ones that aren't in ascii range.
136
+ @sdb.put_attributes @domain, @item, {"badname"=>[s]}
137
+ sleep 1
138
+ value = @sdb.get_attributes(@domain, @item)[:attributes]['badname'][0]
139
+ puts 'value=' + value.inspect
140
+ assert value == s
141
+ end
142
+
143
+ def test_15_array_of_attrs
154
144
  item = 'multiples'
155
145
  assert_nothing_thrown "Failed to put multiple attrs" do
156
146
  @sdb.put_attributes(@domain, item, {:one=>1, :two=>2, :three=>3})
157
147
  end
158
148
  end
159
149
 
160
- def test_13_zero_len_attrs
150
+ def test_16_zero_len_attrs
161
151
  item = 'zeroes'
162
152
  assert_nothing_thrown "Failed to put zero-length attributes" do
163
153
  @sdb.put_attributes(@domain, item, {:one=>"", :two=>"", :three=>""})
164
154
  end
165
155
  end
166
156
 
167
- def test_14_nil_attrs
157
+ def test_17_nil_attrs
168
158
  item = 'nils'
169
159
  res = nil
170
160
  assert_nothing_thrown do
171
161
  @sdb.put_attributes(@domain, item, {:one=>nil, :two=>nil, :three=>'chunder'})
172
162
  end
163
+ sleep 1
173
164
  assert_nothing_thrown do
174
165
  res = @sdb.get_attributes(@domain, item)
175
166
  end
@@ -178,7 +169,7 @@ class TestSdb < Test::Unit::TestCase
178
169
  assert_not_nil(res[:attributes]['three'][0])
179
170
  end
180
171
 
181
- def test_15_url_escape
172
+ def test_18_url_escape
182
173
  item = 'urlescapes'
183
174
  content = {:a=>"one & two & three",
184
175
  :b=>"one ? two / three"}
@@ -189,7 +180,7 @@ class TestSdb < Test::Unit::TestCase
189
180
  assert_equal(content[:b], res[:attributes]['b'][0])
190
181
  end
191
182
 
192
- def test_16_put_attrs_by_post
183
+ def test_19_put_attrs_by_post
193
184
  item = 'reqgirth'
194
185
  i = 0
195
186
  sa = ""
@@ -200,12 +191,12 @@ class TestSdb < Test::Unit::TestCase
200
191
  @sdb.put_attributes(@domain, item, {:a => sa, :b => sa, :c => sa, :d => sa, :e => sa})
201
192
  end
202
193
 
203
- def test_20_query_with_atributes
194
+ def test_21_query_with_atributes
204
195
  # not applicable anymore
205
196
  end
206
197
 
207
198
  # Keep this test last, because it deletes the domain...
208
- def test_21_delete_domain
199
+ def test_40_delete_domain
209
200
  assert @sdb.delete_domain(@domain), 'delete_domain fail'
210
201
  wait SDB_DELAY, 'after domain deletion'
211
202
  # check that domain does not exist
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.6
4
+ prerelease: false
5
+ segments:
6
+ - 2
7
+ - 3
8
+ - 0
9
+ version: 2.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Travis Reeder
@@ -11,39 +16,45 @@ autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
18
 
14
- date: 2010-02-15 00:00:00 -08:00
19
+ date: 2010-03-22 00:00:00 -07:00
15
20
  default_executable:
16
21
  dependencies:
17
22
  - !ruby/object:Gem::Dependency
18
23
  name: uuidtools
19
- type: :runtime
20
- version_requirement:
21
- version_requirements: !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
22
26
  requirements:
23
27
  - - ">="
24
28
  - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
25
31
  version: "0"
26
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
27
34
  - !ruby/object:Gem::Dependency
28
35
  name: http_connection
29
- type: :runtime
30
- version_requirement:
31
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
32
38
  requirements:
33
39
  - - ">="
34
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
35
43
  version: "0"
36
- version:
44
+ type: :runtime
45
+ version_requirements: *id002
37
46
  - !ruby/object:Gem::Dependency
38
47
  name: xml-simple
39
- type: :runtime
40
- version_requirement:
41
- version_requirements: !ruby/object:Gem::Requirement
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
42
50
  requirements:
43
51
  - - ">="
44
52
  - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
45
55
  version: "0"
46
- version:
56
+ type: :runtime
57
+ version_requirements: *id003
47
58
  description: AWS Ruby Library for interfacing with Amazon Web Services.
48
59
  email: travis@appoxy.com
49
60
  executables: []
@@ -84,18 +95,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
95
  requirements:
85
96
  - - ">="
86
97
  - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
87
100
  version: "0"
88
- version:
89
101
  required_rubygems_version: !ruby/object:Gem::Requirement
90
102
  requirements:
91
103
  - - ">="
92
104
  - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
93
107
  version: "0"
94
- version:
95
108
  requirements: []
96
109
 
97
110
  rubyforge_project:
98
- rubygems_version: 1.3.5
111
+ rubygems_version: 1.3.6
99
112
  signing_key:
100
113
  specification_version: 3
101
114
  summary: AWS Ruby Library for interfacing with Amazon Web Services.