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

Commit

Permalink
Merge pull request #5 from andrerod/storageconnect
Browse files Browse the repository at this point in the history
Storageconnect
  • Loading branch information
André Rodrigues committed Oct 10, 2012
2 parents 0967bcc + 1ecbcf5 commit 2fba11f
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 18 deletions.
6 changes: 4 additions & 2 deletions lib/services/core/serviceclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ function ServiceClient(host, authenticationProvider) {
var parsedHost = this._parseHost(host);
this.host = parsedHost.hostname;
this.port = parsedHost.port;
this.protocol = parsedHost.protocol + '//';
if (!this.protocol) {
this.protocol = parsedHost.protocol + '//';
}
}
else {
else if (!this.protocol) {
this.protocol = ServiceClient.DEFAULT_PROTOCOL;
}

Expand Down
23 changes: 23 additions & 0 deletions lib/services/core/storageserviceclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var xml2js = require('xml2js');

var azureutil = require('../../util/util');

var ConnectionStringParser = require('../core/connectionstringparser');

var ServiceClient = require('./serviceclient');
var Constants = require('../../util/constants');
var HeaderConstants = Constants.HeaderConstants;
Expand All @@ -49,6 +51,27 @@ StorageServiceClient.incorrectStorageAccessKeyErr = 'AccessKey must be a non emp
function StorageServiceClient(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
var storageAccount = storageAccountOrConnectionString;

if (storageAccountOrConnectionString && !storageAccessKey) {
// If namespaceOrConnectionString was passed and no accessKey was passed, assume connection string
var connectionString = ConnectionStringParser.parse(storageAccountOrConnectionString);
if (connectionString['accountname']) {
storageAccount = connectionString['accountname'];
}

if (connectionString['accountkey']) {
storageAccessKey = connectionString['accountkey'];
}

if (connectionString['defaultendpointsprotocol']) {
if (connectionString['defaultendpointsprotocol'] !== 'http' &&
connectionString['defaultendpointsprotocol'] !== 'https') {
throw new Error('Invalid protocol ' + connectionString['defaultendpointsprotocol']);
}

this.protocol = connectionString['defaultendpointsprotocol'] + '://';
}
}

this._setAccountCredentials(storageAccount, storageAccessKey);
this.apiVersion = HeaderConstants.TARGET_STORAGE_VERSION;
this.usePathStyleUri = ServiceClient.isEmulated(host);
Expand Down
20 changes: 8 additions & 12 deletions test/cli/commands/cli.account-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ var cli = require('../cli');
var capture = require('../util').capture;

suite('cli', function(){
suite('account', function() {

suite('import', function() {

test('should launch browser when there is no file name', function(done) {
suite('account', function() {
suite('import', function() {
test('should launch browser when there is no file name', function(done) {
capture(function() {
cli.parse('node cli.js account import data/account-credentials.publishsettings'.split(' '));
}, function (result) {

var result = capture(function() {
cli.parse('node cli.js account import'.split(' '));
});

done();
});

done();
});
});
});
});
Expand Down
34 changes: 34 additions & 0 deletions test/cli/commands/cli.site-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require('should');
var cli = require('../cli');
var capture = require('../util').capture;

suite('cli', function(){
suite('site', function() {
suite('list', function() {
test('should list no sites', function(done) {
capture(function() {
cli.parse('node cli.js site list --json'.split(' '));
}, function (result) {
done();
});
});
});
});
});


11 changes: 11 additions & 0 deletions test/cli/data/account-credentials.publishsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PublishData>
<PublishProfile
PublishMethod="AzureServiceManagementAPI"
Url="https://management.core.windows.net/"
ManagementCertificate="MIIKDAIBAzCCCcwGCSqGSIb3DQEHAaCCCb0Eggm5MIIJtTCCBe4GCSqGSIb3DQEHAaCCBd8EggXbMI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Kt/BBcQon1m+ZTHwBvpdsR/SQSS3lfAyJP1acZZ7T3pLXxM8wNzAfMAcGBSsOAwIaBBRg0ngTO/0B+dyUbleHraeCZ9toYgQUhTCQqY83eCb/LR5d4DShd5cfd98=">
<Subscription
Id="db1ab6f0-4769-4b27-930e-01e2ef9c123c"
Name="Account" />
</PublishProfile>
</PublishData>
8 changes: 4 additions & 4 deletions test/cli/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports = module.exports = {
capture: capture,
};

function capture(action) {
function capture(action, cb) {
var result = {
text: '',
}
Expand All @@ -26,11 +26,12 @@ function capture(action) {
var processExit = process.exit

process.stdout.write = function(data, encoding, fd) {
result.text = result.text + data;
result.text += data;
};
process.exit = function(status) {
result.exitStatus = status;
throw new Error('process exit');

return cb(result);
};

try {
Expand All @@ -41,5 +42,4 @@ function capture(action) {
}
process.stdout.write = processStdoutWrite;
process.exit = processExit;
return result;
}
13 changes: 13 additions & 0 deletions test/services/blob/blobservice-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var testPrefix = 'blobservice-tests';
var numberTests = 34;

suite('blobservice-tests', function () {
/*
setup(function (done) {
blobtestutil.setUpTest(testPrefix, function (err, newBlobService) {
blobService = newBlobService;
Expand Down Expand Up @@ -1272,6 +1273,18 @@ suite('blobservice-tests', function () {
});
});
});
*/
test('storageConnectionStrings', function (done) {
var connectionString = 'DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey';
var blobService = azure.createBlobService(connectionString);

assert.equal(blobService.storageAccount, 'myaccount');
assert.equal(blobService.storageAccessKey, 'mykey');
assert.equal(blobService.protocol, 'https://');
assert.equal(blobService.host, 'blob.core.windows.net');

done();
});
});

function repeat(s, n) {
Expand Down
11 changes: 11 additions & 0 deletions test/services/queue/queueservice-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,15 @@ suite('queueservice-tests', function () {
done();
});
});

test('storageConnectionStrings', function (done) {
var connectionString = 'DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey';
var queueService = azure.createQueueService(connectionString);

assert.equal(queueService.storageAccount, 'myaccount');
assert.equal(queueService.storageAccessKey, 'mykey');
assert.equal(queueService.protocol, 'https://');

done();
});
});
11 changes: 11 additions & 0 deletions test/services/table/tableservice-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,4 +766,15 @@ suite('tableservice-tests', function () {
});
});
});

test('storageConnectionStrings', function (done) {
var connectionString = 'DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey';
var tableService = azure.createTableService(connectionString);

assert.equal(tableService.storageAccount, 'myaccount');
assert.equal(tableService.storageAccessKey, 'mykey');
assert.equal(tableService.protocol, 'https://');

done();
});
});

0 comments on commit 2fba11f

Please sign in to comment.