Skip to content

Commit

Permalink
Merge pull request #75 from yaxia/master
Browse files Browse the repository at this point in the history
Storage Client Library - 0.5.0
  • Loading branch information
slepox committed Aug 6, 2015
2 parents 97b0429 + c7857f9 commit 631beb4
Show file tree
Hide file tree
Showing 82 changed files with 20,003 additions and 11,288 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ results

npm-debug.log
node_modules
docs
docs
18 changes: 18 additions & 0 deletions BreakingChanges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Tracking Breaking Changes in 0.5.0
ALL
* The suffix "_HEADER" is removed from all the http header constants.
* The generateSharedAccessSignatureWithVersion function in each service is deprecated.
* The shouldRetry function in the retry policy filters takes a "requestOption" object instead of a "retryData" object.

BLOB
* The "publicAccessLevel" parameter in the BlobService.setContainerACL function is moved into the "options" parameter.
* The properties in the BlobService.setBlobProperties function are moved from the "options" to the "properties" parameter.
* The "AccessPolicy.Permission" is renamed to "AccessPolicy.Permissions" on the result object of the BlobService.getContainerAcl function.

TABLE
* The "signedIdentifiers" parameter in the TableService.SetTableACL function is moved out from the "options" parameter.
* The "AccessPolicy.Permission" is renamed to "AccessPolicy.Permissions" on the result object of the TableService.getTableAcl function.

QUEUE
* The option "options.messagetext" is renamed to "options.messageText" in the QueueService.UpdateMessage function.
* The "AccessPolicy.Permission" is renamed to "AccessPolicy.Permissions" on the result object of the QueueService.getQueueAcl function.
21 changes: 20 additions & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
Note: This is an Azure Storage only package. The all up Azure node sdk still has the old storage bits in there. In a future release, those storage bits will be removed and an npm dependency to this storage node sdk will
be taken. This is a CTP v1 release and the changes described below indicate the changes from the Azure node SDK 0.9.8 available here - https://github.com/Azure/azure-sdk-for-node.

2015.06 Version 0.4.5
2015.08 Version 0.5.0

ALL
* Updated storage service version to 2015-02-21. For more information, please see - https://msdn.microsoft.com/en-us/library/azure/dd894041.aspx
* Unified the function parameters for setting ACL of container, table, queue and share.
* Renamed 'AccessPolicy.Permission' to 'AccessPolicy.Permissions' on the result object from get*Acl to match the property name on the signedIdentifier property passed to set*Acl calls.
* Unified the name pattern of the http header constants.
* Split the property parameters from the options parameter for setting properties of blob, share and file.
* Updated the error message when an argument is in a wrong type while it requires a string.
* Exported AccessCondition to generate an object that represents a condition.
* Fixed an issue that the SAS in the SharedAccessSignature part of the connection string cannot start with '?'.
* Deprecated the generateSharedAccessSignatureWithVersion() method in each service.

BLOB
* Supported operating against append blobs.
* Fixed an issue that the file descriptor in the FileReadStream is not closed.

QUEUE
* Fixed an issue that options.messageText doesn't work in QueueService.updateMessage.

2015.06 Version 0.4.5

* Updated the dependency of the 'request' module to avoid the security vulnerability reported by the 'nsp' tool: (https://nodesecurity.io/advisories/qs_dos_extended_event_loop_blocking) and (https://nodesecurity.io/advisories/qs_dos_memory_exhaustion).
* Included package validation in grunt tasks.

Expand Down
4 changes: 2 additions & 2 deletions examples/blobuploader/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ blobClient.createContainerIfNotExists(containerName, function (error) {
}
});


function setSAS(containerName, blobName) {
var sharedAccessPolicy = {
AccessPolicy: {
Expand All @@ -158,7 +157,8 @@ function setSAS(containerName, blobName) {
}

function setPermissions() {
blobClient.setContainerAcl(containerName, azure.BlobUtilities.BlobContainerPublicAccessType.BLOB, function (error) {
var options = { publicAccessLevel: azure.BlobUtilities.BlobContainerPublicAccessType.BLOB };
blobClient.setContainerAcl(containerName, null, options, function (error) {
if (error) {
console.log(error);
} else {
Expand Down
5 changes: 3 additions & 2 deletions examples/samples/sassample.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ function createPolicies (callback) {
var signedIdentifiers = [readWriteSharedAccessPolicy, readSharedAccessPolicy];

// Wait 30 seconds for the container acl to be processed
var func = function() {
blobService.setContainerAcl(container, signedIdentifiers, BlobUtilities.BlobContainerPublicAccessType.CONTAINER, function(error) {
var func = function () {
var options = { publicAccessLevel: BlobUtilities.BlobContainerPublicAccessType.CONTAINER };
blobService.setContainerAcl(container, signedIdentifiers, options, function(error) {
if (error) {
console.log(error);
} else {
Expand Down
1 change: 1 addition & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
module.exports = function(grunt) {
//init stuff
grunt.initConfig({

pkg: grunt.file.readJSON('package.json'),

mochaTest: {
Expand Down
13 changes: 13 additions & 0 deletions lib/azure-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ exports.createFileService = function (storageAccountOrConnectionString, storageA
return new FileService(storageAccountOrConnectionString, storageAccessKey, host);
};

/**
* Creates a new {@link FileService} object using the host Uri and the SAS credentials provided.
*
* @param {string|object} host The host address. To define primary only, pass a string.
* Otherwise 'host.primaryHost' defines the primary host and 'host.secondaryHost' defines the secondary host.
* @param {string} sasToken The Shared Access Signature token.
* @return {FileService} A new FileService object with the SAS credentials.
*/
exports.createFileServiceWithSas = function (hostUri, sasToken) {
return new FileService(null, null, hostUri, sasToken);
};

/**
* Queue client exports.
* @ignore
Expand Down Expand Up @@ -202,6 +214,7 @@ var azureCommon = require('./common/common');

exports.Constants = azureCommon.Constants;
exports.StorageUtilities = azureCommon.StorageUtilities;
exports.AccessCondition = azureCommon.AccessCondition;

exports.SR = azureCommon.SR;
exports.StorageServiceClient = azureCommon.StorageServiceClient;
Expand Down
3 changes: 2 additions & 1 deletion lib/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ exports.date = require('./util/date');
exports.ISO8061Date = require('./util/iso8061date');
exports.util = require('./util/util');
exports.validate = require('./util/validate');
exports.StorageUtilities = require('./util/storageutilities');
exports.StorageUtilities = require('./util/storageutilities');
exports.AccessCondition = require('./util/accesscondition');
23 changes: 8 additions & 15 deletions lib/common/filters/exponentialretrypolicyfilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ var RetryPolicyFilter = require('./retrypolicyfilter');
* To apply a filter to service operations, use `withFilter`
* and specify the filter to be used when creating a service.
* @constructor
* @param {number} [retryCount=3] The client retry count.
* @param {number} [retryCount=3] The client retry count.
* @param {number} [retryInterval=30000] The client retry interval, in milliseconds.
* @param {number} [minRetryInterval=3000] The minimum retry interval, in milliseconds.
* @param {number} [minRetryInterval=3000] The minimum retry interval, in milliseconds.
* @param {number} [maxRetryInterval=90000] The maximum retry interval, in milliseconds.
*
* @example
Expand Down Expand Up @@ -66,28 +66,21 @@ ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MIN_RETRY_INTERVAL = 1000 * 3;
* Determines if the operation should be retried and how long to wait until the next retry.
*
* @param {number} statusCode The HTTP status code.
* @param {object} retryData The retry data.
* @param {object} requestOptions The request options.
* @return {retryInfo} Information about whether the operation qualifies for a retry and the retryInterval.
*/
ExponentialRetryPolicyFilter.prototype.shouldRetry = function (statusCode, retryData) {

var currentCount = (retryData && retryData.retryCount) ? retryData.retryCount : 0;
ExponentialRetryPolicyFilter.prototype.shouldRetry = function (statusCode, requestOptions) {
var retryData = (requestOptions && requestOptions.retryContext) ? requestOptions.retryContext : {};

// Adjust retry interval
var incrementDelta = Math.pow(2, retryData.retryCount) - 1;
var boundedRandDelta = this.retryInterval * 0.8 + Math.floor(Math.random() * (this.retryInterval * 1.2 - this.retryInterval * 0.8));
incrementDelta *= boundedRandDelta;

var retryInfo = {
retryInterval: Math.min(this.minRetryInterval + incrementDelta, this.maxRetryInterval),
retryable: currentCount < this.retryCount
};

if ((statusCode >= 300 && statusCode < 500 && statusCode != 408) || statusCode == 501 || statusCode == 505) {
retryInfo.retryable = false;
}
retryData.retryInterval = Math.min(this.minRetryInterval + incrementDelta, this.maxRetryInterval);
retryData.retryable = retryData.retryCount ? retryData.retryCount < this.retryCount : true;

return retryInfo;
return RetryPolicyFilter._shouldAbsorbConditionalError(statusCode, requestOptions);
};

/**
Expand Down
25 changes: 9 additions & 16 deletions lib/common/filters/linearretrypolicyfilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var RetryPolicyFilter = require('./retrypolicyfilter');
* To apply a filter to service operations, use `withFilter`
* and specify the filter to be used when creating a service.
* @constructor
* @param {number} [retryCount=30000] The client retry count.
* @param {number} [retryInterval=3] The client retry interval, in milliseconds.
* @param {number} [retryCount=3] The client retry count.
* @param {number} [retryInterval=30000] The client retry interval, in milliseconds.
*
* @example
* var azure = require('azure-storage');
Expand All @@ -51,23 +51,16 @@ LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT = 3;
/**
* Determines if the operation should be retried and how long to wait until the next retry.
*
* @param {number} statusCode The HTTP status code.
* @param {object} retryData The retry data.
* @param {number} statusCode The HTTP status code.
* @param {object} requestOptions The request options.
* @return {retryInfo} Information about whether the operation qualifies for a retry and the retryInterval.
*/
LinearRetryPolicyFilter.prototype.shouldRetry = function (statusCode, retryData) {
LinearRetryPolicyFilter.prototype.shouldRetry = function (statusCode, requestOptions) {
var retryData = (requestOptions && requestOptions.retryContext) ? requestOptions.retryContext : {};
retryData.retryInterval = this.retryInterval;
retryData.retryable = retryData.retryCount ? retryData.retryCount < this.retryCount : true;

var currentCount = (retryData && retryData.retryCount) ? retryData.retryCount : 0;
var retryInfo = {
retryInterval: this.retryInterval,
retryable: currentCount < this.retryCount,
};

if ((statusCode >= 300 && statusCode < 500 && statusCode != 408) || statusCode == 501 || statusCode == 505) {
retryInfo.retryable = false;
}

return retryInfo;
return RetryPolicyFilter._shouldAbsorbConditionalError(statusCode, requestOptions);
};

/**
Expand Down
34 changes: 33 additions & 1 deletion lib/common/filters/retrypolicyfilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ RetryPolicyFilter._handle = function (self, requestOptions, next) {
// location, the failure should still be retryable.
var secondaryNotFound = (retryRequestOptions.currentLocation === Constants.StorageLocation.SECONDARY) && (returnObject.response && returnObject.response.statusCode === 404);

var retryInfo = self.shouldRetry(secondaryNotFound ? 500 : (azureutil.objectIsNull(returnObject.response) ? 306 : returnObject.response.statusCode), retryRequestOptions.retryContext);
var retryInfo = self.shouldRetry(secondaryNotFound ? 500 : (azureutil.objectIsNull(returnObject.response) ? 306 : returnObject.response.statusCode), retryRequestOptions);
retryRequestOptions.retryContext.retryCount++;

if (retryInfo.ignore) {
returnObject.error = null;
}

// If the custom retry logic(shouldRetry) does not return a targetLocation, calculate based on the previous location and locationMode.
if(azureutil.objectIsNull(retryInfo.targetLocation)) {
Expand Down Expand Up @@ -181,4 +185,32 @@ RetryPolicyFilter._handle = function (self, requestOptions, next) {
operation();
};

RetryPolicyFilter._shouldAbsorbConditionalError = function (statusCode, requestOptions) {
var retryInfo = (requestOptions && requestOptions.retryContext) ? requestOptions.retryContext : {};

if (statusCode >= 300) {
if (requestOptions && !requestOptions.absorbConditionalErrorsOnRetry) {
retryInfo.retryable = false;
return retryInfo;
}

if (statusCode == 501 || statusCode == 505) {
retryInfo.retryable = false;
} else if (statusCode == 412) {
// When appending block with precondition failure and their was a server error before, we ignore the error.
if (retryInfo.lastServerError) {
retryInfo.ignore = true;
retryInfo.retryable = true;
} else {
retryInfo.retryable = false;
}
} else if (retryInfo.retryable && statusCode >= 500 && statusCode < 600) {
retryInfo.retryable = true;
retryInfo.lastServerError = true;
}
}

return retryInfo;
};

module.exports = RetryPolicyFilter;
2 changes: 1 addition & 1 deletion lib/common/models/aclresult.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ exports.parse = function (signedIdentifiersXml) {
}

if (signedIdentifier.AccessPolicy.Permission) {
si.AccessPolicy.Permission = signedIdentifier.AccessPolicy.Permission;
si.AccessPolicy.Permissions = signedIdentifier.AccessPolicy.Permission;
}
}

Expand Down
Loading

0 comments on commit 631beb4

Please sign in to comment.