aws-sdk
Advanced tools
Comparing version 0.9.1-pre.2 to 0.9.2-pre.3
@@ -24,4 +24,4 @@ # Examples | ||
s3.client.listBuckets(function(err, data) { | ||
for (var index in resp.data.Buckets) { | ||
var bucket = resp.data.Buckets[index]; | ||
for (var index in data.Buckets) { | ||
var bucket = data.Buckets[index]; | ||
console.log("Bucket: ", bucket.Name, ' : ', bucket.CreationDate); | ||
@@ -39,5 +39,5 @@ } | ||
var s3 = new AWS.S3(); | ||
s3.client.createBucket({Bucket: 'myBucket'}, function(err, data) { | ||
s3.client.createBucket({Bucket: 'myBucket'}, function() { | ||
var data = {Bucket: 'myBucket', Key: 'myKey', Body: 'Hello!'}; | ||
s3.client.putObject(data).done(function(resp) { | ||
s3.client.putObject(data, function() { | ||
console.log("Successfully uploaded data to myBucket/myKey"); | ||
@@ -48,5 +48,21 @@ }); | ||
### Amazon S3: Streaming Objects to Files on Disk (getObject) | ||
You can use the `createReadStream()` method on a request object to | ||
get a handle to a stream object which supports piping raw HTTP | ||
body data to a file. This is especially useful when streaming | ||
objects to streams like filesystem objects. The following example | ||
shows how you can stream an object from Amazon S3 directly to a file | ||
on disk: | ||
```js | ||
var s3 = new AWS.S3(); | ||
var params = {Bucket: 'myBucket', Key: 'myImageFile.jpg'}; | ||
var file = require('fs').createWriteStream('/path/to/file.jpg'); | ||
s3.client.getObject(params).createReadStream().pipe(file); | ||
``` | ||
## Amazon DynamoDB | ||
### Amazon DynamoDB: Listing Tables | ||
### Amazon DynamoDB: Listing Tables (listTables) | ||
@@ -58,4 +74,4 @@ The following example will list all tables in a DynamoDB instance: | ||
db.client.listTables(function(err, data) { | ||
console.log(resp.data.TableNames); | ||
console.log(data.TableNames); | ||
}); | ||
``` |
@@ -30,11 +30,11 @@ # @title Making Requests | ||
Note that if you do not specify a callback, the operation will | ||
return an `AWS.AWSRequest` object that must be manually sent using | ||
return an `AWS.Request` object that must be manually sent using | ||
the `send()` method: | ||
```js | ||
// create the AWS.AWSRequest object | ||
// create the AWS.Request object | ||
var request = new AWS.EC2().client.describeInstances(); | ||
// register a callback to report on the data | ||
request.done(function(resp) { | ||
request.on('success', function(resp) { | ||
console.log(resp.data); // log the successful data response | ||
@@ -47,6 +47,6 @@ }); | ||
### The Response Object (`AWS.AWSResponse`) | ||
### The Response Object (`AWS.Response`) | ||
The response object is passed into each callback function so | ||
that you can access response data. The `AWS.AWSResponse` object that | ||
that you can access response data. The `AWS.Response` object that | ||
is passed in contains two important properties to get at this data: | ||
@@ -66,3 +66,3 @@ | ||
```js | ||
> resp.data | ||
> response.data | ||
{ TableNames: | ||
@@ -90,10 +90,16 @@ [ 'table1', 'table2', ... ] } | ||
### Supported Callbacks | ||
#### The `request` property | ||
Currently, you can register callbacks for various events by | ||
either using the simplified callback syntax, or by using the callback | ||
methods on the returned `AWS.AWSRequest` object. | ||
Access to the originating request object is available through this | ||
property. For example, to access the parameters that were sent | ||
with a request: | ||
#### Simplified Callback Method | ||
```js | ||
s3.getObject({Bucket: 'bucket', Key: 'key'}).on('success', function(response) { | ||
console.log("Key was", response.request.params.Key); | ||
}).send(); | ||
``` | ||
### Simplified Callback Method | ||
Each operation supports a simplified callback that can be passed as the last | ||
@@ -108,5 +114,5 @@ parameter to any low-level client operation. The callback function should | ||
if (err) { | ||
console.log(error); // error is AWSResponse.error | ||
console.log(error); // error is Response.error | ||
} else { | ||
console.log(data); // data is AWSResponse.data | ||
console.log(data); // data is Response.data | ||
} | ||
@@ -127,3 +133,3 @@ }); | ||
The error and data parameters accepted are equivalent to the `error` and | ||
`data` properties discussed in the `AWS.AWSResponse` response object section | ||
`data` properties discussed in the `AWS.Response` response object section | ||
above. | ||
@@ -140,7 +146,7 @@ | ||
#### AWS.AWSRequest Callbacks | ||
### AWS.Request Events | ||
You can alternatively register callbacks on events provided by the | ||
`AWS.AWSRequest` object returned by each low-level client operation method. | ||
This request object exposes the `done`, `fail`, `data`, and `always` | ||
`AWS.Request` object returned by each low-level client operation method. | ||
This request object exposes the `success`, `error`, `complete`, and `httpData` | ||
events, each taking a callback that accepts the response object. | ||
@@ -152,5 +158,5 @@ | ||
##### `done(function(response) { ... })` | ||
#### `on('success', function(response) { ... })` | ||
This event registers a callback to be called when a successful response | ||
This event triggers when a successful response | ||
from the server is returned. The response contains a `.data` field | ||
@@ -177,12 +183,15 @@ with the serialized response data from the service. | ||
##### `fail(function(response) { ... })` | ||
#### `on('error', function(error, response) { ... })` | ||
The `fail` event works similarly to the `done` event, except that it | ||
The `error` event works similarly to the `success` event, except that it | ||
triggers in the case of a request failure. In this case, `response.data` | ||
will be `null` and the `response.error` field will be filled with | ||
the error data: | ||
the error data. Note that the `error` object is also passed directly | ||
as the first parameter to the event: | ||
```js | ||
s3.config.credentials.accessKeyId = 'invalid'; | ||
s3.client.listBuckets().fail(function(response) { | ||
s3.client.listBuckets().fail(function(error, response) { | ||
console.log(error); | ||
// or: | ||
console.log(response.error); | ||
@@ -198,19 +207,6 @@ }).send(); | ||
##### `data(function(response) { ... })` | ||
#### `on('complete', function(response) { ... })` | ||
<p class="note">If you register a <code>data</code> callback, | ||
<code>response.data</code> will not contain serialized output | ||
for the entire request. Instead, it will be your responsibility | ||
to stream the output and de-serialize the result on your own. | ||
</p> | ||
The `data` callback is used to stream response data from the | ||
service packet-by-packet. This event is mostly used for large responses, | ||
when it is inefficient (or impossible) to load the entire response into | ||
memory. | ||
##### `always(function(response) { ... })` | ||
The `always` event triggers a callback in any final state of a request, i.e., | ||
both `done` and `fail`. Use this callback to handle any request cleanup | ||
The `complete` event triggers a callback in any final state of a request, i.e., | ||
both `success` and `error`. Use this callback to handle any request cleanup | ||
that must be executed regardless of the success state. Note that if you | ||
@@ -222,3 +218,3 @@ do intend to use response data inside of this callback, you must check | ||
```js | ||
request.always(function(response) { | ||
request.on('complete', function(response) { | ||
if (response.error) { | ||
@@ -232,19 +228,18 @@ // an error occurred, handle it | ||
## Binding Custom Context Data on a Callback | ||
#### `on('httpData', function(chunk, response) { ... })` | ||
By default, the `this` context of a callback function registered on an | ||
event will be the `AWS.AWSResponse` object returned from the service. | ||
In some cases, it may be necessary to pass extra custom context to these | ||
functions; in these cases, you can bind a custom value to be used as the | ||
`this` context object when the callbacks are executed. To do so, pass | ||
the `bind` option to the asynchronous registration method: | ||
<p class="note">If you register a <code>httpData</code> callback, | ||
<code>response.data</code> will still contain serialized output | ||
for the entire request. It will be your responsibility to remove | ||
the default 'httpData' listener if you do not wish to have the | ||
extra parsing and memory overhead from the built-in handlers. | ||
</p> | ||
```js | ||
var myContext = new Object(); | ||
request.always(function(response) { | ||
console.log(this === myContext); | ||
}, {bind: myContext}).send(); | ||
``` | ||
The `httpData` event is used to stream response data from the | ||
service packet-by-packet. This event is mostly used for large responses, | ||
when it is inefficient (or impossible) to load the entire response into | ||
memory. | ||
The above callback will print `true` when the callback function is executed. | ||
Note that this event contains an extra `chunk` parameter containing the | ||
actual data passed on by the server. | ||
@@ -260,9 +255,9 @@ ## Multiple Callbacks and Chaining | ||
request. | ||
done(function(response) { | ||
on('success', function(response) { | ||
console.log("Success!"); | ||
}). | ||
fail(function(response) { | ||
on('error', function(response) { | ||
console.log("Error!"); | ||
}). | ||
always(function(response) { | ||
on('complete', function() { | ||
console.log("Always!"); | ||
@@ -269,0 +264,0 @@ }). |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -19,3 +19,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
this.Before("@s3", function (callback) { | ||
this.s3 = new this.AWS.S3.Client(); | ||
this.client = this.s3 = new this.AWS.S3.Client(); | ||
callback(); | ||
@@ -22,0 +22,0 @@ }); |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -34,7 +34,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
}); | ||
}); | ||
this.When(/^I write "([^"]*)" to the key "([^"]*)"$/, function(contents, key, next) { | ||
var params = {Bucket:this.sharedBucket,Key:key,Body:contents}; | ||
this.When(/^I write (buffer )?"([^"]*)" to the key "([^"]*)"$/, function(buffer, contents, key, next) { | ||
var params = {Bucket: this.sharedBucket, Key: key, Body: buffer ? new Buffer(contents) : contents}; | ||
this.request('s3', 'putObject', params, next); | ||
@@ -46,3 +45,3 @@ }); | ||
this.s3.getObject({Bucket:this.sharedBucket,Key:key}, function(err, data) { | ||
if (data && data.Body == contents) | ||
if (data && data.Body.toString().replace("\n", "") == contents) | ||
next(); | ||
@@ -55,2 +54,9 @@ else | ||
this.When(/^I copy an object with the key "([^"]*)" to "([^"]*)"$/, function(key1, key2, next) { | ||
var params = { | ||
Bucket: this.sharedBucket, Key: key2, CopySource: '/' + this.sharedBucket + '/' + key1 | ||
} | ||
this.request('s3', 'copyObject', params, next); | ||
}); | ||
this.When(/^I delete the object with the key "([^"]*)"$/, function(key, next) { | ||
@@ -74,2 +80,23 @@ var params = {Bucket:this.sharedBucket,Key:key}; | ||
this.When(/^I write file "([^"]*)" to the key "([^"]*)"$/, function(filename, key, next) { | ||
var fs = require('fs'); | ||
var params = {Bucket: this.sharedBucket, Key: key, Body: | ||
fs.createReadStream(__dirname + '/../../support/fixtures/' + filename)}; | ||
this.request('s3', 'putObject', params, next); | ||
}); | ||
this.When(/^I stream key "([^"]*)"$/, function(key, callback) { | ||
var params = {Bucket: this.sharedBucket, Key: key}; | ||
var world = this; | ||
this.result = ''; | ||
this.client.getObject(params).createReadStream(). | ||
on('end', function() { callback(); }). | ||
on('data', function(d) { world.result += d.toString(); }); | ||
}); | ||
this.Then(/^the streamed data should contain "([^"]*)"$/, function(data, callback) { | ||
if (data === this.result.replace("\n", "")) callback(); | ||
else callback.fail("Expected " + data + ", got " + this.result); | ||
}); | ||
// this scenario is a work around for not having an after all hook | ||
@@ -79,3 +106,2 @@ this.Then(/^I delete the shared bucket$/, function(next) { | ||
}); | ||
}; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -22,4 +22,4 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
* | ||
* this.When(/^I something is eventually consistent$/, function(next) { | ||
* this.eventually(function(retry) { | ||
* this.When(/^I something is eventually consistent$/, function(callback) { | ||
* this.eventually(callback, function(retry) { | ||
* doSomething(function(response) { | ||
@@ -29,3 +29,3 @@ * if (response != notWhatIExpect) { | ||
* } else { | ||
* next(); | ||
* callback(); | ||
* } | ||
@@ -42,3 +42,3 @@ * }); | ||
*/ | ||
eventually: function eventually(next, block, options) { | ||
eventually: function eventually(callback, block, options) { | ||
@@ -48,3 +48,3 @@ if (!options) options = {}; | ||
if (!options.backoff) options.backoff = 500; | ||
if (!options.maxTime) options.maxTime = 5 * 1000; | ||
if (!options.maxTime) options.maxTime = 5; | ||
@@ -58,3 +58,3 @@ var delay = options.delay; | ||
var now = self.AWS.util.date.getDate(); | ||
if (now - started < options.maxTime) { | ||
if (now - started < options.maxTime * 1000) { | ||
setTimeout(function () { | ||
@@ -65,3 +65,3 @@ delay += options.backoff; | ||
} else { | ||
next.fail(); | ||
callback.fail(); | ||
} | ||
@@ -79,11 +79,21 @@ | ||
*/ | ||
request: function request(svc, operation, params, next) { | ||
this[svc][operation](params).always(function (resp) { | ||
if (resp.error) { | ||
this.unexpectedError(resp, next); | ||
request: function request(svc, operation, params, next, extra) { | ||
var world = this; | ||
if (!svc) svc = this.client; | ||
if (typeof svc == 'string') svc = this[svc]; | ||
svc[operation](params, function(err, data) { | ||
world.error = err; | ||
world.resp = this; | ||
if (extra) { | ||
extra.call(world, this); | ||
next(); | ||
} | ||
else if (err) { | ||
world.unexpectedError(this, next); | ||
} else { | ||
this.resp = resp; | ||
next(); | ||
} | ||
}, { bind: this }).send(); | ||
}); | ||
}, | ||
@@ -97,4 +107,4 @@ | ||
unexpectedError: function unexpectedError(resp, next) { | ||
var svc = resp.service.serviceName; | ||
var op = resp.method; | ||
var svc = resp.request.client.api.serviceName; | ||
var op = resp.request.operation; | ||
var code = resp.error.code; | ||
@@ -101,0 +111,0 @@ var msg = resp.error.message; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -21,4 +21,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
require('./services/ec2'); | ||
require('./services/elastictranscoder'); | ||
require('./services/s3'); | ||
require('./services/ses'); | ||
require('./services/simpleworkflow'); | ||
require('./services/sqs'); |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -17,2 +17,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('./core'); | ||
require('./event_listeners'); | ||
var inherit = AWS.util.inherit; | ||
@@ -36,2 +37,4 @@ | ||
api: {}, | ||
defaultRetryCount: 3, | ||
@@ -44,5 +47,8 @@ | ||
} | ||
var request = new AWS.AWSRequest(this, operation, params); | ||
var request = new AWS.Request(this, operation, params); | ||
this.addAllRequestListeners(request); | ||
if (callback) { | ||
request.always(function (resp) { | ||
request.on('complete', function (resp) { | ||
callback.call(resp, resp.error, resp.data); | ||
@@ -52,54 +58,38 @@ }); | ||
} | ||
return request; | ||
}, | ||
parseResponse: function parseResponse(httpResponse, method, callback) { | ||
var error = null, data = null; | ||
try { | ||
if (this.successfulResponse(httpResponse, method)) { | ||
data = this.extractData(httpResponse, method); | ||
} else { | ||
error = this.extractError(httpResponse, method); | ||
error.statusCode = httpResponse.statusCode; | ||
error.retryable = this.retryableError(error, method); | ||
} | ||
} catch (err) { | ||
// unrecoverable error trying to parse the response data/error | ||
error = err; | ||
} | ||
callback.call(this, error, data); | ||
addAllRequestListeners: function addAllRequestListeners(request) { | ||
var svc = this.serviceInterface(); | ||
request.addListeners(AWS.EventListeners.Core); | ||
if (svc) request.addListeners(svc); | ||
this.setupRequestListeners(request); | ||
}, | ||
successfulResponse: function successfulResponse(httpResponse) { | ||
return httpResponse.statusCode < 300; | ||
setupRequestListeners: function setupRequestListeners() { | ||
}, | ||
newHttpRequest: function newHttpRequest() { | ||
var serviceName = this.serviceName; | ||
var credentials = AWS.util.copy(this.config.credentials); | ||
var signatureVersion = this.signatureVersion; | ||
var httpRequest = new AWS.HttpRequest(); | ||
httpRequest.endpoint = AWS.util.copy(this.endpoint); | ||
httpRequest.region = this.config.region; | ||
httpRequest.sign = function sign() { | ||
/*jshint newcap:false*/ | ||
var signer = new signatureVersion(httpRequest, serviceName); | ||
signer.addAuthorization(credentials); | ||
}; | ||
return httpRequest; | ||
serviceInterface: function serviceInterface() { | ||
/*jshint maxcomplexity:8*/ | ||
switch (this.api.format) { | ||
case 'query': return AWS.EventListeners.Query; | ||
case 'json': return AWS.EventListeners.Json; | ||
case 'rest-json': return AWS.EventListeners.RestJson; | ||
case 'rest-xml': return AWS.EventListeners.RestXml; | ||
} | ||
if (this.api.format) { | ||
throw new Error('Invalid service `format\' ' + | ||
this.api.format + ' in API config'); | ||
} | ||
}, | ||
retryableError: function retryableError(error) { | ||
if (this.expiredCredentialsError(error)) return true; | ||
if (this.throttledError(error)) return true; | ||
if (error.statusCode >= 500) return true; | ||
return false; | ||
successfulResponse: function successfulResponse(resp) { | ||
return resp.httpResponse.statusCode < 300; | ||
}, | ||
// How many times a failed request should be retried before giving up. | ||
// the defaultRetryCount can be overriden by client classes. | ||
/** | ||
* How many times a failed request should be retried before giving up. | ||
* the defaultRetryCount can be overriden by client classes. | ||
*/ | ||
numRetries: function numRetries() { | ||
@@ -122,2 +112,14 @@ if (this.config.maxRetries !== undefined) { | ||
retryableError: function retryableError(error) { | ||
if (this.networkingError(error)) return true; | ||
if (this.expiredCredentialsError(error)) return true; | ||
if (this.throttledError(error)) return true; | ||
if (error.statusCode >= 500) return true; | ||
return false; | ||
}, | ||
networkingError: function networkingError(error) { | ||
return error.code == 'NetworkingError'; | ||
}, | ||
expiredCredentialsError: function expiredCredentialsError(error) { | ||
@@ -137,3 +139,3 @@ // TODO : this only handles *one* of the expired credential codes | ||
} else { | ||
var host = this.serviceName + '.' + this.config.region + '.amazonaws.com'; | ||
var host = this.api.serviceName + '.' + this.config.region + '.amazonaws.com'; | ||
this.endpoint = new AWS.Endpoint(host, this.config); | ||
@@ -147,3 +149,5 @@ } | ||
// adds one method for each operation described in the api configuration | ||
/** | ||
* Adds one method for each operation described in the api configuration | ||
*/ | ||
defineMethods: function defineMethods(svc) { | ||
@@ -155,6 +159,16 @@ AWS.util.each(svc.prototype.api.operations, function iterator(method) { | ||
}); | ||
}, | ||
defineClient: function defineClient(apiConfig, features) { | ||
apiConfig = apiConfig || {}; | ||
if (typeof apiConfig === 'string') { | ||
apiConfig = require(apiConfig); | ||
} | ||
var client = AWS.util.inherit(AWS.Client, features || {}); | ||
client.prototype.api = apiConfig; | ||
AWS.Client.defineMethods(client); | ||
return client; | ||
} | ||
}); | ||
module.exports = AWS.Client; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -170,6 +170,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
}, | ||
region: undefined, | ||
region: function() { | ||
return process.env.AWS_REGION || process.env.AMAZON_REGION; | ||
}, | ||
maxRetries: undefined, | ||
sslEnabled: true, | ||
s3ForcePathStyle: false | ||
s3ForcePathStyle: false, | ||
dynamoDbCrc32: true | ||
}, | ||
@@ -176,0 +179,0 @@ |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -28,3 +28,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
*/ | ||
VERSION: '0.9.1-pre.2', | ||
VERSION: 'v0.9.2-pre.3', | ||
@@ -34,7 +34,3 @@ /** | ||
*/ | ||
RequestSigner: AWS.util.inherit({ | ||
constructor: function RequestSigner(request) { | ||
this.request = request; | ||
} | ||
}), | ||
ServiceInterface: {}, | ||
@@ -50,4 +46,7 @@ /** | ||
require('./http'); | ||
require('./promise'); | ||
require('./event_emitter'); | ||
require('./event_listeners'); | ||
require('./request'); | ||
require('./client'); | ||
require('./service'); | ||
require('./request_signer'); |
187
lib/http.js
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -17,2 +17,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('./core'); | ||
var Stream = require('stream').Stream; | ||
var inherit = AWS.util.inherit; | ||
@@ -101,3 +102,3 @@ | ||
*/ | ||
constructor: function HttpRequest() { | ||
constructor: function HttpRequest(endpoint, region) { | ||
this.method = 'POST'; | ||
@@ -107,5 +108,5 @@ this.path = '/'; | ||
this.headers['User-Agent'] = AWS.util.userAgent(); | ||
this.body = undefined; | ||
this.endpoint = undefined; | ||
this.region = undefined; | ||
this.body = ''; | ||
this.endpoint = AWS.util.copy(endpoint); | ||
this.region = region; | ||
}, | ||
@@ -148,5 +149,5 @@ | ||
constructor: function HttpResponse() { | ||
this.statusCode = null; | ||
this.statusCode = undefined; | ||
this.headers = {}; | ||
this.body = null; | ||
this.body = undefined; | ||
} | ||
@@ -158,134 +159,12 @@ }); | ||
*/ | ||
AWS.RequestHandler = inherit({ | ||
constructor: function RequestHandler(awsRequest) { | ||
this.awsRequest = awsRequest; | ||
this.awsResponse = awsRequest.awsResponse; | ||
this.client = awsRequest.client; | ||
this.operation = awsRequest.operation; | ||
this.params = awsRequest.params; | ||
}, | ||
makeRequest: function makeRequest() { | ||
var httpRequest = this.client.buildRequest(this.operation, this.params); | ||
httpRequest.sign(); | ||
this.sendRequest(httpRequest); | ||
}, | ||
sendRequest: function sendRequest(httpRequest) { | ||
var httpResponse = new AWS.HttpResponse(); | ||
this.awsResponse.httpResponse = httpResponse; | ||
this.awsResponse.httpRequest = httpRequest; | ||
var self = this; | ||
AWS.HttpClient.getInstance().handleRequest(httpRequest, { | ||
onHeaders: function onHeaders(statusCode, headers) { | ||
httpResponse.statusCode = statusCode; | ||
httpResponse.headers = headers; | ||
}, | ||
onData: function onData(data) { | ||
if (httpResponse.body === null) { | ||
httpResponse.body = data; | ||
} else { | ||
httpResponse.body += data; | ||
} | ||
self.handleHttpData(httpResponse); | ||
}, | ||
onEnd: function onEnd() { | ||
if (httpResponse.body) { | ||
httpResponse.body = httpResponse.body.toString(); | ||
} | ||
if (httpResponse.statusCode == 307) { | ||
self.redirect(httpRequest, httpResponse); | ||
} else { | ||
self.handleHttpResponse(httpResponse); | ||
} | ||
}, | ||
onError: function onError(error) { | ||
self.retryRequest(error); | ||
} | ||
}); | ||
}, | ||
handleHttpData: function handleHttpData(httpResponse) { | ||
if (this.awsRequest.callbacks.data.length === 0) return; | ||
this.awsRequest.notifyData(httpResponse.body); | ||
httpResponse.body = null; | ||
}, | ||
// Called when the http client returns a response. Successfull http requests | ||
// may still contain an error (e.g. 400, 500, etc) | ||
redirect: function redirect(httpRequest, httpResponse) { | ||
/*jshint sub:true */ | ||
httpRequest.endpoint = new AWS.Endpoint(httpResponse.headers['location']); | ||
this.sendRequest(httpRequest); | ||
}, | ||
handleHttpResponse: function handleHttpResponse(httpResponse) { | ||
var self = this; | ||
this.client.parseResponse(httpResponse, this.operation, function (error, data) { | ||
if (error) | ||
self.handleError(error); | ||
else | ||
self.awsRequest.notifyDone(data); | ||
}); | ||
}, | ||
handleError: function handleError(error) { | ||
if (error.retryable) { | ||
this.retryRequest(error); | ||
} else { | ||
this.awsRequest.notifyFail(error); | ||
} | ||
}, | ||
retryRequest: function retryRequest(error) { | ||
var delays = this.client.retryDelays(); | ||
var delay = delays[this.awsResponse.retryCount]; | ||
this.awsResponse.retryCount += 1; | ||
if (delay !== undefined) { | ||
var self = this; | ||
setTimeout(function delayRetry() { | ||
self.makeRequest(); | ||
}, delay); | ||
} else { | ||
this.awsRequest.notifyFail(error); // retried too many times | ||
} | ||
} | ||
}); | ||
/** | ||
* @api private | ||
*/ | ||
AWS.NodeHttpClient = inherit({ | ||
constructor: function NodeHttpClient() {}, | ||
handleRequest: function handleRequest(request, callbacks) { | ||
handleRequest: function handleRequest(request, response) { | ||
var options = { | ||
host: request.endpoint.hostname, | ||
port: request.endpoint.port, | ||
method: request.method, | ||
headers: request.headers, | ||
path: request.path | ||
host: request.httpRequest.endpoint.hostname, | ||
port: request.httpRequest.endpoint.port, | ||
method: request.httpRequest.method, | ||
headers: request.httpRequest.headers, | ||
path: request.httpRequest.path | ||
}; | ||
var useSSL = request.endpoint.protocol === 'https:'; | ||
var useSSL = request.httpRequest.endpoint.protocol === 'https:'; | ||
var client = useSSL ? require('https') : require('http'); | ||
@@ -299,16 +178,32 @@ | ||
var req = client.request(options, function onResponse(resp) { | ||
callbacks.onHeaders(resp.statusCode, resp.headers); | ||
resp.on('data', callbacks.onData); | ||
resp.on('end', callbacks.onEnd); | ||
var stream = this.setupEvents(client, options, request, response); | ||
if (request.httpRequest.body instanceof Stream) { | ||
request.httpRequest.body.pipe(stream, {end: false}); | ||
} else if (request.httpRequest.body) { | ||
stream.write(request.httpRequest.body); | ||
} | ||
stream.end(); | ||
}, | ||
setupEvents: function setupEvents(client, options, request, response) { | ||
var stream = client.request(options, function onResponse(httpResponse) { | ||
request.emit('httpHeaders', httpResponse.statusCode, | ||
httpResponse.headers, response); | ||
httpResponse.on('data', function onData(data) { | ||
request.emit('httpData', data, response); | ||
}); | ||
httpResponse.on('end', function onEnd() { | ||
request.emitEvents(response, 'httpDone'); | ||
}); | ||
}); | ||
if (request.body) req.write(request.body); | ||
stream.on('error', function (err) { | ||
request.emit('httpError', AWS.util.error(err, | ||
{code: 'NetworkingError', retryable: true}), response); | ||
}); | ||
req.end(); | ||
req.on('error', function (e) { | ||
callbacks.onError(e); | ||
}); | ||
return stream; | ||
} | ||
}); | ||
@@ -315,0 +210,0 @@ |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -23,7 +23,18 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
AWS.Service = inherit({ | ||
constructor: function Service(config) { | ||
this.client = new this.constructor.Client(config); | ||
} | ||
}); | ||
}); | ||
/** | ||
* @api private | ||
*/ | ||
AWS.Service.defineService = function defineService(apiConfig, features) { | ||
if (typeof apiConfig !== 'string') { | ||
features = apiConfig; apiConfig = null; | ||
} | ||
features = features || {}; | ||
var svc = inherit(AWS.Service, features.Service || {}); | ||
svc.Client = AWS.Client.defineClient(apiConfig, features.Client); | ||
return svc; | ||
}; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -16,7 +16,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('../core'); | ||
AWS.DynamoDB.Client.prototype.api = { | ||
module.exports = { | ||
format: 'json', | ||
targetPrefix: 'DynamoDB_20111205.', | ||
signatureVersion: 'v4', | ||
serviceName: 'dynamodb', | ||
targetPrefix: 'DynamoDB_20111205', | ||
timestampFormat: 'iso8601', | ||
@@ -23,0 +23,0 @@ operations: { |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -17,55 +17,56 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('../core'); | ||
var inherit = AWS.util.inherit; | ||
require('../json_client'); | ||
require('../sigv4'); | ||
AWS.DynamoDB = AWS.Service.defineService('./services/dynamodb.api', { | ||
Client: { | ||
setupRequestListeners: function setupRequestListeners(request) { | ||
if (request.client.config.dynamoDbCrc32) { | ||
request.addListener('extractData', this.checkCrc32); | ||
} | ||
}, | ||
AWS.DynamoDB = inherit({ | ||
/** | ||
* @api private | ||
*/ | ||
checkCrc32: function checkCrc32(resp) { | ||
if (!resp.request.client.crc32IsValid(resp)) { | ||
resp.error = AWS.util.error(new Error(), { | ||
code: 'CRC32CheckFailed', | ||
message: 'CRC32 integrity check failed', | ||
retryable: true | ||
}); | ||
} | ||
}, | ||
constructor: function DynamoDB(options) { | ||
AWS.Service.call(this, options); | ||
} | ||
/** | ||
* @api private | ||
*/ | ||
crc32IsValid: function crc32IsValid(resp) { | ||
var crc = resp.httpResponse.headers['x-amz-crc32']; | ||
if (!crc) return true; // no (valid) CRC32 header | ||
return parseInt(crc, 10) == AWS.util.crypto.crc32(resp.httpResponse.body); | ||
}, | ||
}); | ||
/** | ||
* @api private | ||
*/ | ||
defaultRetryCount: 10, | ||
AWS.DynamoDB.Client = inherit(AWS.JSONClient, { | ||
/** | ||
* @api private | ||
*/ | ||
constructor: function DynamoDBClient(options) { | ||
this.serviceName = 'dynamodb'; | ||
AWS.JSONClient.call(this, options); | ||
}, | ||
/** | ||
* @api private | ||
*/ | ||
signatureVersion: AWS.SigV4, | ||
/** | ||
* @api private | ||
*/ | ||
defaultRetryCount: 10, | ||
/** | ||
* @api private | ||
*/ | ||
retryDelays: function retryDelays() { | ||
var retryCount = this.numRetries(); | ||
var delays = []; | ||
for (var i = 0; i < retryCount; ++i) { | ||
if (i === 0) { | ||
delays.push(0); | ||
} else { | ||
delays.push(50 * Math.pow(2, i - 1)); | ||
/** | ||
* @api private | ||
*/ | ||
retryDelays: function retryDelays() { | ||
var retryCount = this.numRetries(); | ||
var delays = []; | ||
for (var i = 0; i < retryCount; ++i) { | ||
if (i === 0) { | ||
delays.push(0); | ||
} else { | ||
delays.push(50 * Math.pow(2, i - 1)); | ||
} | ||
} | ||
return delays; | ||
} | ||
return delays; | ||
} | ||
}); | ||
require('./dynamodb.api'); | ||
AWS.Client.defineMethods(AWS.DynamoDB.Client); | ||
module.exports = AWS.DynamoDB; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -17,49 +17,31 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('../core'); | ||
var inherit = AWS.util.inherit; | ||
require('../query_client'); | ||
require('../sigv2'); | ||
AWS.EC2 = AWS.Service.defineService('./services/ec2.api', { | ||
Client: { | ||
setupRequestListeners: function setupRequestListeners(request) { | ||
request.removeListener('extractError', AWS.EventListeners.Query.EXTRACT_ERROR); | ||
request.addListener('extractError', this.extractError); | ||
}, | ||
AWS.EC2 = inherit({ | ||
constructor: function EC2(options) { | ||
AWS.Service.call(this, options); | ||
/** | ||
* @api private | ||
*/ | ||
extractError: function extractError(resp) { | ||
// EC2 nests the error code and message deeper than other AWS Query services. | ||
var httpResponse = resp.httpResponse; | ||
var data = new AWS.XML.Parser({}).parse(httpResponse.body.toString() || ''); | ||
if (data.Errors) | ||
resp.error = AWS.util.error(new Error(), { | ||
code: data.Errors.Error.Code, | ||
message: data.Errors.Error.Message | ||
}); | ||
else | ||
resp.error = AWS.util.error(new Error(), { | ||
code: httpResponse.statusCode, | ||
message: null | ||
}); | ||
} | ||
} | ||
}); | ||
AWS.EC2.Client = inherit(AWS.QueryClient, { | ||
constructor: function EC2Client(options) { | ||
this.serviceName = 'ec2'; | ||
AWS.QueryClient.call(this, options); | ||
}, | ||
/** | ||
* @api private | ||
*/ | ||
signatureVersion: AWS.SigV2, | ||
/** | ||
* @api private | ||
*/ | ||
extractError: function extractError(httpResponse) { | ||
// EC2 nests the error code and message deeper than other AWS Query services. | ||
var data = new AWS.XML.Parser({}).parse(httpResponse.body); | ||
if (data.Errors) | ||
return { | ||
code: data.Errors.Error.Code, | ||
message: data.Errors.Error.Message | ||
}; | ||
else | ||
return { | ||
code: httpResponse.statusCode, | ||
message: null | ||
}; | ||
} | ||
}); | ||
require('./ec2.api'); | ||
AWS.Client.defineMethods(AWS.EC2.Client); | ||
module.exports = AWS.EC2; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -16,6 +16,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('../core'); | ||
AWS.S3.Client.prototype.api = { | ||
module.exports = { | ||
format: 'rest-xml', | ||
signatureVersion: 's3', | ||
serviceName: 's3', | ||
xmlNamespace: 'http://s3.amazonaws.com/doc/2006-03-01/', | ||
@@ -48,3 +48,2 @@ timestampFormat: 'rfc822', | ||
i: { | ||
n: 'MultipartUpload', | ||
m: { | ||
@@ -63,13 +62,20 @@ Bucket: { | ||
}, | ||
Parts: { | ||
n: 'Part', | ||
t: 'a', | ||
f: 1, | ||
MultipartUpload: { | ||
n: 'CompleteMultipartUpload', | ||
t: 'o', | ||
l: 'body', | ||
m: { | ||
t: 'o', | ||
m: { | ||
PartNumber: { | ||
t: 'i' | ||
}, | ||
ETag: { | ||
Parts: { | ||
n: 'Part', | ||
t: 'a', | ||
f: 1, | ||
m: { | ||
t: 'o', | ||
m: { | ||
PartNumber: { | ||
t: 'i' | ||
}, | ||
ETag: { | ||
} | ||
} | ||
} | ||
@@ -124,6 +130,31 @@ } | ||
}, | ||
WebsiteRedirectLocation: { | ||
CopySource: { | ||
l: 'header', | ||
n: 'x-amz-website-redirect-location' | ||
n: 'x-amz-copy-source', | ||
r: 1 | ||
}, | ||
CopySourceIfMatch: { | ||
t: 't', | ||
l: 'header', | ||
n: 'x-amz-copy-source-if-match' | ||
}, | ||
CopySourceIfNoneMatch: { | ||
t: 't', | ||
l: 'header', | ||
n: 'x-amz-copy-source-if-none-match' | ||
}, | ||
CopySourceIfUnmodifiedSince: { | ||
t: 't', | ||
l: 'header', | ||
n: 'x-amz-copy-source-if-unmodified-since' | ||
}, | ||
CopySourceIfModifiedSince: { | ||
t: 't', | ||
l: 'header', | ||
n: 'x-amz-copy-source-if-modified-since' | ||
}, | ||
StorageClass: { | ||
l: 'header', | ||
n: 'x-amz-storage-class' | ||
}, | ||
ACL: { | ||
@@ -137,6 +168,2 @@ l: 'header', | ||
}, | ||
GrantWrite: { | ||
l: 'header', | ||
n: 'x-amz-grant-write' | ||
}, | ||
GrantReadACP: { | ||
@@ -154,34 +181,39 @@ l: 'header', | ||
}, | ||
ServerSideEncryption: { | ||
CacheControl: { | ||
l: 'header', | ||
n: 'x-amz-server-side-encryption' | ||
n: 'Cache-Control' | ||
}, | ||
StorageClass: { | ||
ContentDisposition: { | ||
l: 'header', | ||
n: 'x-amz-storage-class' | ||
n: 'Content-Disposition' | ||
}, | ||
CopySource: { | ||
ContentEncoding: { | ||
l: 'header', | ||
n: 'x-amz-copy-source', | ||
r: 1 | ||
n: 'Content-Encoding' | ||
}, | ||
CopySourceIfMatch: { | ||
t: 't', | ||
ContentLanguage: { | ||
l: 'header', | ||
n: 'x-amz-copy-source-if-match' | ||
n: 'Content-Language' | ||
}, | ||
CopySourceIfNoneMatch: { | ||
t: 't', | ||
ContentType: { | ||
l: 'header', | ||
n: 'x-amz-copy-source-if-none-match' | ||
n: 'Content-Type' | ||
}, | ||
CopySourceIfUnmodifiedSince: { | ||
Expires: { | ||
t: 't', | ||
l: 'header', | ||
n: 'x-amz-copy-source-if-unmodified-since' | ||
n: 'Expires' | ||
}, | ||
CopySourceIfModifiedSince: { | ||
t: 't', | ||
WebsiteRedirectLocation: { | ||
l: 'header', | ||
n: 'x-amz-copy-source-if-modified-since' | ||
n: 'x-amz-website-redirect-location' | ||
}, | ||
ServerSideEncryption: { | ||
l: 'header', | ||
n: 'x-amz-server-side-encryption' | ||
}, | ||
Metadata: { | ||
t: 'm', | ||
l: 'header', | ||
n: 'x-amz-meta-' | ||
} | ||
@@ -219,3 +251,2 @@ } | ||
i: { | ||
n: 'CreateBucketConfiguration', | ||
m: { | ||
@@ -226,2 +257,10 @@ Bucket: { | ||
}, | ||
CreateBucketConfiguration: { | ||
t: 'o', | ||
l: 'body', | ||
m: { | ||
LocationConstraint: { | ||
} | ||
} | ||
}, | ||
ACL: { | ||
@@ -250,4 +289,2 @@ l: 'header', | ||
n: 'x-amz-grant-full-control' | ||
}, | ||
LocationConstraint: { | ||
} | ||
@@ -276,2 +313,26 @@ } | ||
}, | ||
StorageClass: { | ||
l: 'header', | ||
n: 'x-amz-storage-class' | ||
}, | ||
ACL: { | ||
l: 'header', | ||
n: 'x-amz-acl' | ||
}, | ||
GrantRead: { | ||
l: 'header', | ||
n: 'x-amz-grant-read' | ||
}, | ||
GrantReadACP: { | ||
l: 'header', | ||
n: 'x-amz-grant-read-acp' | ||
}, | ||
GrantWriteACP: { | ||
l: 'header', | ||
n: 'x-amz-grant-write-acp' | ||
}, | ||
GrantFullControl: { | ||
l: 'header', | ||
n: 'x-amz-grant-full-control' | ||
}, | ||
CacheControl: { | ||
@@ -289,2 +350,6 @@ l: 'header', | ||
}, | ||
ContentLanguage: { | ||
l: 'header', | ||
n: 'Content-Language' | ||
}, | ||
ContentType: { | ||
@@ -299,6 +364,2 @@ l: 'header', | ||
}, | ||
StorageClass: { | ||
l: 'header', | ||
n: 'x-amz-storage-class' | ||
}, | ||
WebsiteRedirectLocation: { | ||
@@ -308,22 +369,2 @@ l: 'header', | ||
}, | ||
ACL: { | ||
l: 'header', | ||
n: 'x-amz-acl' | ||
}, | ||
GrantRead: { | ||
l: 'header', | ||
n: 'x-amz-grant-read' | ||
}, | ||
GrantReadACP: { | ||
l: 'header', | ||
n: 'x-amz-grant-read-acp' | ||
}, | ||
GrantWriteACP: { | ||
l: 'header', | ||
n: 'x-amz-grant-write-acp' | ||
}, | ||
GrantFullControl: { | ||
l: 'header', | ||
n: 'x-amz-grant-full-control' | ||
}, | ||
ServerSideEncryption: { | ||
@@ -456,3 +497,2 @@ l: 'header', | ||
i: { | ||
n: 'Delete', | ||
m: { | ||
@@ -463,24 +503,31 @@ Bucket: { | ||
}, | ||
MFA: { | ||
l: 'header', | ||
n: 'x-amz-mfa' | ||
}, | ||
Quiet: { | ||
t: 'b' | ||
}, | ||
Objects: { | ||
n: 'Object', | ||
t: 'a', | ||
f: 1, | ||
Delete: { | ||
t: 'o', | ||
r: 1, | ||
l: 'body', | ||
m: { | ||
t: 'o', | ||
m: { | ||
Key: { | ||
r: 1 | ||
}, | ||
VersionId: { | ||
Quiet: { | ||
t: 'b' | ||
}, | ||
Objects: { | ||
n: 'Object', | ||
t: 'a', | ||
f: 1, | ||
r: 1, | ||
m: { | ||
t: 'o', | ||
m: { | ||
Key: { | ||
r: 1 | ||
}, | ||
VersionId: { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
MFA: { | ||
l: 'header', | ||
n: 'x-amz-mfa' | ||
} | ||
@@ -866,2 +913,11 @@ } | ||
o: { | ||
RedirectAllRequestsTo: { | ||
t: 'o', | ||
m: { | ||
HostName: { | ||
}, | ||
Protocol: { | ||
} | ||
} | ||
}, | ||
IndexDocument: { | ||
@@ -880,2 +936,35 @@ t: 'o', | ||
} | ||
}, | ||
RoutingRules: { | ||
t: 'a', | ||
m: { | ||
n: 'RoutingRule', | ||
t: 'o', | ||
m: { | ||
Condition: { | ||
t: 'o', | ||
m: { | ||
KeyPrefixEquals: { | ||
}, | ||
HttpErrorCodeReturnedEquals: { | ||
} | ||
} | ||
}, | ||
Redirect: { | ||
t: 'o', | ||
m: { | ||
ReplaceKeyPrefixWith: { | ||
}, | ||
ReplaceKeyWith: { | ||
}, | ||
HttpRedirectCode: { | ||
} | ||
} | ||
}, | ||
HostName: { | ||
}, | ||
Protocol: { | ||
} | ||
} | ||
} | ||
} | ||
@@ -886,3 +975,3 @@ } | ||
m: 'GET', | ||
u: '/{Bucket}/{Key}?versionId={VersionId}', | ||
u: '/{Bucket}/{Key}?versionId={VersionId}&response-content-type={ResponseContentType}&response-content-language={ResponseContentLanguage}&response-expires={ResponseExpires}&response-cache-control={ResponseCacheControl}&response-content-disposition={ResponseContentDisposition}&response-content-encoding={ResponseContentEncoding}', | ||
i: { | ||
@@ -899,25 +988,19 @@ m: { | ||
ResponseContentType: { | ||
l: 'header', | ||
n: 'response-content-type' | ||
l: 'uri' | ||
}, | ||
ResponseContentLanguage: { | ||
l: 'header', | ||
n: 'response-content-language' | ||
l: 'uri' | ||
}, | ||
ResponseExpires: { | ||
t: 't', | ||
l: 'header', | ||
n: 'response-expires' | ||
l: 'uri' | ||
}, | ||
ResponseCacheControl: { | ||
l: 'header', | ||
n: 'response-cache-control' | ||
l: 'uri' | ||
}, | ||
ResponseContentDisposition: { | ||
l: 'header', | ||
n: 'response-content-disposition' | ||
l: 'uri' | ||
}, | ||
ResponseContentEncoding: { | ||
l: 'header', | ||
n: 'response-content-encoding' | ||
l: 'uri' | ||
}, | ||
@@ -965,5 +1048,5 @@ VersionId: { | ||
}, | ||
WebsiteRedirectLocation: { | ||
Restore: { | ||
l: 'header', | ||
n: 'x-amz-redirect-location' | ||
n: 'x-amz-restore' | ||
}, | ||
@@ -975,6 +1058,2 @@ LastModified: { | ||
}, | ||
ContentType: { | ||
l: 'header', | ||
n: 'Content-Type' | ||
}, | ||
ContentLength: { | ||
@@ -990,7 +1069,4 @@ t: 'i', | ||
t: 'i', | ||
l: 'x-amz-missing-meta' | ||
}, | ||
ServerSideEncryption: { | ||
l: 'header', | ||
n: 'x-amz-server-side-encryption' | ||
n: 'x-amz-missing-meta' | ||
}, | ||
@@ -1001,2 +1077,35 @@ VersionId: { | ||
}, | ||
CacheControl: { | ||
l: 'header', | ||
n: 'Cache-Control' | ||
}, | ||
ContentDisposition: { | ||
l: 'header', | ||
n: 'Content-Disposition' | ||
}, | ||
ContentEncoding: { | ||
l: 'header', | ||
n: 'Content-Encoding' | ||
}, | ||
ContentLanguage: { | ||
l: 'header', | ||
n: 'Content-Language' | ||
}, | ||
ContentType: { | ||
l: 'header', | ||
n: 'Content-Type' | ||
}, | ||
Expires: { | ||
t: 't', | ||
l: 'header', | ||
n: 'Expires' | ||
}, | ||
WebsiteRedirectLocation: { | ||
l: 'header', | ||
n: 'x-amz-website-redirect-location' | ||
}, | ||
ServerSideEncryption: { | ||
l: 'header', | ||
n: 'x-amz-server-side-encryption' | ||
}, | ||
Metadata: { | ||
@@ -1157,5 +1266,5 @@ t: 'm', | ||
}, | ||
WebsiteRedirectLocation: { | ||
Restore: { | ||
l: 'header', | ||
n: 'x-amz-redirect-location' | ||
n: 'x-amz-restore' | ||
}, | ||
@@ -1167,6 +1276,2 @@ LastModified: { | ||
}, | ||
ContentType: { | ||
l: 'header', | ||
n: 'Content-Type' | ||
}, | ||
ContentLength: { | ||
@@ -1182,7 +1287,4 @@ t: 'i', | ||
t: 'i', | ||
l: 'x-amz-missing-meta' | ||
}, | ||
ServerSideEncryption: { | ||
l: 'header', | ||
n: 'x-amz-server-side-encryption' | ||
n: 'x-amz-missing-meta' | ||
}, | ||
@@ -1193,2 +1295,35 @@ VersionId: { | ||
}, | ||
CacheControl: { | ||
l: 'header', | ||
n: 'Cache-Control' | ||
}, | ||
ContentDisposition: { | ||
l: 'header', | ||
n: 'Content-Disposition' | ||
}, | ||
ContentEncoding: { | ||
l: 'header', | ||
n: 'Content-Encoding' | ||
}, | ||
ContentLanguage: { | ||
l: 'header', | ||
n: 'Content-Language' | ||
}, | ||
ContentType: { | ||
l: 'header', | ||
n: 'Content-Type' | ||
}, | ||
Expires: { | ||
t: 't', | ||
l: 'header', | ||
n: 'Expires' | ||
}, | ||
WebsiteRedirectLocation: { | ||
l: 'header', | ||
n: 'x-amz-website-redirect-location' | ||
}, | ||
ServerSideEncryption: { | ||
l: 'header', | ||
n: 'x-amz-server-side-encryption' | ||
}, | ||
Metadata: { | ||
@@ -1608,3 +1743,2 @@ t: 'm', | ||
i: { | ||
n: 'AccessControlPolicy', | ||
m: { | ||
@@ -1615,2 +1749,51 @@ Bucket: { | ||
}, | ||
AccessControlPolicy: { | ||
t: 'o', | ||
l: 'body', | ||
m: { | ||
Owner: { | ||
t: 'o', | ||
m: { | ||
ID: { | ||
}, | ||
DisplayName: { | ||
} | ||
} | ||
}, | ||
Grants: { | ||
n: 'AccessControlList', | ||
t: 'a', | ||
m: { | ||
n: 'Grant', | ||
t: 'o', | ||
m: { | ||
Grantee: { | ||
t: 'o', | ||
ns: { | ||
prefix: 'xsi', | ||
uri: 'http://www.w3.org/2001/XMLSchema-instance' | ||
}, | ||
m: { | ||
Type: { | ||
n: 'xsi:type', | ||
r: 1, | ||
x: 1 | ||
}, | ||
ID: { | ||
}, | ||
DisplayName: { | ||
}, | ||
EmailAddress: { | ||
}, | ||
URI: { | ||
} | ||
} | ||
}, | ||
Permission: { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
ACL: { | ||
@@ -1640,44 +1823,5 @@ l: 'header', | ||
}, | ||
Owner: { | ||
t: 'o', | ||
m: { | ||
ID: { | ||
}, | ||
DisplayName: { | ||
} | ||
} | ||
}, | ||
Grants: { | ||
n: 'AccessControlList', | ||
t: 'a', | ||
m: { | ||
n: 'Grant', | ||
t: 'o', | ||
m: { | ||
Grantee: { | ||
t: 'o', | ||
ns: { | ||
prefix: 'xsi', | ||
uri: 'http://www.w3.org/2001/XMLSchema-instance' | ||
}, | ||
m: { | ||
Type: { | ||
n: 'xsi:type', | ||
r: 1, | ||
x: 1 | ||
}, | ||
ID: { | ||
}, | ||
DisplayName: { | ||
}, | ||
EmailAddress: { | ||
}, | ||
URI: { | ||
} | ||
} | ||
}, | ||
Permission: { | ||
} | ||
} | ||
} | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1691,3 +1835,2 @@ } | ||
i: { | ||
n: 'CORSConfiguration', | ||
m: { | ||
@@ -1698,29 +1841,39 @@ Bucket: { | ||
}, | ||
CORSRules: { | ||
n: 'CORSRule', | ||
t: 'a', | ||
f: 1, | ||
CORSConfiguration: { | ||
t: 'o', | ||
l: 'body', | ||
m: { | ||
t: 'o', | ||
m: { | ||
AllowedOrigins: { | ||
n: 'AllowedOrigin', | ||
t: 'a', | ||
f: 1 | ||
}, | ||
AllowedMethods: { | ||
n: 'AllowedMethod', | ||
t: 'a', | ||
f: 1 | ||
}, | ||
MaxAgeSeconds: { | ||
t: 'i' | ||
}, | ||
ExposeHeaders: { | ||
n: 'ExposeHeader', | ||
t: 'a', | ||
f: 1 | ||
CORSRules: { | ||
n: 'CORSRule', | ||
t: 'a', | ||
f: 1, | ||
m: { | ||
t: 'o', | ||
m: { | ||
AllowedOrigins: { | ||
n: 'AllowedOrigin', | ||
t: 'a', | ||
f: 1 | ||
}, | ||
AllowedMethods: { | ||
n: 'AllowedMethod', | ||
t: 'a', | ||
f: 1 | ||
}, | ||
MaxAgeSeconds: { | ||
t: 'i' | ||
}, | ||
ExposeHeaders: { | ||
n: 'ExposeHeader', | ||
t: 'a', | ||
f: 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1734,3 +1887,2 @@ } | ||
i: { | ||
n: 'LifecycleConfiguration', | ||
m: { | ||
@@ -1741,42 +1893,48 @@ Bucket: { | ||
}, | ||
Rules: { | ||
n: 'Rule', | ||
t: 'a', | ||
f: 1, | ||
r: 1, | ||
LifecycleConfiguration: { | ||
t: 'o', | ||
l: 'body', | ||
m: { | ||
t: 'o', | ||
m: { | ||
ID: { | ||
}, | ||
Prefix: { | ||
r: 1 | ||
}, | ||
Status: { | ||
r: 1 | ||
}, | ||
Transition: { | ||
Rules: { | ||
n: 'Rule', | ||
t: 'a', | ||
f: 1, | ||
r: 1, | ||
m: { | ||
t: 'o', | ||
m: { | ||
Days: { | ||
t: 'i' | ||
ID: { | ||
}, | ||
Date: { | ||
t: 't', | ||
tf: 'iso8601' | ||
Prefix: { | ||
r: 1 | ||
}, | ||
StorageClass: { | ||
} | ||
} | ||
}, | ||
Expiration: { | ||
t: 'o', | ||
m: { | ||
Days: { | ||
t: 'i', | ||
Status: { | ||
r: 1 | ||
}, | ||
Date: { | ||
t: 't', | ||
tf: 'iso8601' | ||
Transition: { | ||
t: 'o', | ||
m: { | ||
Days: { | ||
t: 'i' | ||
}, | ||
Date: { | ||
t: 't', | ||
tf: 'iso8601' | ||
}, | ||
StorageClass: { | ||
} | ||
} | ||
}, | ||
Expiration: { | ||
t: 'o', | ||
m: { | ||
Days: { | ||
t: 'i', | ||
r: 1 | ||
}, | ||
Date: { | ||
t: 't', | ||
tf: 'iso8601' | ||
} | ||
} | ||
} | ||
@@ -1787,2 +1945,6 @@ } | ||
} | ||
}, | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1796,3 +1958,2 @@ } | ||
i: { | ||
n: 'BucketLoggingStatus', | ||
m: { | ||
@@ -1803,39 +1964,46 @@ Bucket: { | ||
}, | ||
LoggingEnabled: { | ||
BucketLoggingStatus: { | ||
t: 'o', | ||
r: 1, | ||
l: 'body', | ||
m: { | ||
TargetBucket: { | ||
}, | ||
TargetPrefix: { | ||
}, | ||
TargetGrants: { | ||
t: 'a', | ||
LoggingEnabled: { | ||
t: 'o', | ||
r: 1, | ||
m: { | ||
n: 'Grant', | ||
t: 'o', | ||
m: { | ||
Grantee: { | ||
TargetBucket: { | ||
}, | ||
TargetPrefix: { | ||
}, | ||
TargetGrants: { | ||
t: 'a', | ||
m: { | ||
n: 'Grant', | ||
t: 'o', | ||
ns: { | ||
prefix: 'xsi', | ||
uri: 'http://www.w3.org/2001/XMLSchema-instance' | ||
}, | ||
m: { | ||
Type: { | ||
n: 'xsi:type', | ||
r: 1, | ||
x: 1 | ||
Grantee: { | ||
t: 'o', | ||
ns: { | ||
prefix: 'xsi', | ||
uri: 'http://www.w3.org/2001/XMLSchema-instance' | ||
}, | ||
m: { | ||
Type: { | ||
n: 'xsi:type', | ||
r: 1, | ||
x: 1 | ||
}, | ||
ID: { | ||
}, | ||
DisplayName: { | ||
}, | ||
EmailAddress: { | ||
}, | ||
URI: { | ||
} | ||
} | ||
}, | ||
ID: { | ||
}, | ||
DisplayName: { | ||
}, | ||
EmailAddress: { | ||
}, | ||
URI: { | ||
Permission: { | ||
} | ||
} | ||
}, | ||
Permission: { | ||
} | ||
@@ -1846,2 +2014,6 @@ } | ||
} | ||
}, | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1855,3 +2027,2 @@ } | ||
i: { | ||
n: 'NotificationConfiguration', | ||
m: { | ||
@@ -1862,11 +2033,22 @@ Bucket: { | ||
}, | ||
TopicConfiguration: { | ||
NotificationConfiguration: { | ||
t: 'o', | ||
r: 1, | ||
l: 'body', | ||
m: { | ||
Topic: { | ||
}, | ||
Event: { | ||
TopicConfiguration: { | ||
t: 'o', | ||
r: 1, | ||
m: { | ||
Topic: { | ||
}, | ||
Event: { | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1888,2 +2070,6 @@ } | ||
l: 'body' | ||
}, | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1897,3 +2083,2 @@ } | ||
i: { | ||
n: 'RequestPaymentConfiguration', | ||
m: { | ||
@@ -1904,4 +2089,15 @@ Bucket: { | ||
}, | ||
Payer: { | ||
r: 1 | ||
RequestPaymentConfiguration: { | ||
t: 'o', | ||
r: 1, | ||
l: 'body', | ||
m: { | ||
Payer: { | ||
r: 1 | ||
} | ||
} | ||
}, | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1915,3 +2111,2 @@ } | ||
i: { | ||
n: 'Tagging', | ||
m: { | ||
@@ -1922,18 +2117,29 @@ Bucket: { | ||
}, | ||
TagSet: { | ||
t: 'a', | ||
Tagging: { | ||
t: 'o', | ||
r: 1, | ||
l: 'body', | ||
m: { | ||
n: 'Tag', | ||
t: 'o', | ||
r: 1, | ||
m: { | ||
Key: { | ||
r: 1 | ||
}, | ||
Value: { | ||
r: 1 | ||
TagSet: { | ||
t: 'a', | ||
r: 1, | ||
m: { | ||
n: 'Tag', | ||
t: 'o', | ||
r: 1, | ||
m: { | ||
Key: { | ||
r: 1 | ||
}, | ||
Value: { | ||
r: 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1947,3 +2153,2 @@ } | ||
i: { | ||
n: 'VersioningConfiguration', | ||
m: { | ||
@@ -1954,2 +2159,13 @@ Bucket: { | ||
}, | ||
VersioningConfiguration: { | ||
t: 'o', | ||
r: 1, | ||
l: 'body', | ||
m: { | ||
Status: { | ||
}, | ||
MFADelete: { | ||
} | ||
} | ||
}, | ||
MFA: { | ||
@@ -1959,5 +2175,5 @@ l: 'header', | ||
}, | ||
Status: { | ||
}, | ||
MFADelete: { | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -1971,3 +2187,2 @@ } | ||
i: { | ||
n: 'WebsiteConfiguration', | ||
m: { | ||
@@ -1978,17 +2193,73 @@ Bucket: { | ||
}, | ||
IndexDocument: { | ||
WebsiteConfiguration: { | ||
t: 'o', | ||
r: 1, | ||
l: 'body', | ||
m: { | ||
Suffix: { | ||
r: 1 | ||
RedirectAllRequestsTo: { | ||
t: 'o', | ||
m: { | ||
HostName: { | ||
r: 1 | ||
}, | ||
Protocol: { | ||
} | ||
} | ||
}, | ||
IndexDocument: { | ||
t: 'o', | ||
m: { | ||
Suffix: { | ||
r: 1 | ||
} | ||
} | ||
}, | ||
ErrorDocument: { | ||
t: 'o', | ||
m: { | ||
Key: { | ||
r: 1 | ||
} | ||
} | ||
}, | ||
RoutingRules: { | ||
t: 'a', | ||
m: { | ||
n: 'RoutingRule', | ||
t: 'o', | ||
m: { | ||
Condition: { | ||
t: 'o', | ||
m: { | ||
KeyPrefixEquals: { | ||
}, | ||
HttpErrorCodeReturnedEquals: { | ||
} | ||
} | ||
}, | ||
Redirect: { | ||
t: 'o', | ||
r: 1, | ||
m: { | ||
ReplaceKeyPrefixWith: { | ||
}, | ||
ReplaceKeyWith: { | ||
}, | ||
HttpRedirectCode: { | ||
} | ||
} | ||
}, | ||
HostName: { | ||
r: 1 | ||
}, | ||
Protocol: { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
ErrorDocument: { | ||
t: 'o', | ||
m: { | ||
Key: { | ||
r: 1 | ||
} | ||
} | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -2011,2 +2282,31 @@ } | ||
}, | ||
Body: { | ||
t: 'bl', | ||
l: 'body', | ||
s: 1 | ||
}, | ||
StorageClass: { | ||
l: 'header', | ||
n: 'x-amz-storage-class' | ||
}, | ||
ACL: { | ||
l: 'header', | ||
n: 'x-amz-acl' | ||
}, | ||
GrantRead: { | ||
l: 'header', | ||
n: 'x-amz-grant-read' | ||
}, | ||
GrantReadACP: { | ||
l: 'header', | ||
n: 'x-amz-grant-read-acp' | ||
}, | ||
GrantWriteACP: { | ||
l: 'header', | ||
n: 'x-amz-grant-write-acp' | ||
}, | ||
GrantFullControl: { | ||
l: 'header', | ||
n: 'x-amz-grant-full-control' | ||
}, | ||
CacheControl: { | ||
@@ -2024,2 +2324,6 @@ l: 'header', | ||
}, | ||
ContentLanguage: { | ||
l: 'header', | ||
n: 'Content-Language' | ||
}, | ||
ContentType: { | ||
@@ -2034,6 +2338,2 @@ l: 'header', | ||
}, | ||
StorageClass: { | ||
l: 'header', | ||
n: 'x-amz-storage-class' | ||
}, | ||
WebsiteRedirectLocation: { | ||
@@ -2043,27 +2343,2 @@ l: 'header', | ||
}, | ||
Body: { | ||
t: 'bl', | ||
l: 'body', | ||
s: 1 | ||
}, | ||
ACL: { | ||
l: 'header', | ||
n: 'x-amz-acl' | ||
}, | ||
GrantRead: { | ||
l: 'header', | ||
n: 'x-amz-grant-read' | ||
}, | ||
GrantReadACP: { | ||
l: 'header', | ||
n: 'x-amz-grant-read-acp' | ||
}, | ||
GrantWriteACP: { | ||
l: 'header', | ||
n: 'x-amz-grant-write-acp' | ||
}, | ||
GrantFullControl: { | ||
l: 'header', | ||
n: 'x-amz-grant-full-control' | ||
}, | ||
ServerSideEncryption: { | ||
@@ -2104,3 +2379,2 @@ l: 'header', | ||
i: { | ||
n: 'AccessControlPolicy', | ||
m: { | ||
@@ -2115,2 +2389,51 @@ Bucket: { | ||
}, | ||
AccessControlPolicy: { | ||
t: 'o', | ||
l: 'body', | ||
m: { | ||
Owner: { | ||
t: 'o', | ||
m: { | ||
ID: { | ||
}, | ||
DisplayName: { | ||
} | ||
} | ||
}, | ||
Grants: { | ||
n: 'AccessControlList', | ||
t: 'a', | ||
m: { | ||
n: 'Grant', | ||
t: 'o', | ||
m: { | ||
Grantee: { | ||
t: 'o', | ||
ns: { | ||
prefix: 'xsi', | ||
uri: 'http://www.w3.org/2001/XMLSchema-instance' | ||
}, | ||
m: { | ||
Type: { | ||
n: 'xsi:type', | ||
r: 1, | ||
x: 1 | ||
}, | ||
ID: { | ||
}, | ||
DisplayName: { | ||
}, | ||
EmailAddress: { | ||
}, | ||
URI: { | ||
} | ||
} | ||
}, | ||
Permission: { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
ACL: { | ||
@@ -2140,44 +2463,5 @@ l: 'header', | ||
}, | ||
Owner: { | ||
t: 'o', | ||
m: { | ||
ID: { | ||
}, | ||
DisplayName: { | ||
} | ||
} | ||
}, | ||
Grants: { | ||
n: 'AccessControlList', | ||
t: 'a', | ||
m: { | ||
n: 'Grant', | ||
t: 'o', | ||
m: { | ||
Grantee: { | ||
t: 'o', | ||
ns: { | ||
prefix: 'xsi', | ||
uri: 'http://www.w3.org/2001/XMLSchema-instance' | ||
}, | ||
m: { | ||
Type: { | ||
n: 'xsi:type', | ||
r: 1, | ||
x: 1 | ||
}, | ||
ID: { | ||
}, | ||
DisplayName: { | ||
}, | ||
EmailAddress: { | ||
}, | ||
URI: { | ||
} | ||
} | ||
}, | ||
Permission: { | ||
} | ||
} | ||
} | ||
ContentMD5: { | ||
l: 'header', | ||
n: 'Content-MD5' | ||
} | ||
@@ -2191,3 +2475,2 @@ } | ||
i: { | ||
n: 'RestoreRequest', | ||
m: { | ||
@@ -2202,5 +2485,11 @@ Bucket: { | ||
}, | ||
Days: { | ||
t: 'i', | ||
r: 1 | ||
RestoreRequest: { | ||
t: 'o', | ||
l: 'body', | ||
m: { | ||
Days: { | ||
t: 'i', | ||
r: 1 | ||
} | ||
} | ||
} | ||
@@ -2207,0 +2496,0 @@ } |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -17,203 +17,186 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('../core'); | ||
var inherit = AWS.util.inherit; | ||
require('../rest_xml_client'); | ||
require('../sigvs3'); | ||
AWS.S3 = AWS.Service.defineService('./services/s3.api', { | ||
Client: { | ||
/** | ||
* @api private | ||
*/ | ||
constructor: function S3Client(options) { | ||
AWS.Client.call(this, options); | ||
this.setEndpoint((options || {}).endpoint, options); | ||
}, | ||
AWS.S3 = inherit({ | ||
setupRequestListeners: function setupRequestListeners(request) { | ||
request.addListener('build', this.populateURI); | ||
if (request.operation == 'deleteObjects') | ||
request.addListener('build', this.computeContentMd5); | ||
request.removeListener('validate', | ||
AWS.EventListeners.Core.VALIDATE_REGION); | ||
request.addListener('extractError', this.extractError); | ||
request.addListener('extractData', this.extractData); | ||
}, | ||
constructor: function S3(options) { | ||
AWS.Service.call(this, options); | ||
} | ||
/** | ||
* S3 prefers dns-compatible bucket names to be moved from the uri path | ||
* to the hostname as a sub-domain. This is not possible, even for dns-compat | ||
* buckets when using SSL and the bucket name contains a dot ('.'). The | ||
* ssl wildcard certificate is only 1-level deep. | ||
* | ||
* @api private | ||
*/ | ||
populateURI: function populateURI(req) { | ||
var httpRequest = req.httpRequest; | ||
var b = req.params.Bucket; | ||
}); | ||
if (b) { | ||
if (!req.client.pathStyleBucketName(b)) { | ||
httpRequest.endpoint.hostname = b + '.' + | ||
httpRequest.endpoint.hostname; | ||
AWS.S3.Client = inherit(AWS.RESTXMLClient, { | ||
httpRequest.virtualHostedBucket = b; // needed for signing the request | ||
httpRequest.path = httpRequest.path.replace(new RegExp('^/' + b), ''); | ||
if (httpRequest.path[0] !== '/') { | ||
httpRequest.path = '/' + httpRequest.path; | ||
} | ||
} | ||
} | ||
}, | ||
/** | ||
* @api private | ||
*/ | ||
constructor: function S3Client(options) { | ||
this.serviceName = 's3'; | ||
AWS.RESTXMLClient.call(this, options); | ||
this.setEndpoint((options || {}).endpoint, options); | ||
}, | ||
computeContentMd5: function computeContentMd5(req) { | ||
var md5 = AWS.util.crypto.md5(req.httpRequest.body, 'base64'); | ||
req.httpRequest.headers['Content-MD5'] = md5; | ||
}, | ||
/** | ||
* @api private | ||
*/ | ||
signatureVersion: AWS.SigVS3, | ||
/** | ||
* Returns true if the bucket name should be left in the URI path for | ||
* a request to S3. This function takes into account the current | ||
* endpoint protocol (e.g. http or https). | ||
* | ||
* @api private | ||
*/ | ||
pathStyleBucketName: function pathStyleBucketName(bucketName) { | ||
// user can force path style requests via the configuration | ||
if (this.config.s3ForcePathStyle) return true; | ||
/** | ||
* S3 prefers dns-compatible bucket names to be moved from the uri path | ||
* to the hostname as a sub-domain. This is not possible, even for dns-compat | ||
* buckets when using SSL and the bucket name contains a dot ('.'). The | ||
* ssl wildcart certificate is only 1-level deep. | ||
* | ||
* @api private | ||
*/ | ||
populateURI: function populateURI(req, operation, params) { | ||
if (this.dnsCompatibleBucketName(bucketName)) { | ||
return (this.config.sslEnabled && bucketName.match(/\./)) ? true : false; | ||
} else { | ||
return true; // not dns compatible names must always use path style | ||
} | ||
}, | ||
AWS.RESTClient.prototype.populateURI.call(this, req, operation, params); | ||
/** | ||
* Returns true if the bucket name is DNS compatible. Buckets created | ||
* outside of the classic region MUST be DNS compatible. | ||
* | ||
* @api private | ||
*/ | ||
dnsCompatibleBucketName: function dnsCompatibleBucketName(bucketName) { | ||
var b = bucketName; | ||
var domain = new RegExp(/^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$/); | ||
var ipAddress = new RegExp(/(\d+\.){3}\d+/); | ||
var dots = new RegExp(/\.\./); | ||
return (b.match(domain) && !b.match(ipAddress) && !b.match(dots)) ? true : false; | ||
}, | ||
var b = params.Bucket; | ||
if (b) { | ||
if (!this.pathStyleBucketName(b)) { | ||
/** | ||
* S3 requires that path params not escape forward slashes. | ||
* | ||
* @api private | ||
*/ | ||
escapePathParam: function escapePathParam(value) { | ||
return AWS.util.uriEscapePath(String(value)); | ||
}, | ||
req.virtualHostedBucket = b; // needed for signing the request | ||
/** | ||
* @return [Boolean] whether response contains an error | ||
* @api private | ||
*/ | ||
successfulResponse: function successfulResponse(resp) { | ||
var req = resp.request; | ||
var httpResponse = resp.httpResponse; | ||
if (req.operation === 'completeMultipartUpload' && | ||
httpResponse.body.toString().match('<Error>')) | ||
return false; | ||
else | ||
return httpResponse.statusCode < 300; | ||
}, | ||
req.path = req.path.replace(new RegExp('^/' + b), ''); | ||
if (req.path[0] !== '/') req.path = '/' + req.path; | ||
req.endpoint.hostname = b + '.' + req.endpoint.hostname; | ||
/** | ||
* @return [Boolean] whether the error can be retried | ||
* @api private | ||
*/ | ||
retryableError: function retryableError(error, request) { | ||
if (request.operation == 'completeMultipartUpload' && | ||
error.statusCode === 200) { | ||
return true; | ||
} else { | ||
var _super = AWS.Client.prototype.retryableError; | ||
return _super.call(this, error, request); | ||
} | ||
} | ||
}, | ||
}, | ||
/** | ||
* Returns true if the bucket name should be left in the URI path for | ||
* a request to S3. This function takes into account the current | ||
* endpoint protocol (e.g. http or https). | ||
* | ||
* @api private | ||
*/ | ||
pathStyleBucketName: function pathStyleBucketName(bucketName) { | ||
// user can force path style requests via the configuration | ||
if (this.config.s3ForcePathStyle) return true; | ||
if (this.dnsCompatibleBucketName(bucketName)) { | ||
return (this.config.sslEnabled && bucketName.match(/\./)) ? true : false; | ||
} else { | ||
return true; // not dns compatible names must always use path style | ||
} | ||
}, | ||
/** | ||
* Returns true if the bucket name is DNS compatible. Buckets created | ||
* outside of the classic region MUST be DNS compatible. | ||
* | ||
* @api private | ||
*/ | ||
dnsCompatibleBucketName: function dnsCompatibleBucketName(bucketName) { | ||
var b = bucketName; | ||
var domain = new RegExp(/^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$/); | ||
var ipAddress = new RegExp(/(\d+\.){3}\d+/); | ||
var dots = new RegExp(/\.\./); | ||
return (b.match(domain) && !b.match(ipAddress) && !b.match(dots)) ? true : false; | ||
}, | ||
/** | ||
* S3 requires that path params not escape forward slashes. | ||
* | ||
* @api private | ||
*/ | ||
escapePathParam: function escapePathParam(value) { | ||
return AWS.util.uriEscapePath(String(value)); | ||
}, | ||
/** | ||
* @return [Boolean] whether response contains an error | ||
* @api private | ||
*/ | ||
successfulResponse: function successfulResponse(httpResponse, method) { | ||
if (method === 'completeMultipartUpload' && httpResponse.body && httpResponse.body.match('<Error>')) | ||
return false; | ||
else | ||
return httpResponse.statusCode < 300; | ||
}, | ||
/** | ||
* @return [Boolean] whether the error can be retried | ||
* @api private | ||
*/ | ||
retryableError: function retryableError(error, method) { | ||
if (method == 'completeMultipartUpload' && error.statusCode === 200) { | ||
return true; | ||
} else { | ||
var _super = AWS.Client.prototype.retryableError; | ||
return _super.call(this, error, method); | ||
} | ||
}, | ||
/** | ||
* Provides a specialized parser for getBucketLocation -- all other | ||
* operations are parsed by the super class. | ||
* | ||
* @api private | ||
*/ | ||
extractData: function extractData(httpResponse, method) { | ||
var _super = AWS.RESTXMLClient.prototype.extractData; | ||
var data = _super.call(this, httpResponse, method); | ||
if (method === 'getBucketLocation') { | ||
/*jshint regexp:false*/ | ||
var match = httpResponse.body.match(/>(.+)<\/Location/); | ||
if (match) { | ||
/*jshint sub:true */ | ||
delete data['_']; | ||
data.LocationConstraint = match[1]; | ||
/** | ||
* Provides a specialized parser for getBucketLocation -- all other | ||
* operations are parsed by the super class. | ||
* | ||
* @api private | ||
*/ | ||
extractData: function extractData(resp) { | ||
var req = resp.request; | ||
if (req.operation === 'getBucketLocation') { | ||
/*jshint regexp:false*/ | ||
var match = resp.httpResponse.body.toString().match(/>(.+)<\/Location/); | ||
if (match) { | ||
delete resp.data['_']; | ||
resp.data.LocationConstraint = match[1]; | ||
} | ||
} | ||
}, | ||
} | ||
return data; | ||
}, | ||
/** | ||
* Extracts an error object from the http response. | ||
* | ||
* @api private | ||
*/ | ||
extractError: function extractError(httpResponse) { | ||
var codes = { | ||
304: 'NotModified', | ||
403: 'Forbidden', | ||
404: 'NotFound' | ||
}; | ||
if (codes[httpResponse.statusCode]) { | ||
return { | ||
code: codes[httpResponse.statusCode], | ||
message: null | ||
/** | ||
* Extracts an error object from the http response. | ||
* | ||
* @api private | ||
*/ | ||
extractError: function extractError(resp) { | ||
var codes = { | ||
304: 'NotModified', | ||
403: 'Forbidden', | ||
400: 'BadRequest', | ||
404: 'NotFound' | ||
}; | ||
} else { | ||
var code = resp.httpResponse.statusCode; | ||
var body = resp.httpResponse.body; | ||
if (codes[code] && body.length === 0) { | ||
resp.error = AWS.util.error(new Error(), { | ||
code: codes[resp.httpResponse.statusCode], | ||
message: null | ||
}); | ||
} else { | ||
var data = new AWS.XML.Parser({}).parse(body.toString()); | ||
resp.error = AWS.util.error(new Error(), { | ||
code: data.Code || code, | ||
message: data.Message || null | ||
}); | ||
} | ||
}, | ||
var data = new AWS.XML.Parser({}).parse(httpResponse.body || ''); | ||
return { | ||
code: data.Code || httpResponse.statusCode, | ||
message: data.Message || null | ||
}; | ||
/** | ||
* @api private | ||
*/ | ||
setEndpoint: function setEndpoint(endpoint) { | ||
if (endpoint) { | ||
this.endpoint = new AWS.Endpoint(endpoint, this.config); | ||
} else if (this.config.region && this.config.region !== 'us-east-1') { | ||
var hostname = 's3-' + this.config.region + '.amazonaws.com'; | ||
this.endpoint = new AWS.Endpoint(hostname); | ||
} else { | ||
this.endpoint = new AWS.Endpoint('s3.amazonaws.com', this.config); | ||
} | ||
} | ||
}, | ||
/** | ||
* @api private | ||
*/ | ||
setEndpoint: function setEndpoint(endpoint) { | ||
if (endpoint) { | ||
this.endpoint = new AWS.Endpoint(endpoint, this.config); | ||
} else if (this.config.region && this.config.region !== 'us-east-1') { | ||
var hostname = 's3-' + this.config.region + '.amazonaws.com'; | ||
this.endpoint = new AWS.Endpoint(hostname); | ||
} else { | ||
this.endpoint = new AWS.Endpoint('s3.amazonaws.com', this.config); | ||
} | ||
} | ||
}); | ||
require('./s3.api'); | ||
AWS.Client.defineMethods(AWS.S3.Client); | ||
AWS.S3.Client.prototype.createBucket = function createBucket(params, options) { | ||
@@ -227,6 +210,9 @@ // When creating a bucket *outside* the classic region, the location | ||
var hostname = this.endpoint.hostname; | ||
if (hostname != 's3.amazonaws.com' && !params.LocationConstraint) { | ||
params.LocationConstraint = this.config.region; | ||
if (hostname != 's3.amazonaws.com' && !params.CreateBucketConfiguration) { | ||
params.CreateBucketConfiguration = {}; | ||
params.CreateBucketConfiguration.LocationConstraint = this.config.region; | ||
} | ||
return this.makeRequest('createBucket', params, options); | ||
}; | ||
module.exports = AWS.S3; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -16,7 +16,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('../core'); | ||
AWS.SimpleWorkflow.Client.prototype.api = { | ||
module.exports = { | ||
format: 'json', | ||
targetPrefix: 'SimpleWorkflowService.', | ||
signatureVersion: 'v3', | ||
serviceName: 'swf', | ||
targetPrefix: 'SimpleWorkflowService', | ||
timestampFormat: 'unixTimestamp', | ||
@@ -23,0 +23,0 @@ operations: { |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -17,34 +17,5 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
var AWS = require('../core'); | ||
var inherit = AWS.util.inherit; | ||
require('../json_client'); | ||
require('../sigv3'); | ||
AWS.SimpleWorkflow = AWS.Service.defineService('./services/simpleworkflow.api'); | ||
AWS.SimpleWorkflow = inherit({ | ||
constructor: function SimpleWorkflow(options) { | ||
AWS.Service.call(this, options); | ||
} | ||
}); | ||
AWS.SimpleWorkflow.Client = inherit(AWS.JSONClient, { | ||
/** | ||
* @api private | ||
*/ | ||
constructor: function SimpleWorkflowClient(options) { | ||
this.serviceName = 'swf'; | ||
AWS.JSONClient.call(this, options); | ||
}, | ||
/** | ||
* @api private | ||
*/ | ||
signatureVersion: AWS.SigV3 | ||
}); | ||
require('./simpleworkflow.api'); | ||
AWS.Client.defineMethods(AWS.SimpleWorkflow.Client); | ||
module.exports = AWS.SimpleWorkflow; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -23,7 +23,2 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
AWS.SigV2 = inherit(AWS.RequestSigner, { | ||
constructor: function SigV2(request) { | ||
AWS.RequestSigner.call(this, request); | ||
}, | ||
addAuthorization: function addAuthorization(credentials, date) { | ||
@@ -47,3 +42,2 @@ | ||
r.headers['Content-Length'] = r.body.length; | ||
}, | ||
@@ -50,0 +44,0 @@ |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -23,7 +23,2 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
AWS.SigV3 = inherit(AWS.RequestSigner, { | ||
constructor: function SigV3(request) { | ||
AWS.RequestSigner.call(this, request); | ||
}, | ||
addAuthorization: function addAuthorization(credentials, date) { | ||
@@ -33,3 +28,2 @@ | ||
/*jshint sub:true */ | ||
this.request.headers['Date'] = datetime; | ||
@@ -36,0 +30,0 @@ this.request.headers['X-Amz-Date'] = datetime; |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -23,3 +23,2 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
AWS.SigV4 = inherit(AWS.RequestSigner, { | ||
constructor: function SigV4(request, serviceName) { | ||
@@ -33,3 +32,2 @@ AWS.RequestSigner.call(this, request); | ||
this.addHeaders(credentials, datetime); | ||
/*jshint sub:true */ | ||
this.request.headers['Authorization'] = | ||
@@ -40,3 +38,2 @@ this.authorization(credentials, datetime); | ||
addHeaders: function addHeaders(credentials, datetime) { | ||
/*jshint sub:true */ | ||
this.request.headers['Host'] = this.request.endpoint.hostname; | ||
@@ -85,3 +82,3 @@ this.request.headers['Date'] = datetime; | ||
parts.push(this.signedHeaders()); | ||
parts.push(this.hexEncodedHash(this.request.body || '')); | ||
parts.push(this.hexEncodedHash(this.request.body)); | ||
return parts.join('\n'); | ||
@@ -88,0 +85,0 @@ }, |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -23,9 +23,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
AWS.SigVS3 = inherit(AWS.RequestSigner, { | ||
constructor: function SigVS3(request) { | ||
AWS.RequestSigner.call(this, request); | ||
}, | ||
// when building the stringToSign, these sub resource params should be | ||
// part of the canonical resource string with their NON-decoded values | ||
/** | ||
* When building the stringToSign, these sub resource params should be | ||
* part of the canonical resource string with their NON-decoded values | ||
*/ | ||
subResources: { | ||
@@ -62,5 +59,4 @@ 'acl': 1, | ||
addAuthorization: function addAuthorization(credentials, date) { | ||
this.request.headers['Date'] = AWS.util.date.rfc822(date); | ||
this.setDate(date); | ||
if (credentials.sessionToken) | ||
@@ -72,10 +68,6 @@ this.request.headers['X-Amz-Security-Token'] = credentials.sessionToken; | ||
/*jshint sub:true */ | ||
this.request.headers['Authorization'] = auth; | ||
}, | ||
stringToSign: function stringToSign() { | ||
/*jshint sub:true */ | ||
var r = this.request; | ||
@@ -178,16 +170,5 @@ | ||
return AWS.util.crypto.hmac(secret, string, 'base64', 'sha1'); | ||
}, | ||
setDate: function setDate(date) { | ||
/*jshint sub:true */ | ||
var r = this.request; | ||
if (date) { | ||
r.headers['Date'] = date; | ||
} else if (!r.headers['X-Amz-Date'] && !r.headers['Date']) { | ||
r.headers['Date'] = AWS.util.date.rfc822(); | ||
} | ||
} | ||
}); | ||
module.exports = AWS.SigVS3; |
147
lib/util.js
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -40,3 +40,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
userAgent: function userAgent() { | ||
return 'aws-sdk-nodejs/' + AWS.VERSION + AWS.util.engine(); | ||
return 'aws-sdk-nodejs/' + AWS.VERSION + ' ' + AWS.util.engine(); | ||
}, | ||
@@ -46,5 +46,3 @@ | ||
/*jshint undef:false */ | ||
var uri = escape(string).replace(/\+/g, '%2B').replace(/\//g, '%2F'); | ||
uri = uri.replace(/%7E/g, '~').replace(/\=/g, '%3D'); | ||
return uri; | ||
return encodeURIComponent(string).replace(/[^A-Za-z0-9_.~\-%]+/g, escape); | ||
}, | ||
@@ -76,2 +74,19 @@ | ||
string: { | ||
byteLength: function byteLength(string) { | ||
if (string === null || string === undefined) return 0; | ||
if (typeof string === 'string') string = new Buffer(string); | ||
if (string.length !== undefined) { | ||
return string.length; | ||
} else if (string.path !== undefined) { | ||
return require('fs').lstatSync(string.path).size; | ||
} else { | ||
throw AWS.util.error(new Error(), { | ||
message: 'Cannot determine length of ' + string, object: string | ||
}); | ||
} | ||
} | ||
}, | ||
/** | ||
@@ -117,3 +132,71 @@ * Date and time utility functions. | ||
crypto: { | ||
crc32Table: [ | ||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, | ||
0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, | ||
0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, | ||
0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, | ||
0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, | ||
0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, | ||
0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, | ||
0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, | ||
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, | ||
0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, | ||
0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, | ||
0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, | ||
0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, | ||
0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, | ||
0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, | ||
0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, | ||
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, | ||
0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, | ||
0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, | ||
0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, | ||
0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, | ||
0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, | ||
0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, | ||
0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, | ||
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, | ||
0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, | ||
0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, | ||
0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, | ||
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, | ||
0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, | ||
0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, | ||
0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, | ||
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, | ||
0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, | ||
0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, | ||
0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, | ||
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, | ||
0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, | ||
0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, | ||
0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, | ||
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, | ||
0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, | ||
0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, | ||
0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, | ||
0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, | ||
0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, | ||
0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, | ||
0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, | ||
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, | ||
0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, | ||
0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, | ||
0x2D02EF8D], | ||
crc32: function crc32(data) { | ||
/*jshint bitwise:false*/ | ||
var tbl = AWS.util.crypto.crc32Table; | ||
var crc = 0 ^ -1; | ||
if (typeof data === 'string') { | ||
data = new Buffer(data); | ||
} | ||
for (var i = 0; i < data.length; i++) { | ||
crc = (crc>>>8) ^ tbl[(crc^data[i])&0xFF]; | ||
} | ||
return (crc ^ -1) >>> 0; | ||
}, | ||
hmac: function hmac(key, string, digest, fn) { | ||
@@ -125,4 +208,11 @@ if (!digest) digest = 'binary'; | ||
md5: function md5(data, digest) { | ||
if (!digest) { digest = 'binary'; } | ||
if (typeof data === 'string') data = new Buffer(data); | ||
return cryptoLib.createHash('md5').update(data).digest(digest); | ||
}, | ||
sha256: function sha256(string, digest) { | ||
if (!digest) { digest = 'binary'; } | ||
if (typeof string === 'string') string = new Buffer(string); | ||
return cryptoLib.createHash('sha256').update(string).digest(digest); | ||
@@ -156,6 +246,7 @@ }, | ||
arrayEach: function arrayEach(array, iterFunction) { | ||
/*jshint forin:false*/ | ||
for (var idx in array) { | ||
var ret = iterFunction.call(this, array[idx], parseInt(idx, 10)); | ||
if (ret === AWS.util.abort) break; | ||
if (array.hasOwnProperty(idx)) { | ||
var ret = iterFunction.call(this, array[idx], parseInt(idx, 10)); | ||
if (ret === AWS.util.abort) break; | ||
} | ||
} | ||
@@ -176,2 +267,3 @@ }, | ||
copy: function copy(object) { | ||
if (object === null || object === undefined) return object; | ||
var dupe = {}; | ||
@@ -194,2 +286,15 @@ /*jshint forin:false */ | ||
error: function error(err, options) { | ||
err.message = err.message || null; | ||
if (typeof options === 'string') { | ||
err.message = options; | ||
} else { | ||
AWS.util.update(err, options); | ||
} | ||
err.name = err.code || 'Error'; | ||
return err; | ||
}, | ||
/** | ||
@@ -202,2 +307,3 @@ * @api private | ||
features = klass; | ||
klass = Object; | ||
newObject = {}; | ||
@@ -210,2 +316,10 @@ } else { | ||
} | ||
// constructor not supplied, create pass-through ctor | ||
if (features.constructor === Object) { | ||
features.constructor = function() { | ||
klass.apply(this, arguments); | ||
}; | ||
} | ||
features.constructor.prototype = newObject; | ||
@@ -215,2 +329,19 @@ AWS.util.update(features.constructor.prototype, features); | ||
return features.constructor; | ||
}, | ||
/** | ||
* @api private | ||
*/ | ||
mixin: function mixin() { | ||
var klass = arguments[0]; | ||
for (var i = 1; i < arguments.length; i++) { | ||
/*jshint forin:false*/ | ||
for (var prop in arguments[i].prototype) { | ||
var fn = arguments[i].prototype[prop]; | ||
if (prop != 'constructor') { | ||
klass.prototype[prop] = fn; | ||
} | ||
} | ||
} | ||
return klass; | ||
} | ||
@@ -217,0 +348,0 @@ |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -49,7 +49,13 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
serializeList: function serializeList(name, rules, list, xml) { | ||
xml = xml.node(name); | ||
AWS.util.arrayEach.call(this, list, function (value) { | ||
var memberName = rules.m.n || 'member'; | ||
this.serializeMember(memberName, rules.m, value, xml); | ||
}); | ||
if (rules.f) { | ||
AWS.util.arrayEach.call(this, list, function (value) { | ||
this.serializeMember(rules.n || name, rules.m, value, xml); | ||
}); | ||
} else { | ||
xml = xml.node(name); | ||
AWS.util.arrayEach.call(this, list, function (value) { | ||
var memberName = rules.m.n || 'member'; | ||
this.serializeMember(memberName, rules.m, value, xml); | ||
}); | ||
} | ||
}, | ||
@@ -56,0 +62,0 @@ |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -48,7 +48,13 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
serializeList: function serializeList(name, rules, list, xml) { | ||
xml = xml.ele(name); | ||
AWS.util.arrayEach.call(this, list, function (value) { | ||
var memberName = rules.m.n || 'member'; | ||
this.serializeMember(memberName, rules.m, value, xml); | ||
}); | ||
if (rules.f) { | ||
AWS.util.arrayEach.call(this, list, function (value) { | ||
this.serializeMember(rules.n || name, rules.m, value, xml); | ||
}); | ||
} else { | ||
xml = xml.ele(name); | ||
AWS.util.arrayEach.call(this, list, function (value) { | ||
var memberName = rules.m.n || 'member'; | ||
this.serializeMember(memberName, rules.m, value, xml); | ||
}); | ||
} | ||
}, | ||
@@ -55,0 +61,0 @@ |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -56,3 +56,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You | ||
} else if (error) { | ||
throw { code: 'AWS.XML.Parser.Error', message: error.message }; | ||
throw AWS.util.error(error, {code: 'XMLParserError'}); | ||
} else { // empty xml document | ||
@@ -135,3 +135,3 @@ return {}; | ||
var msg = 'unhandled type: ' + rules.t; | ||
throw { code: 'AWS.XML.Parser.Error', message: msg }; | ||
throw AWS.util.error(new Error(msg), {code: 'XMLParserError'}); | ||
@@ -153,8 +153,8 @@ } | ||
var date = new Date(parts[0], 0, 1); | ||
if (parts[1]) { date.setMonth(parts[1]); } | ||
if (parts[2]) { date.setDate(parts[2]); } | ||
if (parts[3]) { date.setHours(parts[3]); } | ||
if (parts[4]) { date.setMinutes(parts[4]); } | ||
if (parts[5]) { date.setSeconds(parts[5]); } | ||
if (parts[6]) { date.setMilliseconds(Number('0.' + parts[6]) * 1000); } | ||
if (parts[1]) { date.setUTCMonth(parts[1] - 1); } | ||
if (parts[2]) { date.setUTCDate(parts[2]); } | ||
if (parts[3]) { date.setUTCHours(parts[3]); } | ||
if (parts[4]) { date.setUTCMinutes(parts[4]); } | ||
if (parts[5]) { date.setUTCSeconds(parts[5]); } | ||
if (parts[6]) { date.setUTCMilliseconds(Number('0.' + parts[6]) * 1000); } | ||
@@ -169,3 +169,5 @@ return date; | ||
throw 'unhandled timestamp format: ' + value; | ||
throw AWS.util.error( | ||
new Error('unhandled timestamp format: ' + value), | ||
{code: 'TimestampParserError'}); | ||
@@ -172,0 +174,0 @@ } |
/** | ||
* Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"). You |
@@ -1,2 +0,2 @@ | ||
Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
@@ -3,0 +3,0 @@ Licensed under the Apache License, Version 2.0 (the "License"). You |
{ | ||
"name": "aws-sdk", | ||
"description": "AWS SDK for JavaScript", | ||
"version": "0.9.1-pre.2", | ||
"version": "v0.9.2-pre.3", | ||
"author": { | ||
@@ -16,7 +16,6 @@ "name":"Amazon Web Services", | ||
"devDependencies": { | ||
"repl.history": "latest", | ||
"jasmine-node": "latest", | ||
"coffee-script": "latest", | ||
"visionmedia-jscoverage": "latest", | ||
"node-ffi": "latest", | ||
"jshint": "latest", | ||
"jshint": "0.9.0", | ||
"cucumber": "latest" | ||
@@ -57,7 +56,9 @@ }, | ||
"scripts" : { | ||
"test" : "npm -s run-script lint && (([ -f configuration ] && jasmine-node --coffee test) || ([ ! -f configuration ] && npm -s run-script unit))", | ||
"test" : "npm -s run-script lint && (([ -f configuration ] && jasmine-node --coffee test && cucumber.js) || ([ ! -f configuration ] && npm -s run-script unit))", | ||
"unit" : "jasmine-node --noColor --coffee test/unit", | ||
"integration": "jasmine-node --noColor --coffee test/integration", | ||
"lint" : "jshint lib" | ||
"features": "cucumber.js", | ||
"lint" : "jshint lib", | ||
"console": "./scripts/console" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# AWS SDK for Node.js | ||
# AWS SDK for Node.js [![Build Status](https://travis-ci.org/aws/aws-sdk-js.png?branch=master)](https://travis-ci.org/aws/aws-sdk-js) | ||
@@ -3,0 +3,0 @@ The official JavaScript implementation of the AWS SDK for Node.js. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1631548
5
117
32558
10
3