Permalink
Browse files

Removing duplicate code

  • Loading branch information...
1 parent 6932775 commit df5b1307baf46e6701621cec7e301303689833e8 Andre Rodrigues committed Oct 12, 2012
@@ -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');
@@ -36,8 +37,6 @@ var QueryStringConstants = Constants.QueryStringConstants;
var BlobConstants = Constants.BlobConstants;
var HttpConstants = Constants.HttpConstants;
-var StorageServiceSettings = require('../core/storageservicesettings');
-
// Models requires
var ServicePropertiesResult = require('./models/servicepropertiesresult');
var ContainerAclResult = require('./models/containeraclresult');
@@ -78,25 +77,7 @@ BlobService.incorrectEndByteOffsetErr = 'End byte offset must be a modulus of 51
* @param {object} [authenticationProvider] The authentication provider.
*/
function BlobService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
- var storageServiceSettings;
- if (storageAccountOrConnectionString && !storageAccessKey) {
- // If namespaceOrConnectionString was passed and no accessKey was passed, assume connection string
- storageServiceSettings = StorageServiceSettings.createFromConnectionString(storageAccountOrConnectionString);
- } else {
- if (!(storageAccountOrConnectionString && storageAccessKey) && ServiceClient.isEmulated()) {
- host = ServiceClient.DEVSTORE_BLOB_HOST;
- } else {
- host = ServiceClient.CLOUD_BLOB_HOST;
- }
-
- var settings = {
- accountname: storageAccountOrConnectionString,
- accountkey: storageAccessKey,
- blobendpoint: host
- };
-
- storageServiceSettings = StorageServiceSettings.createFromSettings(settings);
- }
+ var storageServiceSettings = StorageServiceClient.getStorageSettings(storageAccountOrConnectionString, storageAccessKey, host);
BlobService.super_.call(this,
storageServiceSettings._name,
@@ -23,6 +23,8 @@ var xml2js = require('xml2js');
var azureutil = require('../../util/util');
+var StorageServiceSettings = require('../core/storageservicesettings');
+
var ServiceClient = require('./serviceclient');
var Constants = require('../../util/constants');
var HeaderConstants = Constants.HeaderConstants;
@@ -59,6 +61,50 @@ function StorageServiceClient(storageAccount, storageAccessKey, host, authentica
util.inherits(StorageServiceClient, ServiceClient);
/**
+* Gets the storage settings.
+*
+* @param {string} [storageAccountOrConnectionString] The storage account or the connection string.
+* @param {string} [storageAccessKey] The storage access key.
+* @param {string} [host] The host address.
+*
+* @return {StorageServiceSettings}
+*/
+StorageServiceClient.getStorageSettings = function (storageAccountOrConnectionString, storageAccessKey, host) {
+ var storageServiceSettings;
+ if (storageAccountOrConnectionString && !storageAccessKey) {
+ // If storageAccountOrConnectionString was passed and no accessKey was passed, assume connection string
+ storageServiceSettings = StorageServiceSettings.createFromConnectionString(storageAccountOrConnectionString);
+ } else {
+ if (!(storageAccountOrConnectionString && storageAccessKey) && ServiceClient.isEmulated()) {
+ // Dev storage scenario
+ storageServiceSettings = StorageServiceSettings.developmentStorageAccount();
+ } else {
+ // Explicit credentials scenario
+
+ if (!storageAccountOrConnectionString) {
+ storageAccountOrConnectionString = process.env[ServiceClient.EnvironmentVariables.AZURE_STORAGE_ACCOUNT];
+ }
+
+ if (!storageAccessKey) {
+ storageAccessKey = process.env[ServiceClient.EnvironmentVariables.AZURE_STORAGE_ACCESS_KEY];
+ }
+
+ var settings = {
+ accountname: storageAccountOrConnectionString,
+ accountkey: storageAccessKey,
+ blobendpoint: url.format({ protocol: 'https:', host: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_BLOB_HOST }),
+ tableendpoint: url.format({ protocol: 'https:', host: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_TABLE_HOST }),
+ queueendpoint: url.format({ protocol: 'https:', host: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_QUEUE_HOST })
+ };
+
+ storageServiceSettings = StorageServiceSettings.createFromSettings(settings);
+ }
+ }
+
+ return storageServiceSettings;
+};
+
+/**
* Builds the request options to be passed to the http.request method.
*
* @param {WebResource} webResource The webresource where to build the options from.
@@ -15,6 +15,7 @@
// Module dependencies.
var util = require('util');
+var url = require('url');
var azureutil = require('../../util/util');
@@ -27,8 +28,6 @@ var QueryStringConstants = Constants.QueryStringConstants;
var HttpConstants = Constants.HttpConstants;
var HeaderConstants = Constants.HeaderConstants;
-var StorageServiceSettings = require('../core/storageservicesettings');
-
// Models requires
var ListQueuesResultContinuation = require('./models/listqueuesresultcontinuation');
var QueueResult = require('./models/queueresult');
@@ -52,25 +51,7 @@ exports = module.exports = QueueService;
* @param {object} [authenticationProvider] The authentication provider.
*/
function QueueService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
- var storageServiceSettings;
- if (storageAccountOrConnectionString && !storageAccessKey) {
- // If namespaceOrConnectionString was passed and no accessKey was passed, assume connection string
- storageServiceSettings = StorageServiceSettings.createFromConnectionString(storageAccountOrConnectionString);
- } else {
- if (!(storageAccountOrConnectionString && storageAccessKey) && ServiceClient.isEmulated()) {
- host = ServiceClient.DEVSTORE_QUEUE_HOST;
- } else {
- host = ServiceClient.CLOUD_QUEUE_HOST;
- }
-
- var settings = {
- accountname: storageAccountOrConnectionString,
- accountkey: storageAccessKey,
- queueendpoint: host
- };
-
- storageServiceSettings = StorageServiceSettings.createFromSettings(settings);
- }
+ var storageServiceSettings = StorageServiceClient.getStorageSettings(storageAccountOrConnectionString, storageAccessKey, host);
QueueService.super_.call(this,
storageServiceSettings._name,
@@ -15,6 +15,7 @@
// Module dependencies.
var util = require('util');
+var url = require('url');
var xmlbuilder = require('xmlbuilder');
var azureutil = require('../../util/util');
@@ -31,8 +32,6 @@ var HeaderConstants = Constants.HeaderConstants;
var TableConstants = Constants.TableConstants;
var HttpConstants = Constants.HttpConstants;
-var StorageServiceSettings = require('../core/storageservicesettings');
-
// Models requires
var TableResult = require('./models/tableresult');
var EntityResult = require('./models/entityresult');
@@ -62,25 +61,7 @@ TableService.incorrectPartitionErr = 'PartitionKey and RowKey must be specified
* @param {object} [authenticationProvider] The authentication provider.
*/
function TableService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
- var storageServiceSettings;
- if (storageAccountOrConnectionString && !storageAccessKey) {
- // If namespaceOrConnectionString was passed and no accessKey was passed, assume connection string
- storageServiceSettings = StorageServiceSettings.createFromConnectionString(storageAccountOrConnectionString);
- } else {
- if (!(storageAccountOrConnectionString && storageAccessKey) && ServiceClient.isEmulated()) {
- host = ServiceClient.DEVSTORE_TABLE_HOST;
- } else {
- host = ServiceClient.CLOUD_TABLE_HOST;
- }
-
- var settings = {
- accountname: storageAccountOrConnectionString,
- accountkey: storageAccessKey,
- tableendpoint: host
- };
-
- storageServiceSettings = StorageServiceSettings.createFromSettings(settings);
- }
+ var storageServiceSettings = StorageServiceClient.getStorageSettings(storageAccountOrConnectionString, storageAccessKey, host);
TableService.super_.call(this,
storageServiceSettings._name,

0 comments on commit df5b130

Please sign in to comment.