| 11 | const TokensListCommand = require('./list.js'); |
| 12 | |
| 13 | class TokensCommand extends Command { |
| 14 | |
| 15 | constructor() { |
| 16 | super('tokens'); |
| 17 | } |
| 18 | |
| 19 | help() { |
| 20 | return { |
| 21 | description: 'Selects an active Identity Token for API Authentication', |
| 22 | }; |
| 23 | } |
| 24 | |
| 25 | run(params, callback) { |
| 26 | |
| 27 | let activeToken = config.get('ACTIVE_LIBRARY_TOKEN'); |
| 28 | |
| 29 | let host = params.flags.h ? params.flags.h[0] : 'https://api.autocode.com'; |
| 30 | let port = params.flags.p && params.flags.p[0]; |
| 31 | |
| 32 | let resource = new APIResource(host, port); |
| 33 | |
| 34 | resource.authorize(config.get('ACCESS_TOKEN')); |
| 35 | resource.request('/v1/library_tokens').index({}, async (err, response) => { |
| 36 | |
| 37 | if (err) { |
| 38 | return callback(err); |
| 39 | } |
| 40 | |
| 41 | let tokens = (response && response.data) || []; |
| 42 | |
| 43 | if (!tokens.length) { |
| 44 | console.log(); |
| 45 | console.log(chalk.bold.red('Oops!')); |
| 46 | console.log(); |
| 47 | console.log(`It doesn't look like you have any Identity Tokens.`); |
| 48 | console.log(`This usually means you've removed them.`); |
| 49 | console.log(); |
| 50 | console.log(`Try typing `); |
| 51 | console.log(`\t${chalk.bold('lib tokens:create')}`); |
| 52 | console.log(); |
| 53 | console.log(`To create a new Identity Token.`); |
| 54 | console.log(); |
| 55 | return callback(new Error('No Identity Tokens.')); |
| 56 | } |
| 57 | |
| 58 | console.log(); |
| 59 | console.log(`Here's a list of your available ${chalk.bold('Identity Tokens')}.`); |
| 60 | console.log(`These are your API keys that provide authentication and access to functions.`); |
| 61 | console.log(); |
| 62 | console.log(`Here you can change your active authentication token, simply choose from the list.`); |
| 63 | console.log(); |
| 64 | |
| 65 | let answers = await inquirer.prompt( |
| 66 | [ |
| 67 | { |
| 68 | name: 'libraryToken', |
| 69 | type: 'list', |
| 70 | pageSize: 100, |
nothing calls this directly
no outgoing calls
no test coverage detected