mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-08 03:44:13 +00:00
Move auth to resin module
This commit is contained in:
parent
64cb1520f6
commit
ff07764b39
@ -1,6 +1,6 @@
|
||||
open = require('open')
|
||||
async = require('async')
|
||||
auth = require('../auth/auth')
|
||||
resin = require('../resin')
|
||||
authHooks = require('../hooks/auth')
|
||||
widgets = require('../widgets/widgets')
|
||||
config = require('../config')
|
||||
@ -10,17 +10,17 @@ exports.login = (credentials) ->
|
||||
|
||||
(callback) ->
|
||||
if credentials?
|
||||
return auth.parseCredentials(credentials, callback)
|
||||
return resin.auth.parseCredentials(credentials, callback)
|
||||
else
|
||||
return widgets.login(callback)
|
||||
|
||||
(credentials, callback) ->
|
||||
auth.login(credentials, callback)
|
||||
resin.auth.login(credentials, callback)
|
||||
|
||||
], resin.errors.handle
|
||||
|
||||
exports.logout = authHooks.failIfNotLoggedIn ->
|
||||
auth.logout()
|
||||
resin.auth.logout()
|
||||
|
||||
exports.signup = ->
|
||||
open(config.urls.signup)
|
||||
|
@ -1,11 +1,11 @@
|
||||
_ = require('lodash')
|
||||
auth = require('../auth/auth')
|
||||
resin = require('../resin')
|
||||
messages = require('../messages/messages')
|
||||
|
||||
exports.failIfNotLoggedIn = (fn, onError) ->
|
||||
return ->
|
||||
args = arguments
|
||||
auth.isLoggedIn (isLoggedIn) ->
|
||||
resin.auth.isLoggedIn (isLoggedIn) ->
|
||||
|
||||
if not isLoggedIn
|
||||
error = new Error(messages.errors.loginRequired)
|
||||
|
@ -3,7 +3,6 @@ nock = require('nock')
|
||||
sinon = require('sinon')
|
||||
expect = require('chai').expect
|
||||
config = require('../config')
|
||||
auth = require('../auth/auth')
|
||||
resin = require('../resin')
|
||||
authHooks = require('./auth')
|
||||
johnDoeFixture = require('../../tests/fixtures/johndoe')
|
||||
@ -29,7 +28,7 @@ describe 'Auth Hooks:', ->
|
||||
describe 'if not logged in', ->
|
||||
|
||||
beforeEach (done) ->
|
||||
auth.logout(done)
|
||||
resin.auth.logout(done)
|
||||
|
||||
it 'should not call the function', (done) ->
|
||||
spy = sinon.spy()
|
||||
@ -63,7 +62,7 @@ describe 'Auth Hooks:', ->
|
||||
.post('/login_', johnDoeFixture.credentials)
|
||||
.reply(200, johnDoeFixture.token)
|
||||
|
||||
auth.login(johnDoeFixture.credentials, done)
|
||||
resin.auth.login(johnDoeFixture.credentials, done)
|
||||
|
||||
it 'should call the function with the correct arguments', (done) ->
|
||||
args = [ 1, 2, 3, 'foo', 'bar' ]
|
||||
|
@ -1,10 +1,11 @@
|
||||
async = require('async')
|
||||
_ = require('lodash')
|
||||
|
||||
resin = require('../resin')
|
||||
token = require('../token/token')
|
||||
server = require('../server/server')
|
||||
|
||||
exports.authenticate = (credentials, callback) ->
|
||||
resin.server.post '/login_', credentials, (error, response) ->
|
||||
server.post '/login_', credentials, (error, response) ->
|
||||
return callback(error, response?.body)
|
||||
|
||||
exports.login = (credentials, callback) ->
|
||||
@ -14,17 +15,17 @@ exports.login = (credentials, callback) ->
|
||||
exports.authenticate(credentials, callback)
|
||||
|
||||
(authToken, callback) ->
|
||||
resin.token.saveToken(authToken, callback)
|
||||
token.saveToken(authToken, callback)
|
||||
|
||||
], callback)
|
||||
|
||||
# Handy aliases
|
||||
exports.isLoggedIn = resin.token.hasToken
|
||||
exports.getToken = resin.token.getToken
|
||||
exports.isLoggedIn = token.hasToken
|
||||
exports.getToken = token.getToken
|
||||
|
||||
# TODO: Maybe we should post to /logout or something
|
||||
# like that to invalidate the token on the server?
|
||||
exports.logout = resin.token.clearToken
|
||||
exports.logout = token.clearToken
|
||||
|
||||
exports.parseCredentials = (credentials, callback) ->
|
||||
result = credentials.split(':')
|
@ -3,11 +3,11 @@ nock = require('nock')
|
||||
_ = require('lodash')
|
||||
async = require('async')
|
||||
auth = require('./auth')
|
||||
resin = require('../resin')
|
||||
config = require('../config')
|
||||
mock = require('../../tests/utils/mock')
|
||||
johnDoeFixture = require('../../tests/fixtures/johndoe')
|
||||
janeDoeFixture = require('../../tests/fixtures/janedoe')
|
||||
data = require('../data/data')
|
||||
config = require('../../config')
|
||||
mock = require('../../../tests/utils/mock')
|
||||
johnDoeFixture = require('../../../tests/fixtures/johndoe')
|
||||
janeDoeFixture = require('../../../tests/fixtures/janedoe')
|
||||
|
||||
describe 'Auth:', ->
|
||||
|
||||
@ -19,7 +19,7 @@ describe 'Auth:', ->
|
||||
|
||||
beforeEach (done) ->
|
||||
mock.fs.init()
|
||||
resin.data.prefix.set(config.dataPrefix, done)
|
||||
data.prefix.set(config.dataPrefix, done)
|
||||
|
||||
afterEach ->
|
||||
mock.fs.restore()
|
@ -5,3 +5,4 @@ module.exports =
|
||||
errors: require('./errors/errors')
|
||||
token: require('./token/token')
|
||||
data: require('./data/data')
|
||||
auth: require('./auth/auth')
|
||||
|
Loading…
x
Reference in New Issue
Block a user