mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-07 11:26:41 +00:00
Allow login with token
This commit is contained in:
parent
6e978d74dd
commit
77695bb505
@ -28,42 +28,18 @@
|
||||
};
|
||||
|
||||
exports.login = {
|
||||
signature: 'login',
|
||||
signature: 'login [token]',
|
||||
description: 'login to resin.io',
|
||||
help: 'Use this command to login to your resin.io account.\nYou need to login before you can use most of the commands this tool provides.\n\nYou can pass your credentials as `--username` and `--password` options, or you can omit the\ncredentials, in which case the tool will present you with an interactive login form.\n\nExamples:\n\n $ resin login --username <username> --password <password>\n $ resin login',
|
||||
options: [
|
||||
{
|
||||
signature: 'username',
|
||||
parameter: 'username',
|
||||
description: 'user name',
|
||||
alias: 'u'
|
||||
}, {
|
||||
signature: 'password',
|
||||
parameter: 'password',
|
||||
description: 'user password',
|
||||
alias: 'p'
|
||||
}
|
||||
],
|
||||
help: 'Use this command to login to your resin.io account.\n\nTo login, you need your token, which is accesible from the preferences page:\n\n https://dashboard.resin.io/preferences?tab=details\n\nExamples:\n\n $ resin login\n $ resin login "eyJ0eXAiOiJKV1Qi..."',
|
||||
action: function(params, options, done) {
|
||||
var hasOptionCredentials;
|
||||
hasOptionCredentials = !_.isEmpty(options);
|
||||
if (hasOptionCredentials) {
|
||||
if (!options.username) {
|
||||
return done(new Error('Missing username'));
|
||||
}
|
||||
if (!options.password) {
|
||||
return done(new Error('Missing password'));
|
||||
}
|
||||
}
|
||||
return async.waterfall([
|
||||
function(callback) {
|
||||
if (hasOptionCredentials) {
|
||||
return callback(null, options);
|
||||
} else {
|
||||
return visuals.widgets.login(callback);
|
||||
if (params.token != null) {
|
||||
return callback(null, params.token);
|
||||
}
|
||||
}, function(credentials, callback) {
|
||||
return resin.auth.login(credentials, callback);
|
||||
return visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback);
|
||||
}, function(token, callback) {
|
||||
return resin.auth.loginWithToken(token, done);
|
||||
}
|
||||
], done);
|
||||
}
|
||||
|
@ -22,58 +22,31 @@ exports.whoami =
|
||||
return done()
|
||||
|
||||
exports.login =
|
||||
signature: 'login'
|
||||
signature: 'login [token]'
|
||||
description: 'login to resin.io'
|
||||
help: '''
|
||||
Use this command to login to your resin.io account.
|
||||
You need to login before you can use most of the commands this tool provides.
|
||||
|
||||
You can pass your credentials as `--username` and `--password` options, or you can omit the
|
||||
credentials, in which case the tool will present you with an interactive login form.
|
||||
To login, you need your token, which is accesible from the preferences page:
|
||||
|
||||
https://dashboard.resin.io/preferences?tab=details
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin login --username <username> --password <password>
|
||||
$ resin login
|
||||
$ resin login "eyJ0eXAiOiJKV1Qi..."
|
||||
'''
|
||||
options: [
|
||||
{
|
||||
signature: 'username'
|
||||
parameter: 'username'
|
||||
description: 'user name'
|
||||
alias: 'u'
|
||||
}
|
||||
{
|
||||
signature: 'password'
|
||||
parameter: 'password'
|
||||
description: 'user password'
|
||||
alias: 'p'
|
||||
}
|
||||
]
|
||||
action: (params, options, done) ->
|
||||
|
||||
hasOptionCredentials = not _.isEmpty(options)
|
||||
|
||||
if hasOptionCredentials
|
||||
|
||||
if not options.username
|
||||
return done(new Error('Missing username'))
|
||||
|
||||
if not options.password
|
||||
return done(new Error('Missing password'))
|
||||
|
||||
async.waterfall [
|
||||
async.waterfall([
|
||||
|
||||
(callback) ->
|
||||
if hasOptionCredentials
|
||||
return callback(null, options)
|
||||
else
|
||||
return visuals.widgets.login(callback)
|
||||
return callback(null, params.token) if params.token?
|
||||
visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback)
|
||||
|
||||
(credentials, callback) ->
|
||||
resin.auth.login(credentials, callback)
|
||||
(token, callback) ->
|
||||
resin.auth.loginWithToken(token, done)
|
||||
|
||||
], done
|
||||
], done)
|
||||
|
||||
exports.logout =
|
||||
signature: 'logout'
|
||||
|
Loading…
x
Reference in New Issue
Block a user