Skip to content

Commit 7e09f20

Browse files
committed
feat(cli): add command to show nRF Cloud account
1 parent 7574381 commit 7e09f20

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

cli/cli.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { registerDeviceCommand } from './commands/register-device.js'
2525
import { registerSimulatorDeviceCommand } from './commands/register-simulator-device.js'
2626
import { showDeviceCommand } from './commands/show-device.js'
2727
import { showFingerprintCommand } from './commands/show-fingerprint.js'
28+
import { showNRFCloudAccount } from './commands/show-nrfcloud-account.js'
2829
import { simulateDeviceCommand } from './commands/simulate-device.js'
2930

3031
const ssm = new SSMClient({})
@@ -143,6 +144,10 @@ const CLI = async ({ isCI }: { isCI: boolean }) => {
143144
db,
144145
devicesTableName: outputs.devicesTableName,
145146
}),
147+
showNRFCloudAccount({
148+
ssm,
149+
stackName: STACK_NAME,
150+
}),
146151
)
147152
} catch (error) {
148153
console.warn(chalk.yellow('⚠️'), chalk.yellow((error as Error).message))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { SSMClient } from '@aws-sdk/client-ssm'
2+
import chalk from 'chalk'
3+
import { table } from 'table'
4+
import { apiClient } from '../../nrfcloud/apiClient.js'
5+
import { getAPISettings } from '../../nrfcloud/settings.js'
6+
import type { CommandDefinition } from './CommandDefinition.js'
7+
8+
export const showNRFCloudAccount = ({
9+
ssm,
10+
stackName,
11+
}: {
12+
ssm: SSMClient
13+
stackName: string
14+
}): CommandDefinition => ({
15+
command: 'show-nrfcloud-account',
16+
action: async () => {
17+
const { apiKey, apiEndpoint } = await getAPISettings({
18+
ssm,
19+
stackName,
20+
})()
21+
22+
const client = apiClient({
23+
endpoint: apiEndpoint,
24+
apiKey,
25+
})
26+
27+
const account = await client.account()
28+
if ('error' in account) {
29+
console.error(chalk.red('⚠️'), '', chalk.red(account.error.message))
30+
process.exit(1)
31+
}
32+
33+
console.log(
34+
table([
35+
['Team name', 'Tenant ID', 'API endpoint', 'API key'],
36+
[
37+
chalk.cyan(account.account.team.name),
38+
chalk.cyan(account.account.team.tenantId),
39+
chalk.magenta(apiEndpoint.toString()),
40+
chalk.magenta(`${apiKey.slice(0, 5)}***`),
41+
],
42+
]),
43+
)
44+
},
45+
help: 'Show information about the associated nRF Cloud account',
46+
})

0 commit comments

Comments
 (0)