api-key: Add revoke command which accepts a list of API key ids

Change-type: minor
This commit is contained in:
myarmolinsky 2023-05-24 14:50:08 -04:00
parent 1a77d86347
commit 4b1378dfbc
4 changed files with 146 additions and 66 deletions

View File

@ -10,7 +10,7 @@ _balena() {
# Valid top-level completions
main_commands=( build deploy envs fleets join keys leave login logout logs note orgs preload push releases scan settings ssh support tags tunnel version whoami api-key api-keys app block config device device devices env fleet fleet internal key key local os release release tag util )
# Sub-completions
api_key_cmds=( generate )
api_key_cmds=( generate revoke )
app_cmds=( create )
block_cmds=( create )
config_cmds=( generate inject read reconfigure write )

View File

@ -9,7 +9,7 @@ _balena_complete()
# Valid top-level completions
main_commands="build deploy envs fleets join keys leave login logout logs note orgs preload push releases scan settings ssh support tags tunnel version whoami api-key api-keys app block config device device devices env fleet fleet internal key key local os release release tag util"
# Sub-completions
api_key_cmds="generate"
api_key_cmds="generate revoke"
app_cmds="create"
block_cmds="create"
config_cmds="generate inject read reconfigure write"

View File

@ -0,0 +1,80 @@
/**
* @license
* Copyright 2016-2020 Balena Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { flags } from '@oclif/command';
import Command from '../../command';
import * as cf from '../../utils/common-flags';
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
interface FlagsDef {
help: void;
}
interface ArgsDef {
ids: string;
}
export default class RevokeCmd extends Command {
public static description = stripIndent`
Revoke balenaCloud API keys.
Revoke balenaCloud API keys with the given
comma-separated list of ids.
The given balenaCloud API keys will no longer be usable.
`;
public static examples = [
'$ balena api-key revoke 123',
'$ balena api-key revoke 123,124,456',
];
public static args = [
{
name: 'ids',
description: 'the API key ids',
required: true,
},
];
public static usage = 'api-key revoke <ids>';
public static flags: flags.Input<FlagsDef> = {
help: cf.help,
};
public static authenticated = true;
public async run() {
const { args: params } = this.parse<FlagsDef, ArgsDef>(RevokeCmd);
try {
const apiKeyIds = params.ids.split(',');
if (apiKeyIds.filter((apiKeyId) => !apiKeyId.match(/^\d+$/)).length > 0) {
console.log('API key ids must be positive integers');
return;
}
await Promise.all(
apiKeyIds.map(
async (id) => await getBalenaSdk().models.apiKey.revoke(Number(id)),
),
);
console.log('Successfully revoked the given API keys');
} catch (e) {
throw e;
}
}
}

128
npm-shrinkwrap.json generated
View File

@ -1790,16 +1790,16 @@
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/@oclif/command": {
"version": "1.8.27",
"resolved": "https://registry.npmjs.org/@oclif/command/-/command-1.8.27.tgz",
"integrity": "sha512-x1evrqQ2bAEuoqkveOCYgIqkj43SntoM02C45gfYNrdvrX8nsne+uzzXzwKcJ0p94qnQRX7PmyxOaRDF7f77xw==",
"version": "1.8.29",
"resolved": "https://registry.npmjs.org/@oclif/command/-/command-1.8.29.tgz",
"integrity": "sha512-wupMygd4nZ5B4oCjkjGBMzZKY9tjNKGg8iZgqjLpWs9zz8WlwIf0DemDkdaYfIkZ7vUGbPAKSg0zbD/qSdhMRw==",
"dependencies": {
"@oclif/config": "^1.18.2",
"@oclif/errors": "^1.3.6",
"@oclif/help": "^1.0.1",
"@oclif/parser": "^3.8.12",
"debug": "^4.1.1",
"semver": "^7.5.1"
"semver": "^7.5.3"
},
"engines": {
"node": ">=12.0.0"
@ -3048,9 +3048,9 @@
}
},
"node_modules/@types/node": {
"version": "16.18.34",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.34.tgz",
"integrity": "sha512-VmVm7gXwhkUimRfBwVI1CHhwp86jDWR04B5FGebMMyxV90SlCmFujwUHrxTD4oO+SOYU86SoxvhgeRQJY7iXFg=="
"version": "16.18.36",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.36.tgz",
"integrity": "sha512-8egDX8dE50XyXWH6C6PRCNkTP106DuUrvdrednFouDSmCi7IOvrqr0frznfZaHifHH/3aq/7a7v9N4wdXMqhBQ=="
},
"node_modules/@types/node-cleanup": {
"version": "2.1.2",
@ -4177,9 +4177,9 @@
}
},
"node_modules/balena-sdk/node_modules/@types/node": {
"version": "14.18.48",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.48.tgz",
"integrity": "sha512-iL0PIMwejpmuVHgfibHpfDwOdsbmB50wr21X71VnF5d7SsBF7WK+ZvP/SCcFm7Iwb9iiYSap9rlrdhToNAWdxg=="
"version": "14.18.51",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.51.tgz",
"integrity": "sha512-P9bsdGFPpVtofEKlhWMVS2qqx1A/rt9QBfihWlklfHHpUpjtYse5AzFz6j4DWrARLYh6gRnw9+5+DJcrq3KvBA=="
},
"node_modules/balena-sdk/node_modules/date-fns": {
"version": "2.30.0",
@ -5871,9 +5871,9 @@
}
},
"node_modules/cpu-features": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.7.tgz",
"integrity": "sha512-fjzFmsUKKCrC9GrM1eQTvQx18e+kjXFzjRLvJPNEDjk31+bJ6ZiV6uchv/hzbzXVIgbWdrEyyX1IFKwse65+8w==",
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.8.tgz",
"integrity": "sha512-BbHBvtYhUhksqTjr6bhNOjGgMnhwhGTQmOoZGD+K7BCaQDCuZl/Ve1ZxUSMRwVC4D/rkCPQ2MAIeYzrWyK7eEg==",
"hasInstallScript": true,
"optional": true,
"dependencies": {
@ -8047,9 +8047,9 @@
}
},
"node_modules/etcher-sdk/node_modules/node-abi": {
"version": "3.44.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.44.0.tgz",
"integrity": "sha512-MYjZTiAETGG28/7fBH1RjuY7vzDwYC5q5U4whCgM4jNEQcC0gAvN339LxXukmL2T2tGpzYTfp+LZ5RN7E5DwEg==",
"version": "3.45.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.45.0.tgz",
"integrity": "sha512-iwXuFrMAcFVi/ZoZiqq8BzAdsLw9kxDfTC0HMyjXfSL/6CSDAGD5UmR7azrAgWV1zKYq7dUUMj4owusBWKLsiQ==",
"dependencies": {
"semver": "^7.3.5"
},
@ -15458,9 +15458,9 @@
}
},
"node_modules/pkg/node_modules/node-abi": {
"version": "3.44.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.44.0.tgz",
"integrity": "sha512-MYjZTiAETGG28/7fBH1RjuY7vzDwYC5q5U4whCgM4jNEQcC0gAvN339LxXukmL2T2tGpzYTfp+LZ5RN7E5DwEg==",
"version": "3.45.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.45.0.tgz",
"integrity": "sha512-iwXuFrMAcFVi/ZoZiqq8BzAdsLw9kxDfTC0HMyjXfSL/6CSDAGD5UmR7azrAgWV1zKYq7dUUMj4owusBWKLsiQ==",
"dev": true,
"dependencies": {
"semver": "^7.3.5"
@ -17442,9 +17442,9 @@
}
},
"node_modules/semver": {
"version": "7.5.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.1.tgz",
"integrity": "sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==",
"version": "7.5.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz",
"integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==",
"dependencies": {
"lru-cache": "^6.0.0"
},
@ -18240,9 +18240,9 @@
"integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g=="
},
"node_modules/ssh2": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.13.0.tgz",
"integrity": "sha512-CIZBFRRY1y9mAZSqBGFE4EB4dNJad2ysT2PqO8OpkiI3UTB/gUZwE5EaN16qVyQ6s/M7EgC/iaV/MnjdlvnuzA==",
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.14.0.tgz",
"integrity": "sha512-AqzD1UCqit8tbOKoj6ztDDi1ffJZ2rV2SwlgrVVrHPkV5vWqGJOVp5pmtj18PunkPJAuKQsnInyKV+/Nb2bUnA==",
"hasInstallScript": true,
"dependencies": {
"asn1": "^0.2.6",
@ -18252,7 +18252,7 @@
"node": ">=10.16.0"
},
"optionalDependencies": {
"cpu-features": "~0.0.7",
"cpu-features": "~0.0.8",
"nan": "^2.17.0"
}
},
@ -19417,9 +19417,9 @@
}
},
"node_modules/ts-node/node_modules/acorn": {
"version": "8.8.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz",
"integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==",
"version": "8.9.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz",
"integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==",
"dev": true,
"bin": {
"acorn": "bin/acorn"
@ -20582,9 +20582,9 @@
}
},
"node_modules/winusb-driver-generator/node_modules/node-abi": {
"version": "3.44.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.44.0.tgz",
"integrity": "sha512-MYjZTiAETGG28/7fBH1RjuY7vzDwYC5q5U4whCgM4jNEQcC0gAvN339LxXukmL2T2tGpzYTfp+LZ5RN7E5DwEg==",
"version": "3.45.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.45.0.tgz",
"integrity": "sha512-iwXuFrMAcFVi/ZoZiqq8BzAdsLw9kxDfTC0HMyjXfSL/6CSDAGD5UmR7azrAgWV1zKYq7dUUMj4owusBWKLsiQ==",
"optional": true,
"dependencies": {
"semver": "^7.3.5"
@ -23792,16 +23792,16 @@
}
},
"@oclif/command": {
"version": "1.8.27",
"resolved": "https://registry.npmjs.org/@oclif/command/-/command-1.8.27.tgz",
"integrity": "sha512-x1evrqQ2bAEuoqkveOCYgIqkj43SntoM02C45gfYNrdvrX8nsne+uzzXzwKcJ0p94qnQRX7PmyxOaRDF7f77xw==",
"version": "1.8.29",
"resolved": "https://registry.npmjs.org/@oclif/command/-/command-1.8.29.tgz",
"integrity": "sha512-wupMygd4nZ5B4oCjkjGBMzZKY9tjNKGg8iZgqjLpWs9zz8WlwIf0DemDkdaYfIkZ7vUGbPAKSg0zbD/qSdhMRw==",
"requires": {
"@oclif/config": "^1.18.2",
"@oclif/errors": "^1.3.6",
"@oclif/help": "^1.0.1",
"@oclif/parser": "^3.8.12",
"debug": "^4.1.1",
"semver": "^7.5.1"
"semver": "^7.5.3"
}
},
"@oclif/config": {
@ -24893,9 +24893,9 @@
}
},
"@types/node": {
"version": "16.18.34",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.34.tgz",
"integrity": "sha512-VmVm7gXwhkUimRfBwVI1CHhwp86jDWR04B5FGebMMyxV90SlCmFujwUHrxTD4oO+SOYU86SoxvhgeRQJY7iXFg=="
"version": "16.18.36",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.36.tgz",
"integrity": "sha512-8egDX8dE50XyXWH6C6PRCNkTP106DuUrvdrednFouDSmCi7IOvrqr0frznfZaHifHH/3aq/7a7v9N4wdXMqhBQ=="
},
"@types/node-cleanup": {
"version": "2.1.2",
@ -25843,9 +25843,9 @@
},
"dependencies": {
"@types/node": {
"version": "14.18.48",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.48.tgz",
"integrity": "sha512-iL0PIMwejpmuVHgfibHpfDwOdsbmB50wr21X71VnF5d7SsBF7WK+ZvP/SCcFm7Iwb9iiYSap9rlrdhToNAWdxg=="
"version": "14.18.51",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.51.tgz",
"integrity": "sha512-P9bsdGFPpVtofEKlhWMVS2qqx1A/rt9QBfihWlklfHHpUpjtYse5AzFz6j4DWrARLYh6gRnw9+5+DJcrq3KvBA=="
},
"date-fns": {
"version": "2.30.0",
@ -27203,9 +27203,9 @@
}
},
"cpu-features": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.7.tgz",
"integrity": "sha512-fjzFmsUKKCrC9GrM1eQTvQx18e+kjXFzjRLvJPNEDjk31+bJ6ZiV6uchv/hzbzXVIgbWdrEyyX1IFKwse65+8w==",
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.8.tgz",
"integrity": "sha512-BbHBvtYhUhksqTjr6bhNOjGgMnhwhGTQmOoZGD+K7BCaQDCuZl/Ve1ZxUSMRwVC4D/rkCPQ2MAIeYzrWyK7eEg==",
"optional": true,
"requires": {
"buildcheck": "~0.0.6",
@ -28945,9 +28945,9 @@
"integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ=="
},
"node-abi": {
"version": "3.44.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.44.0.tgz",
"integrity": "sha512-MYjZTiAETGG28/7fBH1RjuY7vzDwYC5q5U4whCgM4jNEQcC0gAvN339LxXukmL2T2tGpzYTfp+LZ5RN7E5DwEg==",
"version": "3.45.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.45.0.tgz",
"integrity": "sha512-iwXuFrMAcFVi/ZoZiqq8BzAdsLw9kxDfTC0HMyjXfSL/6CSDAGD5UmR7azrAgWV1zKYq7dUUMj4owusBWKLsiQ==",
"requires": {
"semver": "^7.3.5"
}
@ -34642,9 +34642,9 @@
"dev": true
},
"node-abi": {
"version": "3.44.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.44.0.tgz",
"integrity": "sha512-MYjZTiAETGG28/7fBH1RjuY7vzDwYC5q5U4whCgM4jNEQcC0gAvN339LxXukmL2T2tGpzYTfp+LZ5RN7E5DwEg==",
"version": "3.45.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.45.0.tgz",
"integrity": "sha512-iwXuFrMAcFVi/ZoZiqq8BzAdsLw9kxDfTC0HMyjXfSL/6CSDAGD5UmR7azrAgWV1zKYq7dUUMj4owusBWKLsiQ==",
"dev": true,
"requires": {
"semver": "^7.3.5"
@ -36289,9 +36289,9 @@
}
},
"semver": {
"version": "7.5.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.1.tgz",
"integrity": "sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==",
"version": "7.5.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz",
"integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==",
"requires": {
"lru-cache": "^6.0.0"
}
@ -36934,13 +36934,13 @@
"integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g=="
},
"ssh2": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.13.0.tgz",
"integrity": "sha512-CIZBFRRY1y9mAZSqBGFE4EB4dNJad2ysT2PqO8OpkiI3UTB/gUZwE5EaN16qVyQ6s/M7EgC/iaV/MnjdlvnuzA==",
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.14.0.tgz",
"integrity": "sha512-AqzD1UCqit8tbOKoj6ztDDi1ffJZ2rV2SwlgrVVrHPkV5vWqGJOVp5pmtj18PunkPJAuKQsnInyKV+/Nb2bUnA==",
"requires": {
"asn1": "^0.2.6",
"bcrypt-pbkdf": "^1.0.2",
"cpu-features": "~0.0.7",
"cpu-features": "~0.0.8",
"nan": "^2.17.0"
}
},
@ -37855,9 +37855,9 @@
},
"dependencies": {
"acorn": {
"version": "8.8.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz",
"integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==",
"version": "8.9.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz",
"integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==",
"dev": true
},
"diff": {
@ -38757,9 +38757,9 @@
"optional": true
},
"node-abi": {
"version": "3.44.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.44.0.tgz",
"integrity": "sha512-MYjZTiAETGG28/7fBH1RjuY7vzDwYC5q5U4whCgM4jNEQcC0gAvN339LxXukmL2T2tGpzYTfp+LZ5RN7E5DwEg==",
"version": "3.45.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.45.0.tgz",
"integrity": "sha512-iwXuFrMAcFVi/ZoZiqq8BzAdsLw9kxDfTC0HMyjXfSL/6CSDAGD5UmR7azrAgWV1zKYq7dUUMj4owusBWKLsiQ==",
"optional": true,
"requires": {
"semver": "^7.3.5"