Permalink
Browse files

Extracting function to make code easier to read.

  • Loading branch information...
1 parent fca3318 commit efaf2f0d7422a8f66d0e1d079dfa9e65b341dac9 Andre Rodrigues committed Oct 14, 2012
Showing with 60 additions and 44 deletions.
  1. +60 −44 lib/services/core/storageserviceclient.js
@@ -76,55 +76,71 @@ StorageServiceClient.getStorageSettings = function (storageAccountOrConnectionSt
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.getDevelopmentStorageAccountSettings();
} else {
- if (!(storageAccountOrConnectionString && storageAccessKey) && ServiceClient.isEmulated()) {
- // Dev storage scenario
- storageServiceSettings = StorageServiceSettings.getDevelopmentStorageAccountSettings();
- } else {
- // Explicit or environment credentials scenario
- var usePathStyleUri = false;
-
- if (!storageAccountOrConnectionString) {
- storageAccountOrConnectionString = process.env[ServiceClient.EnvironmentVariables.AZURE_STORAGE_ACCOUNT];
- }
-
- if (!storageAccessKey) {
- storageAccessKey = process.env[ServiceClient.EnvironmentVariables.AZURE_STORAGE_ACCESS_KEY];
- }
-
- // Default endpoints
- var blobendpoint = url.format({ protocol: 'http:', hostname: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_BLOB_HOST });
- var tableendpoint = url.format({ protocol: 'http:', hostname: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_TABLE_HOST });
- var queueendpoint = url.format({ protocol: 'http:', hostname: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_QUEUE_HOST });
-
- if (host) {
- var parsedHost = ServiceClient._parseHost(host);
-
- var parsedHostUrl = url.format(parsedHost);
- if (parsedHostUrl === url.format(ServiceClient._parseHost(ServiceClient.DEVSTORE_BLOB_HOST)) ||
- parsedHostUrl === url.format(ServiceClient._parseHost(ServiceClient.DEVSTORE_TABLE_HOST)) ||
- parsedHostUrl === url.format(ServiceClient._parseHost(ServiceClient.DEVSTORE_QUEUE_HOST))) {
- usePathStyleUri = true;
- }
-
- blobendpoint = url.format(parsedHostUrl);
- tableendpoint = url.format(parsedHostUrl);
- queueendpoint = url.format(parsedHostUrl);
- }
-
- var settings = {
- accountname: storageAccountOrConnectionString,
- accountkey: storageAccessKey,
- blobendpoint: blobendpoint,
- tableendpoint: tableendpoint,
- queueendpoint: queueendpoint
- };
+ // Explicit or environment variable credentials scenario
+ storageServiceSettings = StorageServiceSettings._getStorageSettingsExplicitOrEnvironment(
+ storageAccountOrConnectionString,
+ storageAccessKey,
+ host);
+ }
+
+ return storageServiceSettings;
+};
- storageServiceSettings = StorageServiceSettings.createFromSettings(settings);
- storageServiceSettings._usePathStyleUri = usePathStyleUri;
+/**
+* Gets the storage settings from the parameters or environment variables.
+*
+* @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._getStorageSettingsExplicitOrEnvironment = function (storageAccount, storageAccessKey, host) {
+ var usePathStyleUri = false;
+
+ if (!storageAccountOrConnectionString) {
+ storageAccountOrConnectionString = process.env[ServiceClient.EnvironmentVariables.AZURE_STORAGE_ACCOUNT];
+ }
+
+ if (!storageAccessKey) {
+ storageAccessKey = process.env[ServiceClient.EnvironmentVariables.AZURE_STORAGE_ACCESS_KEY];
+ }
+
+ // Default endpoints
+ var blobendpoint = url.format({ protocol: 'http:', hostname: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_BLOB_HOST });
+ var tableendpoint = url.format({ protocol: 'http:', hostname: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_TABLE_HOST });
+ var queueendpoint = url.format({ protocol: 'http:', hostname: storageAccountOrConnectionString + '.' + ServiceClient.CLOUD_QUEUE_HOST });
+
+ if (host) {
+ var parsedHost = ServiceClient._parseHost(host);
+
+ var parsedHostUrl = url.format(parsedHost);
+ if (parsedHostUrl === url.format(ServiceClient._parseHost(ServiceClient.DEVSTORE_BLOB_HOST)) ||
+ parsedHostUrl === url.format(ServiceClient._parseHost(ServiceClient.DEVSTORE_TABLE_HOST)) ||
+ parsedHostUrl === url.format(ServiceClient._parseHost(ServiceClient.DEVSTORE_QUEUE_HOST))) {
+ usePathStyleUri = true;
}
+
+ blobendpoint = url.format(parsedHostUrl);
+ tableendpoint = url.format(parsedHostUrl);
+ queueendpoint = url.format(parsedHostUrl);
}
+ var settings = {
+ accountname: storageAccountOrConnectionString,
+ accountkey: storageAccessKey,
+ blobendpoint: blobendpoint,
+ tableendpoint: tableendpoint,
+ queueendpoint: queueendpoint
+ };
+
+ var storageServiceSettings = StorageServiceSettings.createFromSettings(settings);
+ storageServiceSettings._usePathStyleUri = usePathStyleUri;
+
return storageServiceSettings;
};

0 comments on commit efaf2f0

Please sign in to comment.