Skip to content

Commit 9ccf274

Browse files
committed
fix(import): re-import devices that have been imported previously
Kit production team states that because some devices will be re-tested, the latest credentials need to be used. Therfore this re-imports the certificate to nRF Cloud for devices that have been imported previously.
1 parent 931fcaf commit 9ccf274

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

cli/commands/import-devices.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ export const importDevicesCommand = ({
9090
table(
9191
[
9292
['Fingerprint', 'Device ID', 'Model', 'HW version'],
93-
...Array.from(devices.entries())
94-
.filter(([imei]) => !existingDevices.includes(`oob-${imei}`))
95-
.map(([imei, { fingerprint, hwVersion }]) => [
93+
...Array.from(devices.entries()).map(
94+
([imei, { fingerprint, hwVersion }]) => [
9695
chalk.green(fingerprint),
9796
chalk.blue(imei),
9897
chalk.blue(model),
9998
chalk.blue(hwVersion),
100-
]),
99+
],
100+
),
101101
],
102102
{
103103
singleLine: true,
@@ -108,7 +108,7 @@ export const importDevicesCommand = ({
108108
if (existingDevices.length > 0) {
109109
console.warn(
110110
chalk.yellow(
111-
`Skipping`,
111+
`Re-importing certificates for`,
112112
existingDevices.length,
113113
`devices which are already registered.`,
114114
),
@@ -146,17 +146,15 @@ export const importDevicesCommand = ({
146146
for (const page of chunk([...deviceCertificates.entries()], 1000)) {
147147
// Bulk-ops API allows max 1,000 devices per request
148148
const registration = await client.register(
149-
Array.from(page)
150-
.filter(([imei]) => !existingDevices.includes(`oob-${imei}`))
151-
.map(([imei, { certificate: certPem }]) => {
152-
const deviceId = `oob-${imei}`
153-
return {
154-
deviceId,
155-
subType: model.replace(/[^0-9a-z-]/gi, '-'),
156-
tags: [model.replace(/[^0-9a-z-]/gi, ':')],
157-
certPem,
158-
}
159-
}),
149+
Array.from(page).map(([imei, { certificate: certPem }]) => {
150+
const deviceId = `oob-${imei}`
151+
return {
152+
deviceId,
153+
subType: model.replace(/[^0-9a-z-]/gi, '-'),
154+
tags: [model.replace(/[^0-9a-z-]/gi, ':')],
155+
certPem,
156+
}
157+
}),
160158
)
161159

162160
if ('error' in registration) {

0 commit comments

Comments
 (0)