Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/apiKey
- Loading branch information
Showing
7 changed files
with
122 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var modulus = require('../modulus'), | ||
userConfig = require('../common/api').userConfig, | ||
util = require('util') | ||
url = require('url'); | ||
|
||
const invalid = ['username', 'userId', 'apiKey']; | ||
|
||
exports.get = function list(name, cb) { | ||
userConfig.load(); | ||
|
||
if (!userConfig.data.hasOwnProperty(name)) { | ||
return cb('Configuration name not found.'); | ||
} | ||
|
||
modulus.io.print(util.format('%s: %s', name, userConfig.data[name]).input); | ||
|
||
return cb(); | ||
}; | ||
|
||
exports.set = function set(name, value, cb) { | ||
if (invalid.indexOf(name.toLowerCase()) >= 0) { | ||
// | ||
// Don't allow username, userId, or apiKey to be set by the user. | ||
// | ||
return cb(util.format('Cannot set value of \'%s\'', name)); | ||
} | ||
|
||
userConfig.load(); | ||
|
||
if (!userConfig.data) userConfig.data = {}; | ||
|
||
try { | ||
// | ||
// Attempt to parse the value the JSON. This will ensure that Booleans are | ||
// correctly stored as JSON rather than a string. | ||
// | ||
userConfig.data[name] = JSON.parse(value); | ||
} catch (e) { | ||
userConfig.data[name] = value; | ||
} | ||
|
||
userConfig.save(userConfig.data); | ||
modulus.io.print(util.format('Saved \'%s\' to \'%s\'', value, name).input); | ||
|
||
return cb(); | ||
}; |
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,7 +1,23 @@ | ||
var librarian = require('../librarian/librarian').init('api.onmodulus.net', 443, true), | ||
UserConfig = require('./userConfig'); | ||
var UserConfig = require('./userConfig'), | ||
url = require('url'), | ||
librarian = require('../librarian/librarian'), | ||
userConfig = new UserConfig(); | ||
|
||
userConfig.load(); | ||
|
||
if (userConfig.data && userConfig.data.api_uri) { | ||
var url = url.parse(userConfig.data.api_uri); | ||
|
||
if (url.protocol === 'https:') { | ||
librarian.init(url.hostname, url.port || 443, true); | ||
} else { | ||
librarian.init(url.hostname, url.port || 80, false); | ||
} | ||
} else { | ||
librarian.init('api.onmodulus.net', 443, true); | ||
} | ||
|
||
module.exports = { | ||
librarian : librarian, | ||
userConfig : new UserConfig() | ||
}; | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = function(modulus) { | ||
var help = new modulus.help('Configuration', modulus); | ||
|
||
help.add('get', function() { | ||
this.line('config get <name>'.verbose); | ||
this.line('Get a configuration value.'.input); | ||
}); | ||
|
||
modulus.program | ||
.command('config get', '<name>') | ||
.description('Get a configuration value.') | ||
.on('--help', help.commands.get) | ||
.action(function(name) { | ||
modulus.runCommand(modulus.commands.config.get, [name], false); | ||
}); | ||
|
||
help.add('set', function() { | ||
this.line('config set <name> <value>'.verbose); | ||
this.line('Set a configuration value.'.input); | ||
}); | ||
|
||
modulus.program | ||
.command('config set', '<name> <value>') | ||
.description('Set a configuration value.') | ||
.on('--help', help.commands.set) | ||
.action(function(name, value) { | ||
modulus.runCommand(modulus.commands.config.set, [name, value], false); | ||
}); | ||
|
||
return { base: 'config', help: help }; | ||
}; |
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