| 69 | } |
| 70 | |
| 71 | async list () { |
| 72 | const json = this.npm.config.get('json') |
| 73 | const parseable = this.npm.config.get('parseable') |
| 74 | log.info('token', 'getting list') |
| 75 | const tokens = await paginate('/-/npm/v1/tokens', this.npm.flatOptions) |
| 76 | if (json) { |
| 77 | output.buffer(tokens) |
| 78 | return |
| 79 | } |
| 80 | if (parseable) { |
| 81 | output.standard(['key', 'token', 'created', 'readonly', 'CIDR whitelist'].join('\t')) |
| 82 | tokens.forEach(token => { |
| 83 | output.standard( |
| 84 | [ |
| 85 | token.key, |
| 86 | token.token, |
| 87 | token.created, |
| 88 | token.readonly ? 'true' : 'false', |
| 89 | token.cidr_whitelist ? token.cidr_whitelist.join(',') : '', |
| 90 | ].join('\t') |
| 91 | ) |
| 92 | }) |
| 93 | return |
| 94 | } |
| 95 | this.generateTokenIds(tokens, 6) |
| 96 | const chalk = this.npm.chalk |
| 97 | for (const token of tokens) { |
| 98 | const created = String(token.created).slice(0, 10) |
| 99 | output.standard(`${chalk.blue('Token')} ${token.token}… with id ${chalk.cyan(token.id)} created ${created}`) |
| 100 | if (token.cidr_whitelist) { |
| 101 | output.standard(`with IP whitelist: ${chalk.green(token.cidr_whitelist.join(','))}`) |
| 102 | } |
| 103 | output.standard() |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | async rm (args) { |
| 108 | if (args.length === 0) { |