Skip to content

Commit

Permalink
Merge pull request #768 from particle-iot/feature/sc-129604/skip-prot…
Browse files Browse the repository at this point in the history
…ected-devices-on-non-protected-products

Skip adding protected devices to non-protection products
  • Loading branch information
keeramis authored Sep 5, 2024
2 parents e179442 + 4f9e7b4 commit 42b719d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/cmd/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ module.exports = class ProductCommand extends CLICommandBase {
.then(result => this.showDeviceAddResult(result));
}

showDeviceAddResult({ product, identifiers, status: { invalidDeviceIds = [], nonmemberDeviceIds = [] } } = {}){
identifiers = filterDeviceIdentifiers(identifiers, invalidDeviceIds, nonmemberDeviceIds);
showDeviceAddResult({ product, identifiers, status: { invalidDeviceIds = [], nonmemberDeviceIds = [], protectedDeviceIds = [] } } = {}){
identifiers = filterDeviceIdentifiers(identifiers, invalidDeviceIds, nonmemberDeviceIds, protectedDeviceIds);
const message = [];

if (identifiers.length){
Expand Down Expand Up @@ -75,6 +75,14 @@ module.exports = class ProductCommand extends CLICommandBase {
);
}

if (protectedDeviceIds.length){
message.push(
'Skipped Protected IDs:',
dedupeAndStringifyIDList(protectedDeviceIds),
''
);
}

if (!identifiers.length){
throw new Error(message.join(os.EOL));
}
Expand Down Expand Up @@ -200,9 +208,10 @@ function readDeviceListFile(file){
});
}

function filterDeviceIdentifiers(identifiers, invalid = [], nonmember = []){
function filterDeviceIdentifiers(identifiers, invalid = [], nonmember = [], protectedDevice = []){
return identifiers.reduce((out, x) => {
if (!hasDeviceIdentifier(x, invalid) && !hasDeviceIdentifier(x, nonmember)){
if (!hasDeviceIdentifier(x, invalid) && !hasDeviceIdentifier(x, nonmember)
&& !hasDeviceIdentifier(x, protectedDevice)){
out.push(x);
}
return out;
Expand Down

0 comments on commit 42b719d

Please sign in to comment.