| 100 | } |
| 101 | |
| 102 | async get (args) { |
| 103 | const tfa = 'two-factor auth' |
| 104 | const info = await get({ ...this.npm.flatOptions }) |
| 105 | |
| 106 | if (!info.cidr_whitelist) { |
| 107 | delete info.cidr_whitelist |
| 108 | } |
| 109 | |
| 110 | if (this.npm.config.get('json')) { |
| 111 | output.buffer(info) |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | // clean up and format key/values for output |
| 116 | const cleaned = {} |
| 117 | for (const key of knownProfileKeys) { |
| 118 | cleaned[key] = info[key] || '' |
| 119 | } |
| 120 | |
| 121 | const unknownProfileKeys = Object.keys(info).filter((k) => !(k in cleaned)) |
| 122 | for (const key of unknownProfileKeys) { |
| 123 | cleaned[key] = info[key] || '' |
| 124 | } |
| 125 | |
| 126 | delete cleaned.tfa |
| 127 | delete cleaned.email_verified |
| 128 | cleaned.email += info.email_verified ? ' (verified)' : '(unverified)' |
| 129 | |
| 130 | if (info.tfa && !info.tfa.pending) { |
| 131 | cleaned[tfa] = info.tfa.mode |
| 132 | } else { |
| 133 | cleaned[tfa] = 'disabled' |
| 134 | } |
| 135 | |
| 136 | if (args.length) { |
| 137 | const values = args // comma or space separated |
| 138 | .join(',') |
| 139 | .split(/,/) |
| 140 | .filter((arg) => arg.trim() !== '') |
| 141 | .map((arg) => cleaned[arg]) |
| 142 | .join('\t') |
| 143 | output.standard(values) |
| 144 | } else { |
| 145 | if (this.npm.config.get('parseable')) { |
| 146 | for (const key of Object.keys(info)) { |
| 147 | if (key === 'tfa') { |
| 148 | output.standard(`${key}\t${cleaned[tfa]}`) |
| 149 | } else { |
| 150 | output.standard(`${key}\t${info[key]}`) |
| 151 | } |
| 152 | } |
| 153 | } else { |
| 154 | for (const [key, value] of Object.entries(cleaned)) { |
| 155 | output.standard(`${key}: ${value}`) |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |