Permalink
Browse files

Refactor SigV2 and query params to support re-signing

  • Loading branch information...
1 parent 5b2b4c7 commit d4fc3e9b3fb4eabfc888bc7fb4d12fb3a31eafb2 Loren Segal committed Mar 18, 2013
Showing with 18 additions and 13 deletions.
  1. +3 −11 lib/service_interface/query.js
  2. +2 −2 lib/services/sqs.js
  3. +1 −0 lib/signers/v2.js
  4. +8 −0 lib/util.js
  5. +4 −0 test/util.spec.coffee
@@ -111,15 +111,15 @@ AWS.ServiceInterface.Query = {
AWS.QueryParamList = inherit({
constructor: function QueryParamList() {
- this.params = [];
+ this.params = {};
},
add: function add(name, value) {
- this.params.push(new AWS.QueryParam(name, value));
+ this.params[name] = new AWS.QueryParam(name, value);
},
sortedParams: function sortedParams() {
- return this.params.sort(function (p1, p2) {
+ return AWS.util.values(this.params).sort(function (p1, p2) {
return p1.name < p2.name ? -1 : 1;
});
},
@@ -130,14 +130,6 @@ AWS.QueryParamList = inherit({
params.push(param.toString());
});
return params.join('&');
- },
-
- getValue: function getValue(name) {
- for (var i = 0; i < this.params.length; i++) {
- if (this.params[i].name === name)
- return this.params[i].value;
- }
- return null;
}
});
View
@@ -22,9 +22,9 @@ AWS.SQS = AWS.Service.defineService('./services/sqs.api', {
},
buildEndpoint: function buildEndpoint(request) {
- var url = request.httpRequest.params.getValue('QueueUrl');
+ var url = request.httpRequest.params.params.QueueUrl;
if (url) {
- request.httpRequest.endpoint = new AWS.Endpoint(url);
+ request.httpRequest.endpoint = new AWS.Endpoint(url.value);
// signature version 4 requires the region name to be set,
// sqs queue urls contain the region name
View
@@ -34,6 +34,7 @@ AWS.Signers.V2 = inherit(AWS.Signers.RequestSigner, {
if (credentials.sessionToken)
r.params.add('SecurityToken', credentials.sessionToken);
+ delete r.params.Signature; // delete old Signature for re-signing
r.params.add('Signature', this.signature(credentials));
r.body = r.params.toString();
View
@@ -286,6 +286,14 @@ AWS.util = {
}
},
+ values: function values(object) {
+ var list = [];
+ AWS.util.arrayEach(object, function(value) {
+ list.push(value);
+ });
+ return list;
+ },
+
update: function update(obj1, obj2) {
AWS.util.each(obj2, function iterator(key, item) {
obj1[key] = item;
View
@@ -257,6 +257,10 @@ describe 'AWS.util.arrayEach', ->
expect(total).toEqual(1)
+describe 'AWS.util.values', ->
+ it 'returns values of a key-value map', ->
+ expect(AWS.util.values(a: 1, b: 2, c: 3)).toEqual([1, 2, 3])
+
describe 'AWS.util.copy', ->
it 'does not copy null or undefined', ->
expect(AWS.util.copy(null)).toEqual(null)

0 comments on commit d4fc3e9

Please sign in to comment.