Skip to content

Commit

Permalink
Fix/update deployment command (#46)
Browse files Browse the repository at this point in the history
* 1.17.3

* fix: deployment update cmd

* fix: use ternary as per linting rule
  • Loading branch information
aarlaud authored Nov 4, 2024
1 parent fa130ee commit bc222e7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 35 deletions.
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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]`

Expand Down Expand Up @@ -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`

Expand All @@ -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`

Expand Down Expand Up @@ -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]`

Expand All @@ -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]`

Expand All @@ -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]`

Expand All @@ -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]`

Expand All @@ -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]`

Expand All @@ -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]`

Expand All @@ -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]`

Expand Down Expand Up @@ -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]`

Expand All @@ -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]`

Expand All @@ -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]`

Expand All @@ -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]`

Expand All @@ -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]`

Expand All @@ -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)_
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 6 additions & 0 deletions src/command-helpers/deployments/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
}
20 changes: 18 additions & 2 deletions src/commands/deployments/update.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -46,7 +46,23 @@ export default class Deployments extends BaseCommand<typeof Deployments> {
}
}

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))
Expand Down

0 comments on commit bc222e7

Please sign in to comment.