This commit is contained in:
Andre Rodrigues 2012-10-12 21:50:18 +01:00
Родитель 101f742932
Коммит 35ec0161b5
14 изменённых файлов: 61 добавлений и 20 удалений

Просмотреть файл

@ -86,7 +86,7 @@ function BlobService(storageAccountOrConnectionString, storageAccessKey, host, a
authenticationProvider);
if (!this.authenticationProvider) {
this.authenticationProvider = new SharedKey(this.storageAccount, this.storageAccessKey);
this.authenticationProvider = new SharedKey(this.storageAccount, this.storageAccessKey, this.usePathStyleUri);
}
if (!this.sharedAccessSignatureCredentials) {
@ -2176,7 +2176,7 @@ BlobService.prototype.generateSharedAccessSignature = function (container, blob,
var resourceName = createResourceName(container, blob);
var signedQueryString = this.sharedAccessSignatureCredentials.generateSignedQueryString(resourceName, {}, resourceType, sharedAccessPolicy);
var baseUrl = this.protocol + this.host + ':' + this.port;
var baseUrl = this.protocol + this._getHostname() + ':' + this.port;
var path = this._getPath('/' + resourceName);
return {
@ -2203,7 +2203,7 @@ BlobService.prototype.getBlobUrl = function (container, blob) {
var resourceName = createResourceName(container, blob);
var baseUrl = this.protocol + this.host + ':' + this.port;
var baseUrl = this.protocol + this._getHostname() + ':' + this.port;
var path = this._getPath('/' + resourceName);
return {

Просмотреть файл

@ -29,10 +29,12 @@ exports = module.exports = SharedKey;
* @constructor
* @param {string} storageAccount The storage account.
* @param {string} storageAccessKey The storage account's access key.
* @param {bool} usePathStyleUri Boolean value indicating if the path, or the hostname, should include the storage account.
*/
function SharedKey(storageAccount, storageAccessKey) {
function SharedKey(storageAccount, storageAccessKey, usePathStyleUri) {
this.storageAccount = storageAccount;
this.storageAccessKey = storageAccessKey;
this.usePathStyleUri = usePathStyleUri;
this.signer = new HmacSha256Sign(storageAccessKey);
}

Просмотреть файл

@ -31,10 +31,12 @@ exports = module.exports = SharedKeyLite;
* @constructor
* @param {string} storageAccount The storage account.
* @param {string} storageAccessKey The storage account's access key.
* @param {bool} usePathStyleUri Boolean value indicating if the path, or the hostname, should include the storage account.
*/
function SharedKeyLite(storageAccount, storageAccessKey) {
function SharedKeyLite(storageAccount, storageAccessKey, usePathStyleUri) {
this.storageAccount = storageAccount;
this.storageAccessKey = storageAccessKey;
this.usePathStyleUri = usePathStyleUri;
this.signer = new HmacSha256Sign(storageAccessKey);
}

Просмотреть файл

@ -69,7 +69,7 @@ ServiceBusServiceClient.prototype._buildRequestOptions = function (webResource,
}
webResource.addOptionalHeader(HeaderConstants.ACCEPT_CHARSET_HEADER, 'UTF-8');
webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this.host + ':' + this.port);
webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this._getHostname() + ':' + this.port);
// Sets the request url in the web resource.
this._setRequestUrl(webResource);
@ -90,7 +90,7 @@ ServiceBusServiceClient.prototype._buildRequestOptions = function (webResource,
requestOptions = {
url: url.format({
protocol: self._isHttps() ? 'https:' : 'http:',
hostname: self.host,
hostname: self._getHostname(),
port: self.port,
pathname: webResource.path + webResource.getQueryString(true)
}),
@ -121,4 +121,13 @@ ServiceBusServiceClient.prototype._getPath = function (path) {
}
return path;
};
/**
* Retrives the hostname.
*
* @return {string} The hostname.
*/
ServiceBusServiceClient.prototype._getHostname = function () {
return this.namespace + '.' + this.host;
};

Просмотреть файл

@ -514,7 +514,7 @@ ServiceClient.prototype._setRequestUrl = function (webResource) {
var queryString = webResource.getQueryString(true);
// Build the full request url
webResource.requestUrl = this.protocol + this.host + ":" + this.port + webResource.path + queryString;
webResource.requestUrl = this.protocol + this._getHostname() + ":" + this.port + webResource.path + queryString;
};
/**

Просмотреть файл

@ -190,7 +190,7 @@ ServiceManagementClient.prototype._buildRequestOptions = function(webResource, o
var requestOptions = {
url: url.format({
protocol: self._isHttps() ? 'https' : 'http',
hostname: self.host,
hostname: self._getHostname(),
port: self.port,
pathname: webResource.path + webResource.getQueryString(true)
}),

Просмотреть файл

@ -51,6 +51,7 @@ StorageServiceClient.incorrectStorageAccessKeyErr = 'You must supply an account
function StorageServiceClient(storageAccount, storageAccessKey, host, authenticationProvider) {
this._setAccountCredentials(storageAccount, storageAccessKey);
this.apiVersion = HeaderConstants.TARGET_STORAGE_VERSION;
this.usePathStyleUri = ServiceClient.isEmulated(host);
StorageServiceClient.super_.call(this, host, authenticationProvider);
@ -142,7 +143,7 @@ StorageServiceClient.prototype._buildRequestOptions = function (webResource, opt
webResource.addOptionalHeader(HeaderConstants.ACCEPT_HEADER, 'application/atom+xml,application/xml');
webResource.addOptionalHeader(HeaderConstants.ACCEPT_CHARSET_HEADER, 'UTF-8');
webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this.host + ':' + this.port);
webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this._getHostname() + ':' + this.port);
if (options) {
if (options.timeoutIntervalInMs) {
@ -169,7 +170,7 @@ StorageServiceClient.prototype._buildRequestOptions = function (webResource, opt
requestOptions = {
url: url.format({
protocol: self._isHttps() ? 'https:' : 'http:',
hostname: self.host,
hostname: self._getHostname(),
port: self.port,
pathname: webResource.path + webResource.getQueryString(true)
}),
@ -186,6 +187,10 @@ StorageServiceClient.prototype._buildRequestOptions = function (webResource, opt
/**
* Retrieves the normalized path to be used in a request.
* This takes into consideration the usePathStyleUri object field
* which specifies if the request is against the emulator or against
* the live service. It also adds a leading "/" to the path in case
* it's not there before.
*
* @param {string} path The path to be normalized.
* @return {string} The normalized path.
@ -197,9 +202,27 @@ StorageServiceClient.prototype._getPath = function (path) {
path = '/' + path;
}
if (this.usePathStyleUri) {
path = '/' + this.storageAccount + path;
}
return path;
};
/**
* Retrives the hostname taking into consideration the usePathStyleUri flag which indicates whether the account
* should be a prefix for it or not.
*
* @return {string} The hostname.
*/
StorageServiceClient.prototype._getHostname = function () {
if (this.usePathStyleUri) {
return this.host;
}
return this.storageAccount + '.' + this.host;
};
/**
* Sets the account credentials taking into consideration the isEmulated value and the environment variables:
* AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY.

Просмотреть файл

@ -60,7 +60,7 @@ function QueueService(storageAccountOrConnectionString, storageAccessKey, host,
authenticationProvider);
if (!this.authenticationProvider) {
this.authenticationProvider = new SharedKey(this.storageAccount, this.storageAccessKey);
this.authenticationProvider = new SharedKey(this.storageAccount, this.storageAccessKey, this.usePathStyleUri);
}
}

Просмотреть файл

@ -31,10 +31,12 @@ exports = module.exports = SharedKeyLiteTable;
* @constructor
* @param {string} storageAccount The storage account.
* @param {string} storageAccessKey The storage account's access key.
* @param {bool} usePathStyleUri Boolean value indicating if the path, or the hostname, should include the storage account.
*/
function SharedKeyLiteTable(storageAccount, storageAccessKey) {
function SharedKeyLiteTable(storageAccount, storageAccessKey, usePathStyleUri) {
this.storageAccount = storageAccount;
this.storageAccessKey = storageAccessKey;
this.usePathStyleUri = usePathStyleUri;
this.signer = new HmacSha256Sign(storageAccessKey);
}

Просмотреть файл

@ -31,10 +31,12 @@ exports = module.exports = SharedKeyTable;
* @constructor
* @param {string} storageAccount The storage account.
* @param {string} storageAccessKey The storage account's access key.
* @param {bool} usePathStyleUri Boolean value indicating if the path, or the hostname, should include the storage account.
*/
function SharedKeyTable(storageAccount, storageAccessKey) {
function SharedKeyTable(storageAccount, storageAccessKey, usePathStyleUri) {
this.storageAccount = storageAccount;
this.storageAccessKey = storageAccessKey;
this.usePathStyleUri = usePathStyleUri;
this.signer = new HmacSha256Sign(storageAccessKey);
}

Просмотреть файл

@ -71,7 +71,7 @@ function TableService(storageAccountOrConnectionString, storageAccessKey, host,
authenticationProvider);
if (!this.authenticationProvider) {
this.authenticationProvider = new SharedKeyTable(this.storageAccount, this.storageAccessKey);
this.authenticationProvider = new SharedKeyTable(this.storageAccount, this.storageAccessKey, this.usePathStyleUri);
}
}

Просмотреть файл

@ -24,10 +24,10 @@ var ServiceBusServiceClient = testutil.libRequire('services/core/servicebusservi
var ServiceClient = azure.ServiceClient;
var environmentAzureStorageAccount = 'myaccount';
var environmentAzureStorageAccessKey = 'myaccountstoragekey';
var environmentAzureStorageAccessKey = 'AhlzsbLRkjfwObuqff3xrhB2yWJNh1EMptmcmxFJ6fvPTVX3PZXwrG2YtYWf5DPMVgNsteKStM5iBLlknYFVoA==';
var environmentServiceBusNamespace = 'mynamespace';
var environmentServiceBusIssuer = 'myissuer';
var environmentServiceBusAccessKey = 'myaccesskey';
var environmentServiceBusAccessKey = 'AhlzsbLRkjfwObuqff3xrhB2yWJNh1EMptmcmxFJ6fvPTVX3PZXwrG2YtYWf5DPMVgNsteKStM5iBLlknYFVoA==';
var environmentWrapNamespace = 'mynamespace-sb';
var parameterAzureStorageAccount = 'storageAccount';

Просмотреть файл

@ -1608,13 +1608,14 @@ suite('servicebusservice-tests', function () {
});
test('connectionStrings', function (done) {
var connectionString = 'Endpoint=sb://ablal-martvue.servicebus.windows.net/;StsEndpoint=https://ablal-martvue-sb.accesscontrol.windows.net;SharedSecretIssuer=owner;SharedSecretValue=value';
var key = 'AhlzsbLRkjfwObuqff3xrhB2yWJNh1EMptmcmxFJ6fvPTVX3PZXwrG2YtYWf5DPMVgNsteKStM5iBLlknYFVoA==';
var connectionString = 'Endpoint=sb://ablal-martvue.servicebus.windows.net/;StsEndpoint=https://ablal-martvue-sb.accesscontrol.windows.net;SharedSecretIssuer=owner;SharedSecretValue=' + key;
var serviceBusService = azure.createServiceBusService(connectionString);
assert.equal(serviceBusService.host, 'servicebus.windows.net');
assert.equal(serviceBusService.namespace, 'ablal-martvue');
assert.equal(serviceBusService.issuer, 'owner');
assert.equal(serviceBusService.accessKey, 'value');
assert.equal(serviceBusService.accessKey, key);
assert.equal(serviceBusService.acsNamespace, 'ablal-martvue-sb');
done();

Просмотреть файл

@ -24,7 +24,7 @@ suite('servicesettings-tests', function () {
var validUri = Validate.getIsValidUri();
validUri('http://www.microsoft.com').should.be.ok;
validUri('http://www.microsoft.com').should.strictEqual(true);
validUri('http://www.microsoft.com').should.equal(true);
(function() {
validUri('something');