Skip to content

Commit

Permalink
Merge pull request #431 from nodejitsu/fix-api-token-name
Browse files Browse the repository at this point in the history
Allow env variables
  • Loading branch information
3rd-Eden committed Apr 4, 2013
2 parents b979b01 + f8683e4 commit a137322
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,4 @@
node_modules/
npm-debug.log
test/fixtures/test-jitsuconf
.idea
.idea
2 changes: 1 addition & 1 deletion bin/jitsu
Expand Up @@ -10,4 +10,4 @@ jitsu.start(function (err) {
}

process.exit(err ? 1 : 0);
});
});
10 changes: 5 additions & 5 deletions lib/jitsu/commands.js
Expand Up @@ -26,11 +26,11 @@ jitsu.use(require('flatiron-cli-users'), {
// Retrieve a token and remove the password with it
//
if (details && details.username) {
jitsu.tokens.create(details.username, (jitsu.config.get('api-token-name')||'jitsu'), function(err, result) {
jitsu.tokens.create(details.username, (jitsu.config.get('apiTokenName')||'jitsu'), function(err, result) {
if(!err && result) {
var token = Object.getOwnPropertyNames(result).filter(function(n){return n !== 'operation'}).pop();
jitsu.config.set('api-token', result[token]);
jitsu.config.set('api-token-name', token);
jitsu.config.set('apiToken', result[token]);
jitsu.config.set('apiTokenName', token);
jitsu.config.clear('password');
jitsu.config.save();
return next();
Expand All @@ -39,9 +39,9 @@ jitsu.use(require('flatiron-cli-users'), {
}
},
logout: function(details, next){
jitsu.config.clear('api-token');
jitsu.config.clear('apiToken');
jitsu.config.save();
return next();
}
}
});
});
2 changes: 1 addition & 1 deletion lib/jitsu/commands/package.js
Expand Up @@ -52,4 +52,4 @@ package.create.usage = [
'Creates a tarball in the `tmproot` directory for app in the current directory',
'',
'jitsu package create'
];
];
14 changes: 7 additions & 7 deletions lib/jitsu/commands/users.js
Expand Up @@ -73,11 +73,11 @@ users.confirm = function (username, inviteCode, callback) {
return setupAuth();
}
// once password is entered checkout a token and clear out password
jitsu.tokens.create(username, (jitsu.config.get('api-token-name')||'jitsu'), function(err, result) {
jitsu.tokens.create(username, (jitsu.config.get('apiTokenName')||'jitsu'), function(err, result) {
if(!err && result) {
var token = Object.getOwnPropertyNames(result).filter(function(n){return n !== 'operation'}).pop();
jitsu.config.set('api-token', result[token]);
jitsu.config.set('api-token-name', token);
jitsu.config.set('apiToken', result[token]);
jitsu.config.set('apiTokenName', token);
jitsu.config.clear('password');
jitsu.config.save(function (err) {
return err ? callback(err) : callback();
Expand Down Expand Up @@ -131,11 +131,11 @@ users.confirm = function (username, inviteCode, callback) {
jitsu.config.set('username', username);
jitsu.config.set('password', results['set password']);
// now that we have a new password lets checkout a new api token and clear out the password
jitsu.tokens.create(username, (jitsu.config.get('api-token-name')||'jitsu'), function(err, result) {
jitsu.tokens.create(username, (jitsu.config.get('apiTokenName')||'jitsu'), function(err, result) {
if(!err && result) {
var token = Object.getOwnPropertyNames(result).filter(function(n){return n !== 'operation'}).pop();
jitsu.config.set('api-token', result[token]);
jitsu.config.set('api-token-name', token);
jitsu.config.set('apiToken', result[token]);
jitsu.config.set('apiTokenName', token);
jitsu.config.clear('password');
jitsu.config.save(function (err) {
return err ? callback(err) : callback(null, res);
Expand Down Expand Up @@ -188,4 +188,4 @@ users.confirm.usage = [
'Will prompt for a valid invite code for the account',
'',
'jitsu users confirm <username> <invitecode>'
];
];
26 changes: 13 additions & 13 deletions lib/jitsu/config.js
Expand Up @@ -26,11 +26,11 @@ if (process.platform == "win32") {
// Setup target file for `.jitsuconf`.
//
//
// TODO: Refactor broadway to emit `bootstrap:after` and put this
// TODO: Refactor broadway to emit `bootstrap:after` and put this
// code in a handler for that event
//
try {
jitsu.config.file({
jitsu.config.env().file({
file: jitsu.argv.jitsuconf || jitsu.argv.j || '.jitsuconf',
dir: process.env.HOME,
search: true
Expand All @@ -49,7 +49,7 @@ catch (err) {

var defaults = {
analyze: true,
"api-token-name": 'jitsu',
"apiTokenName": 'jitsu',
release: 'build',
colors: true,
loglevel: 'info',
Expand Down Expand Up @@ -85,10 +85,10 @@ jitsu.config.defaults(defaults);
jitsu.use(require('flatiron-cli-config'), {
store: 'file',
restricted: [
'auth',
'root',
'remoteUri',
'tmproot',
'auth',
'root',
'remoteUri',
'tmproot',
'userconfig'
],
before: {
Expand Down Expand Up @@ -130,24 +130,24 @@ jitsu.config.load = function (callback) {
}

jitsu.config.set('userconfig', jitsu.config.stores.file.file);

if (store.auth) {
var auth = store.auth.split(':');
jitsu.config.clear('auth');
jitsu.config.set('username', auth[0]);
jitsu.config.set('password', auth[1]);
// create a new token and remove password from being saved to .jitsuconf
jitsu.tokens.create(auth[0], (jitsu.config.get('api-token-name')||'jitsu'), function(err, result) {
jitsu.tokens.create(auth[0], (jitsu.config.get('apiTokenName')||'jitsu'), function(err, result) {
if(!err && result) {
var token = Object.getOwnPropertyNames(result).filter(function(n){return n !== 'operation'}).pop();
jitsu.config.set('api-token', result[token]);
jitsu.config.set('api-token-name', token);
jitsu.config.set('apiToken', result[token]);
jitsu.config.set('apiTokenName', token);
jitsu.config.clear('password');
return jitsu.config.save(callback);
}
});


}

callback(null, store);
Expand Down
2 changes: 1 addition & 1 deletion lib/jitsu/usage.js
Expand Up @@ -57,4 +57,4 @@ module.exports = [
' jitsu snapshots',
' jitsu tokens',
' jitsu logout'
];
];
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -30,7 +30,7 @@
"fstream-npm": "0.1.4",
"ladder": "0.0.0",
"npm": "1.2.15",
"nodejitsu-api": "0.4.5",
"nodejitsu-api": "0.4.6",
"opener": "1.3.x",
"pkginfo": "0.3.0",
"progress": "0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion test/commands/apps-test.js
Expand Up @@ -906,4 +906,4 @@ var suite = vows.describe('jitsu/commands/apps').addBatch({
// 'deploy joyent us-east-1'
// );

suite.export(module);
suite.export(module);
2 changes: 1 addition & 1 deletion test/commands/snapshots-test.js
Expand Up @@ -293,4 +293,4 @@ vows.describe('jitsu/commands/snapshots').addBatch({
process.chdir(mainDirectory);
assert.ok(!err);
})
}).export(module);
}).export(module);
2 changes: 1 addition & 1 deletion test/fixtures/dot-jitsuconf
Expand Up @@ -7,4 +7,4 @@
"gzipbin": "gzip",
"username": "tester",
"password": "EXAMPLE-PASSWORD"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/example-app/package.json
Expand Up @@ -8,4 +8,4 @@
"engines": {
"node": "0.6.x"
}
}
}
2 changes: 1 addition & 1 deletion test/fixtures/example-app/server.js
@@ -1,4 +1,4 @@

module.exports = {hi:console.log}

//console.log('FIXTURES/EXAMPLE-APP')
//console.log('FIXTURES/EXAMPLE-APP')
2 changes: 1 addition & 1 deletion test/fixtures/logged-out-jitsuconf
Expand Up @@ -5,4 +5,4 @@
"loglevel": "silly",
"tar": "tar",
"gzipbin": "gzip"
}
}
2 changes: 1 addition & 1 deletion test/lib/package-test.js
Expand Up @@ -224,4 +224,4 @@ var suite = vows.describe('jitsu/lib/package').addBatch({
}
});

suite.export(module);
suite.export(module);

0 comments on commit a137322

Please sign in to comment.