diff --git a/doc/cli.markdown b/doc/cli.markdown index c5ac9978..a0ef074a 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -262,7 +262,7 @@ from the dashboard. - Credentials: using email/password and 2FA. -- Token: using the authentication token from the preferences page. +- Token: using a session token or API key (experimental) from the preferences page. Examples: @@ -276,7 +276,7 @@ Examples: #### --token, -t <token> -auth token +session token or API key (experimental) #### --web, -w diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index a2460492..69529b35 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -27,7 +27,7 @@ exports.login = - Credentials: using email/password and 2FA. - - Token: using the authentication token from the preferences page. + - Token: using a session token or API key (experimental) from the preferences page. Examples: @@ -40,7 +40,7 @@ exports.login = options: [ { signature: 'token' - description: 'auth token' + description: 'session token or API key (experimental)' parameter: 'token' alias: 't' } @@ -73,7 +73,7 @@ exports.login = action: (params, options, done) -> _ = require('lodash') Promise = require('bluebird') - resin = require('resin-sdk-preconfigured') + resin = require('resin-sdk').fromSharedOptions() auth = require('../auth') form = require('resin-cli-form') patterns = require('../utils/patterns') @@ -84,7 +84,7 @@ exports.login = return Promise.try -> return options.token if _.isString(options.token) return form.ask - message: 'Token (from the preferences page)' + message: 'Session token or API key (experimental) from the preferences page' name: 'token' type: 'input' .then(resin.auth.loginWithToken) @@ -188,7 +188,7 @@ exports.whoami = permission: 'user' action: (params, options, done) -> Promise = require('bluebird') - resin = require('resin-sdk-preconfigured') + resin = require('resin-sdk').fromSharedOptions() visuals = require('resin-cli-visuals') Promise.props diff --git a/lib/app.coffee b/lib/app.coffee index 2ceb6421..4faf13d7 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -62,14 +62,15 @@ capitanoExecuteAsync = Promise.promisify(capitano.execute) # We don't yet use resin-sdk directly everywhere, but we set up shared # options correctly so we can do safely in submodules -require('resin-sdk').setSharedOptions( +ResinSdk = require('resin-sdk') +ResinSdk.setSharedOptions( apiUrl: settings.get('apiUrl') imageMakerUrl: settings.get('imageMakerUrl') dataDirectory: settings.get('dataDirectory') retries: 2 ) -# Keep using sdk-preconfigured for now, but only temporarily -resin = require('resin-sdk-preconfigured') + +resin = ResinSdk.fromSharedOptions() actions = require('./actions') errors = require('./errors') diff --git a/lib/auth/utils.coffee b/lib/auth/utils.coffee index 6dbb69c6..d3756a72 100644 --- a/lib/auth/utils.coffee +++ b/lib/auth/utils.coffee @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ### -resin = require('resin-sdk-preconfigured') +resin = require('resin-sdk').fromSharedOptions() _ = require('lodash') url = require('url') Promise = require('bluebird') @@ -62,7 +62,9 @@ exports.isTokenValid = (sessionToken) -> if not sessionToken? or _.isEmpty(sessionToken.trim()) return Promise.resolve(false) - return resin.token.get().then (currentToken) -> + return resin.auth.getToken() + .catchReturn(undefined) + .then (currentToken) -> resin.auth.loginWithToken(sessionToken) .return(sessionToken) .then(resin.auth.isLoggedIn)