Permalink
Browse files

Merge pull request #474 from andrerod/dev

#469: Making access conditions case insensitive.
  • Loading branch information...
2 parents 34d13cf + 747db08 commit 3c7440d2bd267d8d56205a3f149ae04aeec62266 André Rodrigues committed Nov 15, 2012
@@ -53,8 +53,7 @@ function createContainer() {
blobService.createContainerIfNotExists(container, function (error) {
if (error) {
console.log(error);
- }
- else {
+ } else {
console.log('Created the container ' + container);
uploadSample();
}
@@ -203,8 +202,7 @@ function testAccess(containerName, blobName, etag) {
if (processArguments.length > 5 || processArguments.length < 4) {
console.log('Incorrect number of arguments');
-}
-else if (processArguments.length == 5) {
+} else if (processArguments.length == 5) {
// Adding a third argument on the command line, whatever it is, will delete the container before running the sample.
blobService.deleteContainer(container, function (error) {
if (error) {
@@ -213,8 +211,7 @@ else if (processArguments.length == 5) {
createContainer();
}
});
-}
-else {
+} else {
createContainer();
}
View
@@ -287,40 +287,48 @@ WebResource.prototype.addOptionalMetadataHeaders = function (metadata) {
WebResource.prototype.addOptionalAccessConditionHeader = function (accessConditionHeaders) {
if (accessConditionHeaders) {
- if (accessConditionHeaders[HeaderConstants.IF_MATCH]) {
- this.addOptionalHeader(HeaderConstants.IF_MATCH, accessConditionHeaders[HeaderConstants.IF_MATCH]);
+ var ifMatch = azureutil.tryGetValueInsensitive(HeaderConstants.IF_MATCH, accessConditionHeaders);
+ if (ifMatch) {
+ this.addOptionalHeader(HeaderConstants.IF_MATCH, ifMatch);
}
- if (accessConditionHeaders[HeaderConstants.IF_MODIFIED_SINCE]) {
- this.addOptionalHeader(HeaderConstants.IF_MODIFIED_SINCE, accessConditionHeaders[HeaderConstants.IF_MODIFIED_SINCE]);
+ var ifModifiedSince = azureutil.tryGetValueInsensitive(HeaderConstants.IF_MODIFIED_SINCE, accessConditionHeaders);
+ if (ifModifiedSince) {
+ this.addOptionalHeader(HeaderConstants.IF_MODIFIED_SINCE, ifModifiedSince);
}
- if (accessConditionHeaders[HeaderConstants.IF_NONE_MATCH]) {
- this.addOptionalHeader(HeaderConstants.IF_NONE_MATCH, accessConditionHeaders[HeaderConstants.IF_NONE_MATCH]);
+ var ifNoneMatch = azureutil.tryGetValueInsensitive(HeaderConstants.IF_NONE_MATCH, accessConditionHeaders);
+ if (ifNoneMatch) {
+ this.addOptionalHeader(HeaderConstants.IF_NONE_MATCH, ifNoneMatch);
}
- if (accessConditionHeaders[HeaderConstants.IF_UNMODIFIED_SINCE]) {
- this.addOptionalHeader(HeaderConstants.IF_UNMODIFIED_SINCE, accessConditionHeaders[HeaderConstants.IF_UNMODIFIED_SINCE]);
+ var ifUnmodifiedSince = azureutil.tryGetValueInsensitive(HeaderConstants.IF_UNMODIFIED_SINCE, accessConditionHeaders);
+ if (ifUnmodifiedSince) {
+ this.addOptionalHeader(HeaderConstants.IF_UNMODIFIED_SINCE, ifUnmodifiedSince);
}
}
};
WebResource.prototype.addOptionalSourceAccessConditionHeader = function (accessConditionHeaders) {
if (accessConditionHeaders) {
- if (accessConditionHeaders[HeaderConstants.SOURCE_IF_MATCH_HEADER]) {
- this.addOptionalHeader(HeaderConstants.SOURCE_IF_MATCH_HEADER, accessConditionHeaders[HeaderConstants.SOURCE_IF_MATCH_HEADER]);
+ var sourceIfMatch = azureutil.tryGetValueInsensitive(HeaderConstants.SOURCE_IF_MATCH_HEADER, accessConditionHeaders);
+ if (sourceIfMatch) {
+ this.addOptionalHeader(HeaderConstants.SOURCE_IF_MATCH_HEADER, sourceIfMatch);
}
- if (accessConditionHeaders[HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER]) {
- this.addOptionalHeader(HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER, accessConditionHeaders[HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER]);
+ var sourceIfModifiedSince = azureutil.tryGetValueInsensitive(HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER, accessConditionHeaders);
+ if (sourceIfModifiedSince) {
+ this.addOptionalHeader(HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER, sourceIfModifiedSince);
}
- if (accessConditionHeaders[HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER]) {
- this.addOptionalHeader(HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER, accessConditionHeaders[HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER]);
+ var sourceIfNoneMatch = azureutil.tryGetValueInsensitive(HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER, accessConditionHeaders);
+ if (sourceIfNoneMatch) {
+ this.addOptionalHeader(HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER, sourceIfNoneMatch);
}
- if (accessConditionHeaders[HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER]) {
- this.addOptionalHeader(HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER, accessConditionHeaders[HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER]);
+ var sourceIfUnmodifiedSince = azureutil.tryGetValueInsensitive(HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER, accessConditionHeaders);
+ if (sourceIfUnmodifiedSince) {
+ this.addOptionalHeader(HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER, sourceIfUnmodifiedSince);
}
}
};
@@ -22,6 +22,8 @@ var ISO8061Date = require('../../../util/iso8061date');
// Expose 'ContainerAclResult'.
exports = module.exports = ContainerAclResult;
+var ACL_MILLISECONDS_PADING = 7;
+
function ContainerAclResult(signedIdentifiers) {
if (signedIdentifiers) {
this.signedIdentifiers = signedIdentifiers;
@@ -51,7 +53,7 @@ ContainerAclResult.serialize = function (signedIdentifiersJs) {
var startIsoString = signedIdentifier.AccessPolicy.Start;
if (startIsoString instanceof Date) {
// Convert to expected ISO 8061 date format
- startIsoString = ISO8061Date.format(startIsoString);
+ startIsoString = ISO8061Date.format(startIsoString, ACL_MILLISECONDS_PADING);
}
doc = doc
@@ -64,7 +66,7 @@ ContainerAclResult.serialize = function (signedIdentifiersJs) {
var expiryIsoString = signedIdentifier.AccessPolicy.Expiry;
if (expiryIsoString instanceof Date) {
// Convert to expected ISO 8061 date format
- expiryIsoString = ISO8061Date.format(expiryIsoString);
+ expiryIsoString = ISO8061Date.format(expiryIsoString, ACL_MILLISECONDS_PADING);
}
doc = doc
@@ -131,6 +131,81 @@ ServiceManagementSerialize.prototype.buildCreateStorageAccount = function(servic
};
/**
+* Create the message body for UpdateStorageAccount
+*
+* @param {string} serviceName The name of the service.
+* @param {object} serviceOptions The properties for the new service.
+* @param {object} client The servicemanagement object.
+*/
+ServiceManagementSerialize.prototype.buildUpdateStorageAccount = function(serviceName, serviceOptions, client) {
+ var encLabel = undefined;
+ if (serviceOptions.Label) {
+ encLabel = new Buffer(serviceOptions.Label).toString('base64');
+ }
+
+ if (client.serializetype === 'XML') {
+ var doc = _createXmlRoot('UpdateStorageServiceInput');
+ _addDefinedValueXml(doc, 'ServiceName', serviceName);
+
+ if (encLabel) {
+ _addDefinedValueXml(doc, 'Label', encLabel);
+ }
+
+ if (serviceOptions.Description) {
+ _addDefinedValueXml(doc, 'Description', serviceOptions.Description);
+ }
+
+ if (serviceOptions.GeoReplicationEnabled) {
+ _addDefinedValueXml(doc, 'GeoReplicationEnabled', serviceOptions.GeoReplicationEnabled);
+ }
+
+ return doc.toString();
+ } else {
+ var jdoc = {
+ ServiceName: serviceName
+ };
+
+ if (encLabel) {
+ jdoc.Label = encLabel;
+ }
+
+ if (serviceOptions.Description) {
+ jdoc.Description = serviceOptions.Description;
+ }
+
+ if (serviceOptions.GeoReplicationEnabled) {
+ jdoc.GeoReplicationEnabled = serviceOptions.GeoReplicationEnabled;
+ }
+
+ return JSON.stringify(jdoc);
+ }
+};
+
+/**
+* Create the message body for RegenerateStorageKeys
+*
+* @param {string} serviceName The name of the service.
+* @param {string} keyType The key type.
+* @param {object} client The servicemanagement object.
+*/
+ServiceManagementSerialize.prototype.buildRegenerateStorageKeys = function(serviceName, keyType, client) {
+ if (client.serializetype === 'XML') {
+ var doc = _createXmlRoot('RegenerateKeys');
+ doc.ele('KeyType').txt(keyType);
+
+ return doc.toString();
+ } else {
+ var jdoc = {
+ RegenerateKeys: {
+ KeyType: keyType
+ }
+ };
+
+ return JSON.stringify(jdoc);
+ }
+};
+
+/**
* Create the message body for CreateOSImage
* Use the specified serialization - for now only XML.
*
@@ -570,7 +570,7 @@ ServiceManagementService.prototype.deleteHostedService = function(serviceName, c
};
/**
-* Returns keys of specified storage account.
+* Creates a new storage account.
*
* @param {string} serviceName The name of the storage service. Required.
* @param {string} serviceOptions Object with properties for the service. Optional
@@ -629,6 +629,44 @@ ServiceManagementService.prototype.createStorageAccount = function(serviceName,
};
/**
+* Updates a storage account.
+*
+* @param {string} serviceName The name of the storage service. Required.
+* @param {string} serviceOptions Object with properties for the service. Optional
+* {
+* Description: optional. Defaults to 'Service host'
+* Label: optional. Defaults to serviceName
+* GeoReplicationEnabled: optional. Indicates if the geo replication is enabled.
+* }
+* @param {function} callback The callback function called on completion. Required.
+*/
+ServiceManagementService.prototype.updateStorageAccount = function(serviceName, serviceOptions, callback) {
+ if (!callback) {
+ if (typeof serviceOptions === 'function') {
+ callback = serviceOptions;
+ serviceOptions = null;
+ }
+ }
+
+ validateStringArgument(serviceName, 'serviceName', 'updateStorageAccount');
+ validateObjectArgument(callback, 'callback', 'updateStorageAccount');
+
+ var path = '/' + this.subscriptionId + '/services/storageservices/' + serviceName;
+ var webResource = WebResource.put(path);
+ webResource.withOkCode(HttpConstants.HttpResponseCodes.OK_CODE, true);
+
+ var outbody = this.serialize.buildUpdateStorageAccount(serviceName, serviceOptions, this);
+ this.performRequest(webResource, outbody, null, function (responseObject, next) {
+
+ var finalCallback = function (returnObject) {
+ callback(returnObject.error, returnObject.response);
+ };
+
+ next(responseObject, finalCallback);
+ });
+};
+
+/**
* Returns keys of specified storage account.
*
* @param {string} serviceName The name of the storage service. Required.
@@ -680,6 +718,62 @@ ServiceManagementService.prototype.getStorageAccountProperties = function(servic
};
/**
+* Regenerates a storage account's keys
+*
+* @param {string} serviceName The name of the hosted service. Required.
+* @param {string} keyType The storage key type (primary or secondary). Required.
+* @param {function} callback The callback function called on completion. Required.
+*/
+ServiceManagementService.prototype.regenerateStorageAccountKeys = function(serviceName, keyType, callback) {
+ validateStringArgument(serviceName, 'serviceName', 'deleteDeployment');
+ validateObjectArgument(callback, 'callback', 'deleteDeployment');
+
+ if (keyType.toLowerCase() !== 'primary' && keyType.toLowerCase() !== 'secondary') {
+ throw new Error('Invalid storage account type');
+ }
+
+ var path = '/' + this.subscriptionId + '/services/storageservices/' + serviceName + '/keys?action=regenerate';
+ var webResource = WebResource.post(path);
+ webResource.withOkCode(HttpConstants.HttpResponseCodes.OK_CODE, true);
+ var outbody = this.serialize.buildRegenerateStorageKeys(serviceName, keyType, this);
+
+
+
+ this.performRequest(webResource, outbody, null, function (responseObject, next) {
+
+ var finalCallback = function (returnObject) {
+ callback(returnObject.error, returnObject.response);
+ };
+
+ next(responseObject, finalCallback);
+ });
+};
+
+/**
+* Deletes a storage account
+*
+* @param {string} serviceName The name of the hosted service. Required.
+* @param {function} callback The callback function called on completion. Required.
+*/
+ServiceManagementService.prototype.deleteStorageAccount = function(serviceName, callback) {
+ validateStringArgument(serviceName, 'serviceName', 'deleteDeployment');
+ validateObjectArgument(callback, 'callback', 'deleteDeployment');
+
+ var path = '/' + this.subscriptionId + '/services/storageservices/' + serviceName;
+ var webResource = WebResource.del(path);
+ webResource.withOkCode(HttpConstants.HttpResponseCodes.OK_CODE, true);
+
+ this.performRequest(webResource, null, null, function (responseObject, next) {
+
+ var finalCallback = function (returnObject) {
+ callback(returnObject.error, returnObject.response);
+ };
+
+ next(responseObject, finalCallback);
+ });
+};
+
+/**
* Gets deployment properties for named deployment
*
* @param {string} serviceName The name of the hosted service. Required.
View
@@ -16,11 +16,12 @@
/**
* Formats a date into an iso 8061 string.
*
-* @param {date} date The date to format.
-* @param {bool} skipMilliseconds Boolean value indicating if the miliseconds part of the date should not be included.
+* @param {date} date The date to format.
+* @param {bool} skipMilliseconds Boolean value indicating if the miliseconds part of the date should not be included.
+* @param {integer} millisecondsPading Number of digits to left pad the miliseconds.
* @return {string} The date formated in the ISO 8061 date format.
*/
-exports.format = function (date, skipMilliseconds) {
+exports.format = function (date, skipMilliseconds, millisecondsPading) {
var components = [
date.getUTCFullYear(),
'-',
@@ -37,7 +38,11 @@ exports.format = function (date, skipMilliseconds) {
if (!skipMilliseconds) {
components.push('.');
- components.push(leftPadThree(date.getUTCMilliseconds()));
+ if (!millisecondsPading) {
+ millisecondsPading = 3;
+ }
+
+ components.push(leftPad(date.getUTCMilliseconds(), millisecondsPading));
}
components.push('Z');
@@ -77,9 +82,9 @@ var leftPadTwo = function (n) {
return (n < 10 ? '0' : '') + n;
};
-var leftPadThree = function (n) {
+var leftPad = function (n, millisecondsPading) {
var currentN = '' + n;
- while (currentN.length < 3) {
+ while (currentN.length < millisecondsPading) {
currentN = '0' + currentN;
}
Oops, something went wrong.

0 comments on commit 3c7440d

Please sign in to comment.