UNPKG

@axway/axway-cli-auth

Version:

Authenticate machines with the Axway Amplify platform

70 lines (62 loc) 2.27 kB
import { initSDK, getAuthConfigEnvSpecifier } from '@axway/amplify-cli-utils'; import { renderAccountInfo } from '../lib/info.js'; import snooplogg from 'snooplogg'; var whoami = { args: [ { name: 'account-name', desc: 'The account to display' } ], desc: 'Display info for an authenticated account', help: 'Display the currently selected account, organizations, roles, and teams.', options: { '--json': { callback: ({ ctx, value }) => ctx.jsonMode = value, desc: 'Outputs accounts as JSON' } }, async action({ argv, console }) { const { config, sdk } = await initSDK({ baseUrl: argv.baseUrl, env: argv.env, realm: argv.realm }); const authConfigEnvSpecifier = getAuthConfigEnvSpecifier(sdk.env.name); let accounts = await sdk.auth.list({ defaultTeams: await config.get(`${authConfigEnvSpecifier}.defaultTeam`), validate: true }); for (const account of accounts) { account.default = account.name === await config.get(`${authConfigEnvSpecifier}.defaultAccount`); } if (argv.accountName) { // eslint-disable-next-line security/detect-non-literal-regexp const re = new RegExp(`${argv.accountName}`, 'i'); accounts = accounts.filter(a => re.test(a.name) || re.test(a.user.email) || re.test(a.org.name)); } if (argv.json) { console.log(JSON.stringify(accounts, null, 2)); } else { const { highlight, note } = snooplogg.styles; if (accounts.length) { let account = accounts.find(a => a.default); if (!account) { account = accounts[0]; } if (account.isPlatform && account.org?.name) { console.log(`You are logged into a ${highlight('platform')} account in organization ${highlight(account.org.name)} ${note(`(${account.org.guid})`)} as ${highlight(account.user.email || account.name)}.`); } else { console.log(`You are logged into a ${highlight('service')} account as ${highlight(account.user.email || account.name)}.`); } console.log(await renderAccountInfo(account, config, sdk)); } else if (argv.accountName) { console.log(`The account ${highlight(argv.accountName)} is not logged in.`); } else { console.log('You are not logged in.'); } } } }; export { whoami as default }; //# sourceMappingURL=whoami.js.map