From bc222e724d828a4b3e1bed757a903b22be660eed Mon Sep 17 00:00:00 2001 From: aarlaud Date: Mon, 4 Nov 2024 11:48:08 +0100 Subject: [PATCH] Fix/update deployment command (#46) * 1.17.3 * fix: deployment update cmd * fix: use ternary as per linting rule --- README.md | 60 ++++++++++++------------ package-lock.json | 4 +- package.json | 2 +- src/command-helpers/deployments/flags.ts | 6 +++ src/commands/deployments/update.ts | 20 +++++++- 5 files changed, 57 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 63d5b9d..c9e11c1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ $ npm install -g snyk-broker-config $ snyk-broker-config COMMAND running command... $ snyk-broker-config (--version) -snyk-broker-config/1.17.2 linux-x64 node-v20.14.0 +snyk-broker-config/1.17.3 linux-x64 node-v20.14.0 $ snyk-broker-config --help [COMMAND] USAGE $ snyk-broker-config COMMAND @@ -208,7 +208,7 @@ EXAMPLES $ snyk-broker-config connections create TENANT_ID INSTALL_ID DEPLOYMENT_ID --type github ``` -_See code: [src/commands/connections/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/connections/create.ts)_ +_See code: [src/commands/connections/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/connections/create.ts)_ ## `snyk-broker-config connections delete DEPLOYMENTID CONNECTIONID [APIURL] [APIVERSION]` @@ -243,7 +243,7 @@ EXAMPLES $ snyk-broker-config connections delete TENANT_ID INSTALL_ID DEPLOYMENT_ID CONNECTION_ID ``` -_See code: [src/commands/connections/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/connections/delete.ts)_ +_See code: [src/commands/connections/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/connections/delete.ts)_ ## `snyk-broker-config connections list DEPLOYMENTID [APIURL] [APIVERSION]` @@ -277,7 +277,7 @@ EXAMPLES $ snyk-broker-config connections list TENANT_ID INSTALL_ID DEPLOYMENT_ID ``` -_See code: [src/commands/connections/list.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/connections/list.ts)_ +_See code: [src/commands/connections/list.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/connections/list.ts)_ ## `snyk-broker-config connections update DEPLOYMENTID CONNECTIONID [APIURL] [APIVERSION]` @@ -355,7 +355,7 @@ EXAMPLES $ snyk-broker-config connections update TENANT_ID INSTALL_ID DEPLOYMENT_ID CONNECTION_ID --type github ``` -_See code: [src/commands/connections/update.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/connections/update.ts)_ +_See code: [src/commands/connections/update.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/connections/update.ts)_ ## `snyk-broker-config credentials create DEPLOYMENTID [APIURL] [APIVERSION]` @@ -395,7 +395,7 @@ EXAMPLES $ snyk-broker-config credentials create TENANT_ID INSTALL_ID DEPLOYMENT_ID --comment "mycomment" --env_var_name MY_GITHUB_TOKEN --type github ``` -_See code: [src/commands/credentials/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/credentials/create.ts)_ +_See code: [src/commands/credentials/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/credentials/create.ts)_ ## `snyk-broker-config credentials delete DEPLOYMENTID [APIURL] [APIVERSION]` @@ -432,7 +432,7 @@ EXAMPLES $ snyk-broker-config credentials delete TENANT_ID INSTALL_ID DEPLOYMENT_ID -c CREDENTIALS_ID ``` -_See code: [src/commands/credentials/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/credentials/delete.ts)_ +_See code: [src/commands/credentials/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/credentials/delete.ts)_ ## `snyk-broker-config credentials list DEPLOYMENTID [APIURL] [APIVERSION]` @@ -466,7 +466,7 @@ EXAMPLES $ snyk-broker-config credentials list TENANT_ID INSTALL_ID DEPLOYMENT_ID ``` -_See code: [src/commands/credentials/list.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/credentials/list.ts)_ +_See code: [src/commands/credentials/list.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/credentials/list.ts)_ ## `snyk-broker-config credentials update DEPLOYMENTID [APIURL] [APIVERSION]` @@ -507,7 +507,7 @@ EXAMPLES $ snyk-broker-config credentials update TENANT_ID INSTALL_ID DEPLOYMENT_ID --credentialsId CREDENTIALID --comment "mycomment" --env_var_name MY_GITHUB_TOKEN --type github ``` -_See code: [src/commands/credentials/update.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/credentials/update.ts)_ +_See code: [src/commands/credentials/update.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/credentials/update.ts)_ ## `snyk-broker-config deployments create APPINSTALLEDINORGID [APIURL] [APIVERSION]` @@ -545,7 +545,7 @@ EXAMPLES $ snyk-broker-config deployments create TENANT_ID INSTALL_ID APP_INSTALLED_ORG_ID --data mykey=myvalue,mykey2=myvalue2 ``` -_See code: [src/commands/deployments/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/deployments/create.ts)_ +_See code: [src/commands/deployments/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/deployments/create.ts)_ ## `snyk-broker-config deployments delete DEPLOYMENTID` @@ -576,7 +576,7 @@ EXAMPLES $ snyk-broker-config deployments delete TENANT_ID INSTALL_ID DEPLOYMENT_ID ``` -_See code: [src/commands/deployments/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/deployments/delete.ts)_ +_See code: [src/commands/deployments/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/deployments/delete.ts)_ ## `snyk-broker-config deployments list [APIURL] [APIVERSION]` @@ -608,7 +608,7 @@ EXAMPLES $ snyk-broker-config deployments list TENANT_ID INSTALL_ID ``` -_See code: [src/commands/deployments/list.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/deployments/list.ts)_ +_See code: [src/commands/deployments/list.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/deployments/list.ts)_ ## `snyk-broker-config deployments update DEPLOYMENTID` @@ -643,7 +643,7 @@ EXAMPLES $ snyk-broker-config deployments update TENANT_ID INSTALL_ID DEPLOYMENT_ID --data mykey=myvalue,mykey2=myvalue2 ``` -_See code: [src/commands/deployments/update.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/deployments/update.ts)_ +_See code: [src/commands/deployments/update.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/deployments/update.ts)_ ## `snyk-broker-config help [COMMAND]` @@ -700,7 +700,7 @@ EXAMPLES $ snyk-broker-config integrations create TENANT_ID INSTALL_ID CONNECTION_ID ORG_ID INTEGRATION_ID ``` -_See code: [src/commands/integrations/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/integrations/create.ts)_ +_See code: [src/commands/integrations/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/integrations/create.ts)_ ## `snyk-broker-config integrations delete CONNECTIONID ORGID INTEGRATIONID [APIURL] [APIVERSION]` @@ -736,7 +736,7 @@ EXAMPLES $ snyk-broker-config integrations delete TENANT_ID INSTALL_ID CONNECTION_ID ORG_ID INTEGRATION_ID ``` -_See code: [src/commands/integrations/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/integrations/delete.ts)_ +_See code: [src/commands/integrations/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/integrations/delete.ts)_ ## `snyk-broker-config integrations list CONNECTIONID [APIURL] [APIVERSION]` @@ -770,7 +770,7 @@ EXAMPLES $ snyk-broker-config integrations list TENANT_ID INSTALL_ID CONNECTION_ID ``` -_See code: [src/commands/integrations/list.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/integrations/list.ts)_ +_See code: [src/commands/integrations/list.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/integrations/list.ts)_ ## `snyk-broker-config introduction` @@ -792,7 +792,7 @@ EXAMPLES $ snyk-broker-config introduction ``` -_See code: [src/commands/introduction/index.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/introduction/index.ts)_ +_See code: [src/commands/introduction/index.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/introduction/index.ts)_ ## `snyk-broker-config plugins` @@ -1128,7 +1128,7 @@ EXAMPLES $ snyk-broker-config workflows connections create ``` -_See code: [src/commands/workflows/connections/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/connections/create.ts)_ +_See code: [src/commands/workflows/connections/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/connections/create.ts)_ ## `snyk-broker-config workflows connections delete [APIURL] [APIVERSION]` @@ -1155,7 +1155,7 @@ EXAMPLES $ snyk-broker-config workflows connections delete ``` -_See code: [src/commands/workflows/connections/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/connections/delete.ts)_ +_See code: [src/commands/workflows/connections/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/connections/delete.ts)_ ## `snyk-broker-config workflows connections disconnect [APIURL] [APIVERSION]` @@ -1182,7 +1182,7 @@ EXAMPLES $ snyk-broker-config workflows connections disconnect ``` -_See code: [src/commands/workflows/connections/disconnect.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/connections/disconnect.ts)_ +_See code: [src/commands/workflows/connections/disconnect.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/connections/disconnect.ts)_ ## `snyk-broker-config workflows connections get [APIURL] [APIVERSION]` @@ -1209,7 +1209,7 @@ EXAMPLES $ snyk-broker-config workflows connections get ``` -_See code: [src/commands/workflows/connections/get.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/connections/get.ts)_ +_See code: [src/commands/workflows/connections/get.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/connections/get.ts)_ ## `snyk-broker-config workflows connections integrate [APIURL] [APIVERSION]` @@ -1236,7 +1236,7 @@ EXAMPLES $ snyk-broker-config workflows connections integrate ``` -_See code: [src/commands/workflows/connections/integrate.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/connections/integrate.ts)_ +_See code: [src/commands/workflows/connections/integrate.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/connections/integrate.ts)_ ## `snyk-broker-config workflows connections migrate [APIURL] [APIVERSION]` @@ -1263,7 +1263,7 @@ EXAMPLES $ snyk-broker-config workflows connections migrate ``` -_See code: [src/commands/workflows/connections/migrate.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/connections/migrate.ts)_ +_See code: [src/commands/workflows/connections/migrate.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/connections/migrate.ts)_ ## `snyk-broker-config workflows credentials create [APIURL] [APIVERSION]` @@ -1290,7 +1290,7 @@ EXAMPLES $ snyk-broker-config workflows credentials create ``` -_See code: [src/commands/workflows/credentials/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/credentials/create.ts)_ +_See code: [src/commands/workflows/credentials/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/credentials/create.ts)_ ## `snyk-broker-config workflows credentials delete [APIURL] [APIVERSION]` @@ -1323,7 +1323,7 @@ EXAMPLES $ snyk-broker-config workflows credentials delete TENANT_ID INSTALL_ID ``` -_See code: [src/commands/workflows/credentials/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/credentials/delete.ts)_ +_See code: [src/commands/workflows/credentials/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/credentials/delete.ts)_ ## `snyk-broker-config workflows credentials get [APIURL] [APIVERSION]` @@ -1350,7 +1350,7 @@ EXAMPLES $ snyk-broker-config workflows credentials get ``` -_See code: [src/commands/workflows/credentials/get.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/credentials/get.ts)_ +_See code: [src/commands/workflows/credentials/get.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/credentials/get.ts)_ ## `snyk-broker-config workflows deployments create [APIURL] [APIVERSION]` @@ -1377,7 +1377,7 @@ EXAMPLES $ snyk-broker-config workflows deployments create ``` -_See code: [src/commands/workflows/deployments/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/deployments/create.ts)_ +_See code: [src/commands/workflows/deployments/create.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/deployments/create.ts)_ ## `snyk-broker-config workflows deployments delete [APIURL] [APIVERSION]` @@ -1404,7 +1404,7 @@ EXAMPLES $ snyk-broker-config workflows deployments delete ``` -_See code: [src/commands/workflows/deployments/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/deployments/delete.ts)_ +_See code: [src/commands/workflows/deployments/delete.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/deployments/delete.ts)_ ## `snyk-broker-config workflows deployments get [APIURL] [APIVERSION]` @@ -1431,7 +1431,7 @@ EXAMPLES $ snyk-broker-config workflows deployments get ``` -_See code: [src/commands/workflows/deployments/get.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/deployments/get.ts)_ +_See code: [src/commands/workflows/deployments/get.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/deployments/get.ts)_ ## `snyk-broker-config workflows deployments update [APIURL] [APIVERSION]` @@ -1458,5 +1458,5 @@ EXAMPLES $ snyk-broker-config workflows deployments update ``` -_See code: [src/commands/workflows/deployments/update.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.2/src/commands/workflows/deployments/update.ts)_ +_See code: [src/commands/workflows/deployments/update.ts](https://github.com/snyk/snyk-broker-config/blob/v1.17.3/src/commands/workflows/deployments/update.ts)_ diff --git a/package-lock.json b/package-lock.json index cb1ea5c..14e57e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "snyk-broker-config", - "version": "1.17.2", + "version": "1.17.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "snyk-broker-config", - "version": "1.17.2", + "version": "1.17.3", "license": "MIT", "dependencies": { "@inquirer/prompts": "^5.3.8", diff --git a/package.json b/package.json index c3fe163..1b1ce97 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "snyk-broker-config", "description": "Small utility to help with Universal Broker configuration and management", - "version": "1.17.2", + "version": "1.17.3", "author": "Snyk Ltd.", "bin": { "snyk-broker-config": "./bin/run.js" diff --git a/src/command-helpers/deployments/flags.ts b/src/command-helpers/deployments/flags.ts index bd6ea8a..a4da952 100644 --- a/src/command-helpers/deployments/flags.ts +++ b/src/command-helpers/deployments/flags.ts @@ -7,4 +7,10 @@ export const deploymentMetadata = { description: 'A series of key/value pairs comma separated. Ex: cluster=my_cluster,deployment_name=test', required: true, }), + overwrite: Flags.boolean({ + char: 'o', + + description: 'Overwrite metadata. Use to delete keys from metadata instead of additive metadata keys by default.', + required: false, + }), } diff --git a/src/commands/deployments/update.ts b/src/commands/deployments/update.ts index 91e3d8c..4ddd30b 100644 --- a/src/commands/deployments/update.ts +++ b/src/commands/deployments/update.ts @@ -1,6 +1,6 @@ import {ux} from '@oclif/core' import {commonUniversalBrokerArgs, commonUniversalBrokerDeploymentId, getCommonIds} from '../../common/args.js' -import {updateDeployment} from '../../api/deployments.js' +import {getDeployments, updateDeployment} from '../../api/deployments.js' import {deploymentMetadata} from '../../command-helpers/deployments/flags.js' import {printFormattedJSON} from '../../utils/display.js' import {BaseCommand} from '../../base-command.js' @@ -46,7 +46,23 @@ export default class Deployments extends BaseCommand { } } - const deployment = await updateDeployment(tenantId, installId, args.deploymentId!, attributes) + const existingDeployments = await getDeployments(tenantId, installId) + const existingDeployment = existingDeployments.data?.find((x) => x.id === args.deploymentId) + if (!existingDeployment) { + throw new Error('Deployment not found.') + } + + existingDeployment.attributes.metadata = flags.overwrite + ? attributes + : {...existingDeployment?.attributes.metadata, ...attributes} + + const deployment = await updateDeployment( + tenantId, + installId, + args.deploymentId!, + existingDeployment.attributes.metadata, + existingDeployment.attributes, + ) this.log(ux.colorize('cyan', `Updated Universal Broker Deployment for Tenant ${tenantId}, Install ${installId}`)) this.log(printFormattedJSON(deployment))