Skip to content

Commit

Permalink
fix(import): re-import devices that have been imported previously
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
coderbyheart committed Dec 13, 2024
1 parent 931fcaf commit 9ccf274
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions cli/commands/import-devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ export const importDevicesCommand = ({
table(
[
['Fingerprint', 'Device ID', 'Model', 'HW version'],
...Array.from(devices.entries())
.filter(([imei]) => !existingDevices.includes(`oob-${imei}`))
.map(([imei, { fingerprint, hwVersion }]) => [
...Array.from(devices.entries()).map(
([imei, { fingerprint, hwVersion }]) => [
chalk.green(fingerprint),
chalk.blue(imei),
chalk.blue(model),
chalk.blue(hwVersion),
]),
],
),
],
{
singleLine: true,
Expand All @@ -108,7 +108,7 @@ export const importDevicesCommand = ({
if (existingDevices.length > 0) {
console.warn(
chalk.yellow(
`Skipping`,
`Re-importing certificates for`,
existingDevices.length,
`devices which are already registered.`,
),
Expand Down Expand Up @@ -146,17 +146,15 @@ export const importDevicesCommand = ({
for (const page of chunk([...deviceCertificates.entries()], 1000)) {
// Bulk-ops API allows max 1,000 devices per request
const registration = await client.register(
Array.from(page)
.filter(([imei]) => !existingDevices.includes(`oob-${imei}`))
.map(([imei, { certificate: certPem }]) => {
const deviceId = `oob-${imei}`
return {
deviceId,
subType: model.replace(/[^0-9a-z-]/gi, '-'),
tags: [model.replace(/[^0-9a-z-]/gi, ':')],
certPem,
}
}),
Array.from(page).map(([imei, { certificate: certPem }]) => {
const deviceId = `oob-${imei}`
return {
deviceId,
subType: model.replace(/[^0-9a-z-]/gi, '-'),
tags: [model.replace(/[^0-9a-z-]/gi, ':')],
certPem,
}
}),
)

if ('error' in registration) {
Expand Down

0 comments on commit 9ccf274

Please sign in to comment.