Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'plumbing' into connectionStrings
Browse files Browse the repository at this point in the history
Conflicts:
	lib/services/core/servicebussettings.js
	lib/services/core/servicesettings.js
	lib/services/core/storageservicesettings.js
  • Loading branch information
Andre Rodrigues committed Oct 13, 2012
2 parents e761a92 + bd660e4 commit a499fbe
Show file tree
Hide file tree
Showing 25 changed files with 365 additions and 321 deletions.
20 changes: 10 additions & 10 deletions lib/services/blob/blobservice.js
Expand Up @@ -16,6 +16,7 @@
// Module dependencies.
var fs = require('fs');
var qs = require('qs');
var url = require('url');
var path = require('path');
var util = require('util');
var crypto = require('crypto');
Expand Down Expand Up @@ -76,15 +77,14 @@ BlobService.incorrectEndByteOffsetErr = 'End byte offset must be a modulus of 51
* @param {object} [authenticationProvider] The authentication provider.
*/
function BlobService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
if (!host) {
if (ServiceClient.isEmulated()) {
host = ServiceClient.DEVSTORE_BLOB_HOST;
} else {
host = ServiceClient.CLOUD_BLOB_HOST;
}
}
var storageServiceSettings = StorageServiceClient.getStorageSettings(storageAccountOrConnectionString, storageAccessKey, host);

BlobService.super_.call(this, storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider);
BlobService.super_.call(this,
storageServiceSettings._name,
storageServiceSettings._key,
storageServiceSettings._blobEndpointUri,
storageServiceSettings._usePathStyleUri,
authenticationProvider);

if (!this.authenticationProvider) {
this.authenticationProvider = new SharedKey(this.storageAccount, this.storageAccessKey, this.usePathStyleUri);
Expand Down Expand Up @@ -2177,7 +2177,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._getHostname() + ':' + this.port;
var baseUrl = this.protocol + this.host + ':' + this.port;
var path = this._getPath('/' + resourceName);

return {
Expand All @@ -2204,7 +2204,7 @@ BlobService.prototype.getBlobUrl = function (container, blob) {

var resourceName = createResourceName(container, blob);

var baseUrl = this.protocol + this._getHostname() + ':' + this.port;
var baseUrl = this.protocol + this.host + ':' + this.port;
var path = this._getPath('/' + resourceName);

return {
Expand Down
56 changes: 8 additions & 48 deletions lib/services/core/servicebusserviceclient.js
Expand Up @@ -33,49 +33,18 @@ exports = module.exports = ServiceBusServiceClient;
* Creates a new ServiceBusServiceClient object.
*
* @constructor
* @param {string} accessKey The password.
* @param {string} issuer The issuer.
* @param {string} host The host for the service.
* @param {string} [namespace] The service bus namespace.
* @param {string} [accessKey] The password.
* @param {string} [issuer] The issuer.
* @param {string} [acsNamespace] The acs namespace. Usually the same as the sb namespace with "-sb" suffix.
* @param {string} acsHost The acs host. Usually the same as the sb namespace with "-sb" suffix.
* @param {object} [authenticationProvider] The authentication provider.
*/
function ServiceBusServiceClient(host, namespace, accessKey, issuer, acsNamespace, authenticationProvider) {
this.namespace = namespace;
if (!this.namespace) {
this.namespace = process.env[ServiceClient.EnvironmentVariables.AZURE_SERVICEBUS_NAMESPACE];
}

this.acsNamespace = acsNamespace;
if (!this.acsNamespace) {
this.acsNamespace = process.env[ServiceClient.EnvironmentVariables.AZURE_WRAP_NAMESPACE];

if (!this.acsNamespace) {
this.acsNamespace = this.namespace + ServiceClient.DEFAULT_WRAP_NAMESPACE_SUFFIX;
}
}

this.issuer = issuer;
if (!this.issuer) {
this.issuer = process.env[ServiceClient.EnvironmentVariables.AZURE_SERVICEBUS_ISSUER];

if (!this.issuer) {
this.issuer = ServiceClient.DEFAULT_SERVICEBUS_ISSUER;
}
}

this.accessKey = accessKey;
if (!this.accessKey) {
this.accessKey = process.env[ServiceClient.EnvironmentVariables.AZURE_SERVICEBUS_ACCESS_KEY];
}

function ServiceBusServiceClient(accessKey, issuer, host, acsHost, authenticationProvider) {
ServiceBusServiceClient.super_.call(this, host, authenticationProvider);

this.protocol = 'https://';
this.port = 443;

this.authenticationProvider = authenticationProvider;
if (!this.authenticationProvider) {
this.authenticationProvider = new Wrap(this.acsNamespace, this.issuer, this.accessKey);
this.authenticationProvider = new Wrap(acsHost, issuer, accessKey);
}
}

Expand All @@ -100,7 +69,7 @@ ServiceBusServiceClient.prototype._buildRequestOptions = function (webResource,
}

webResource.addOptionalHeader(HeaderConstants.ACCEPT_CHARSET_HEADER, 'UTF-8');
webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this._getHostname() + ':' + this.port);
webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this.host + ':' + this.port);

// Sets the request url in the web resource.
this._setRequestUrl(webResource);
Expand All @@ -121,7 +90,7 @@ ServiceBusServiceClient.prototype._buildRequestOptions = function (webResource,
requestOptions = {
url: url.format({
protocol: self._isHttps() ? 'https:' : 'http:',
hostname: self._getHostname(),
hostname: self.host,
port: self.port,
pathname: webResource.path + webResource.getQueryString(true)
}),
Expand Down Expand Up @@ -152,13 +121,4 @@ ServiceBusServiceClient.prototype._getPath = function (path) {
}

return path;
};

/**
* Retrives the hostname.
*
* @return {string} The hostname.
*/
ServiceBusServiceClient.prototype._getHostname = function () {
return this.namespace + '.' + this.host;
};
79 changes: 57 additions & 22 deletions lib/services/core/servicebussettings.js
Expand Up @@ -26,77 +26,112 @@ var Validate = require('../../util/validate');
exports = module.exports = ServiceBusSettings;

var serviceBusEndpointSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME, Validate.getIsValidUri());
var wrapEndpointSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.WRAP_ENDPOINT_NAME, Validate.getIsValidUri());
var wrapNameSetting = ServiceSettings.setting(ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME);
var wrapPasswordSetting = ServiceSettings.setting(ConnectionStringKeys.SHARED_SECRET_VALUE_NAME);

var validKeys = [
ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME,
ConnectionStringKeys.WRAP_ENDPOINT_NAME,
ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME,
ConnectionStringKeys.SHARED_SECRET_VALUE_NAME
];

/**
* Creates new service bus settings instance.
*
* @param {string} serviceBusEndpoint The Service Bus endpoint uri.
* @param {string} namespace The service namespace.
* @param {string} wrapName The wrap name.
* @param {string} wrapPassword The wrap password.
* @param {string} serviceBusEndpointUri The Service Bus endpoint uri.
* @param {string} wrapEndpointUri The Service Bus endpoint uri.
* @param {string} namespace The service namespace.
* @param {string} wrapName The wrap name.
* @param {string} wrapPassword The wrap password.
*/
function ServiceBusSettings(serviceBusEndpointUri, namespace, wrapName, wrapPassword) {
function ServiceBusSettings(serviceBusEndpointUri, wrapEndpointUri, namespace, wrapName, wrapPassword) {
this._namespace = namespace;
this._serviceBusEndpointUri = serviceBusEndpointUri;
this._wrapEndpointUri = 'https://' + namespace + '-sb.accesscontrol.windows.net/WRAPv0.9';

if (wrapEndpointUri) {
this._wrapEndpointUri = wrapEndpointUri;
} else {
this._wrapEndpointUri = 'https://' + namespace + '-sb.accesscontrol.windows.net/WRAPv0.9';
}

this._wrapName = wrapName;
this._wrapPassword = wrapPassword;
}

/**
* Creates a ServiceBusSettings object from the given connection string.
* Creates a ServiceBusSettings object from a set of settings.
*
* @param {string} connectionString The storage settings connection string.
* @param {object} settings The settings object.
*
* @return {ServiceBusSettings}
*/
ServiceBusSettings.createFromConnectionString = function (connectionString) {
var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);

ServiceBusSettings.createFromSettings = function (settings) {
var matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
settings,
ServiceSettings.allRequired(
serviceBusEndpointSetting,
wrapNameSetting,
wrapPasswordSetting
)
_serviceBusEndpointSetting,
_wrapNameSetting,
_wrapPasswordSetting
),
ServiceSettings.optional(_wrapEndpointSetting)
);

if (matchedSpecs) {
var endpoint = util.tryGetValueInsensitive(
ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME,
tokenizedSettings
settings
);

var wrapEndpoint = util.tryGetValueInsensitive(
ConnectionStringKeys.WRAP_ENDPOINT_NAME,
settings
);

// Parse the namespace part from the URI
var parsedUrl = url.parse(endpoint);
var namespace = parsedUrl.host.split('.')[0];

var issuerName = util.tryGetValueInsensitive(
ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME,
tokenizedSettings
ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME,
settings
);

var issuerValue = util.tryGetValueInsensitive(
ConnectionStringKeys.SHARED_SECRET_VALUE_NAME,
tokenizedSettings
ConnectionStringKeys.SHARED_SECRET_VALUE_NAME,
settings
);

return new ServiceBusSettings(
endpoint,
wrapEndpoint,
namespace,
issuerName,
issuerValue
);
}

ServiceSettings.noMatch(connectionString);
ServiceSettings.noMatchSettings(settings);
};

/**
* Creates a ServiceBusSettings object from the given connection string.
*
* @param {string} connectionString The storage settings connection string.
*
* @return {ServiceBusSettings}
*/
ServiceBusSettings.createFromConnectionString = function (connectionString) {
var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
try {
return ServiceBusSettings.createFromSettings(tokenizedSettings);
} catch (e) {
if (e instanceof ServiceSettings.NoMatchError) {
// Replace no match settings exception by no match connection string one.
ServiceSettings.noMatchConnectionString(connectionString);
} else {
throw e;
}
}
};
23 changes: 6 additions & 17 deletions lib/services/core/serviceclient.js
Expand Up @@ -106,14 +106,13 @@ function ServiceClient(host, authenticationProvider) {
this._initDefaultFilter();

if (host) {
var parsedHost = this._parseHost(host);
var parsedHost = ServiceClient._parseHost(host);
this.host = parsedHost.hostname;
this.port = parsedHost.port;
if (!this.protocol) {
this.protocol = parsedHost.protocol + '//';
}
}
else if (!this.protocol) {
} else if (!this.protocol) {
this.protocol = ServiceClient.DEFAULT_PROTOCOL;
}

Expand Down Expand Up @@ -380,7 +379,7 @@ ServiceClient.prototype._setRequestOptionsProxy = function (requestOptions) {
* @param {string} host The full host to be parsed.
* @return {object} THe parsed host as returned by the method "url.parse".
*/
ServiceClient.prototype._parseHost = function (host) {
ServiceClient._parseHost = function (host) {
var fullHost = host;
if (fullHost.indexOf(Constants.HTTP) === -1) {
fullHost = ServiceClient.DEFAULT_PROTOCOL + fullHost;
Expand Down Expand Up @@ -515,7 +514,7 @@ ServiceClient.prototype._setRequestUrl = function (webResource) {
var queryString = webResource.getQueryString(true);

// Build the full request url
webResource.requestUrl = this.protocol + this._getHostname() + ":" + this.port + webResource.path + queryString;
webResource.requestUrl = this.protocol + this.host + ":" + this.port + webResource.path + queryString;
};

/**
Expand Down Expand Up @@ -564,24 +563,14 @@ ServiceClient.prototype.parseMetadataHeaders = function (headers) {
};

/**
* Determines if the service client is running on an emulated environment.
* This will be considered to be the case if the used url matches the address for the devstore
* (See DEVSTORE_BLOB_HOST, DEVSTORE_TABLE_HOST and DEVSTORE_QUEUE_HOST) or if the environment variable
* "EMULATED" is set.
* Gets the value of the environment variable for is emulated.
*
* @param {string} host The used host.
* @return {bool} True if the service client is running on an emulated environment; false otherwise.
*/
ServiceClient.isEmulated = function (host) {
if (host === ServiceClient.DEVSTORE_BLOB_HOST ||
host === ServiceClient.DEVSTORE_TABLE_HOST ||
host === ServiceClient.DEVSTORE_QUEUE_HOST) {

return true;
}

return (!azureutil.objectIsNull(process.env[ServiceClient.EnvironmentVariables.EMULATED]) &&
process.env[ServiceClient.EnvironmentVariables.EMULATED] !== 'false');
process.env[ServiceClient.EnvironmentVariables.EMULATED] !== 'false');
};

// Other functions
Expand Down
12 changes: 2 additions & 10 deletions lib/services/core/servicemanagementclient.js
Expand Up @@ -190,7 +190,7 @@ ServiceManagementClient.prototype._buildRequestOptions = function(webResource, o
var requestOptions = {
url: url.format({
protocol: self._isHttps() ? 'https' : 'http',
hostname: self._getHostname(),
hostname: self.host,
port: self.port,
pathname: webResource.path + webResource.getQueryString(true)
}),
Expand Down Expand Up @@ -302,12 +302,4 @@ ServiceManagementClient.prototype._setAgent = function(self, reqopts, isHTTPS) {
} else if (isHTTPS) {
reqopts.agent = new https.Agent(reqopts);
}
};

/**
* Get service host name
*/
ServiceManagementClient.prototype._getHostname = function () {
return this.host;
};

};

0 comments on commit a499fbe

Please sign in to comment.