Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added clients creation logic with elastic settings (+ tests).
Added tables listing, creation and removal (automated tests will be in done next).
- Loading branch information
Showing
10 changed files
with
667 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
*.pid | ||
npm-debug.log | ||
node_modules | ||
.idea | ||
.idea | ||
hydepark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,69 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var utils = require('./lib/utils'); | ||
var Client = require('./lib/client').Client; | ||
|
||
var _defaultClientSetting = { | ||
timeout: 10000, | ||
metadata: 'no' | ||
}; | ||
|
||
// default client is created lazily on first get or set request | ||
var _defaultClient = null; | ||
|
||
// initializes default client using default settings and environment variable CLOUD_STORAGE_ACCOUNT | ||
function _initDefaultConnection() { | ||
if ('CLOUD_STORAGE_ACCOUNT' in process.env) { | ||
var accountSettings = utils.parseAccountString(process.env.CLOUD_STORAGE_ACCOUNT); | ||
if (accountSettings !== null) { | ||
_defaultClientSetting = _.defaults(_defaultClientSetting, accountSettings); | ||
} | ||
} | ||
} | ||
|
||
function getDefaultClient() { | ||
if (_defaultClient === null) { | ||
_defaultClient = Client.create(_defaultClientSetting); | ||
} | ||
return _defaultClient; | ||
} | ||
|
||
function setDefaultClient(settings) { | ||
_defaultClient = createClient(settings); | ||
return _defaultClient; | ||
} | ||
|
||
function createClient(settings, base) { | ||
var baseSettings; | ||
if (base) { | ||
baseSettings = base.getSettings(); | ||
} else if (_defaultClient !== null) { | ||
baseSettings = _defaultClient.getSettings(); | ||
} else { | ||
baseSettings = _defaultClientSetting; | ||
} | ||
|
||
var finalSettings = _.clone(baseSettings); | ||
if (settings) { | ||
finalSettings = _.merge(finalSettings, settings, function(a, b) { | ||
return _.isArray(a) ? a.concat(b) : undefined; | ||
}); | ||
} | ||
|
||
return Client.create(finalSettings); | ||
} | ||
|
||
|
||
var azureTable = { | ||
// () -> Client object | ||
getDefaultClient: getDefaultClient, | ||
// (options{object}) -> Client object | ||
setDefaultClient: setDefaultClient, | ||
// (options{object}, [base{object}]) -> Client object | ||
createClient: createClient | ||
}; | ||
|
||
_initDefaultConnection(); | ||
|
||
module.exports = azureTable; |
Oops, something went wrong.