balena-cli/lib/resin/token/token.coffee

20 lines
465 B
CoffeeScript
Raw Normal View History

2014-11-26 16:56:52 +00:00
data = require('../data/data')
2014-11-14 18:28:58 +00:00
TOKEN_KEY = 'token'
exports.saveToken = (newToken, callback) ->
2014-11-14 18:28:58 +00:00
data.set(TOKEN_KEY, newToken, encoding: 'utf8', callback)
exports.hasToken = (callback) ->
2014-11-14 18:28:58 +00:00
data.has(TOKEN_KEY, callback)
exports.getToken = (callback) ->
2014-11-14 18:28:58 +00:00
data.get(TOKEN_KEY, encoding: 'utf8', callback)
exports.clearToken = (callback) ->
2014-11-14 18:28:58 +00:00
data.has TOKEN_KEY, (hasToken) ->
if hasToken
return data.remove(TOKEN_KEY, callback)
else
return callback?(null)