From 4cf790a1d4742833e288e8989b5887c2eedea719 Mon Sep 17 00:00:00 2001 From: Nathan Good Date: Thu, 21 Dec 2023 08:52:46 -0600 Subject: [PATCH 1/3] Added results and tests for results Signed-off-by: Nathan Good --- src/builders.ts | 34 +++++++++++++++++++-- src/common.ts | 16 ++++++++-- test/__snapshots__/taskbuilder.test.ts.snap | 16 ++++++++-- test/files/retrieve-secret.sh | 2 +- test/taskbuilder.test.ts | 20 ++++++------ 5 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/builders.ts b/src/builders.ts index afa532c..bd48823 100644 --- a/src/builders.ts +++ b/src/builders.ts @@ -6,7 +6,7 @@ import * as fs from 'fs'; import { ApiObject, ApiObjectProps, Yaml } from 'cdk8s'; import { Construct } from 'constructs'; -import { buildParam } from './common'; +import { usingBuildParameter, usingResultsPath } from './common'; import { Pipeline, PipelineParam, @@ -235,7 +235,7 @@ export class ParameterBuilder { this._requiresPipelineParam = true; this._name = pipelineParamName; this._defaultValue = defaultValue; - this._value = buildParam(pipelineParamName); + this._value = usingBuildParameter(pipelineParamName); return this; } @@ -308,6 +308,20 @@ class UrlScriptResolver implements ScriptResolver { } } +class UrlScriptToResultsResolver implements ScriptResolver { + readonly _resolver: ScriptResolver; + readonly _resultsName: string; + + constructor(url: string, resultsName: string) { + this._resolver = new UrlScriptResolver(url); + this._resultsName = resultsName; + } + + public scriptData(): string { + return [this._resolver.scriptData(), `tee ${usingResultsPath(this._resultsName)}`].join('|'); + } +} + /** * Gets the content from the static value provided. */ @@ -432,6 +446,20 @@ export class TaskStepBuilder { return this; } + /** + * If supplied, uses the content found at the given URL for the `script` value + * of the step and writes its output to the `results`. Use this as an + * alternative to "heredoc", which is embedding hard-coded shell or other + * scripts in the step. + * + * @param url + * @param resultsName + */ + public fromScriptUrlToResults(url: string, resultsName: string): TaskStepBuilder { + this._script = new UrlScriptToResultsResolver(url, resultsName); + return this; + } + /** * If supplied, uses the cdk8s `ApiObject` supplied as the body of the * `script` for the `Task`. This is most useful when used with `oc apply` or @@ -641,7 +669,7 @@ export class TaskBuilder { } /** - * Allows you to add an result to the Task. + * Allows you to add a result to the Task. * * @see https://tekton.dev/docs/pipelines/tasks/#emitting-results * diff --git a/src/common.ts b/src/common.ts index 038c3a4..dd6d621 100644 --- a/src/common.ts +++ b/src/common.ts @@ -32,7 +32,7 @@ export function secretKeyRef(name: string, key: string): NameKeyPair { * Convenience method for formatting the value of a working directory. * @param workspace */ -export function buildWorkingDir(workspace: string): string { +export function usingWorkspacePath(workspace: string): string { return `$(workspaces.${workspace}.path)`; } @@ -43,6 +43,18 @@ export function buildWorkingDir(workspace: string): string { * For example, if the parameter is `foo`, the result will be `$(params.foo)`. * @param name The name of the parameter. */ -export function buildParam(name: string): string { +export function usingBuildParameter(name: string): string { return `$(params.${name})`; +} + +/** + * Builds the correct string for building a reference to the file in which the + * result can be written during the execution of the Task. For example, if the + * name of the result is `foo`, this function will return `$(results.foo.path)`. + * + * @see https://tekton.dev/docs/pipelines/tasks/#emitting-results + * @param resultName The name of the result from the task. + */ +export function usingResultsPath(resultName: string): string { + return `$(results.${resultName}.path)`; } \ No newline at end of file diff --git a/test/__snapshots__/taskbuilder.test.ts.snap b/test/__snapshots__/taskbuilder.test.ts.snap index e9c7710..be79ec6 100644 --- a/test/__snapshots__/taskbuilder.test.ts.snap +++ b/test/__snapshots__/taskbuilder.test.ts.snap @@ -240,7 +240,7 @@ exports[`TaskBuilderTest TaskBuilderBasic 1`] = ` ] `; -exports[`TaskBuilderTest TaskBuilderIBMSecretGet 1`] = ` +exports[`TaskBuilderTest TestIBMCloudSecretsManagerGet 1`] = ` [ { "apiVersion": "tekton.dev/v1", @@ -266,14 +266,24 @@ exports[`TaskBuilderTest TaskBuilderIBMSecretGet 1`] = ` "description": "An IBM Cloud Secrets Manager key ID", "name": "KEY_ID", }, + { + "default": "https://{instance_ID}.us-south.secrets-manager.appdomain.cloud", + "description": "An IBM Cloud Secrets Manager instance endpoint URL (https://cloud.ibm.com/apidocs/secrets-manager/secrets-manager-v2#endpoints)", + "name": "SECRETS_MANAGER_ENDPOINT_URL", + }, + ], + "results": [ + { + "description": " A secret value retrieved using the provided KEY_ID", + "name": "secret-value", + }, ], - "results": [], "steps": [ { "env": undefined, "image": "quay.io/openshift/origin-cli:4.7", "name": "retrieve-key", - "script": "#!/usr/bin/env bash\\nset -x\\n\\n# Retrieves the IBM Cloud API Key configured in a \`deployer\` cluster\\n\\nexport IBMCLOUD_API_KEY=$(oc get secret ibm-secret -n kube-system -o jsonpath='{.data.apiKey}' | base64 -d)\\nexport AUTH_RESPONSE_JSON=$(curl -s -X POST \\\\n "https://iam.cloud.ibm.com/identity/token" \\\\n --header 'Content-Type: application/x-www-form-urlencoded' \\\\n --header 'Accept: application/json' \\\\n --data-urlencode 'grant_type=urn:ibm:params:oauth:grant-type:apikey' \\\\n --data-urlencode "apikey=\${IBMCLOUD_API_KEY}")\\nexport ACCESS_TOKEN=$(echo $AUTH_RESPONSE_JSON | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$')\\nexport SECRET_JSON=$(curl -s -X GET --location --header "Authorization: Bearer \${ACCESS_TOKEN}" --header "Accept: application/json" "$(params.SECRETS_MANAGER_ENDPOINT_URL)/api/v2/secrets/$(params.KEY_ID)")\\nexport SECRET=$(echo $SECRET_JSON | grep -o '"payload":"[^"]*' | grep -o '[^"]*$')\\nprintf "\${SECRET}" | tee $(results.secret-value.path)", + "script": "#!/usr/bin/env bash\\nset -x\\n\\n# Retrieves the IBM Cloud API Key configured in a \`deployer\` cluster\\n\\nexport IBMCLOUD_API_KEY=$(oc get secret ibm-secret -n kube-system -o jsonpath='{.data.apiKey}' | base64 -d)\\nexport AUTH_RESPONSE_JSON=$(curl -s -X POST \\\\n "https://iam.cloud.ibm.com/identity/token" \\\\n --header 'Content-Type: application/x-www-form-urlencoded' \\\\n --header 'Accept: application/json' \\\\n --data-urlencode 'grant_type=urn:ibm:params:oauth:grant-type:apikey' \\\\n --data-urlencode "apikey=\${IBMCLOUD_API_KEY}")\\nexport ACCESS_TOKEN=$(echo $AUTH_RESPONSE_JSON | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$')\\nexport SECRET_JSON=$(curl -s -X GET --location --header "Authorization: Bearer \${ACCESS_TOKEN}" --header "Accept: application/json" "$(params.SECRETS_MANAGER_ENDPOINT_URL)/api/v2/secrets/$(params.KEY_ID)")\\nexport SECRET=$(echo $SECRET_JSON | grep -o '"payload":"[^"]*' | grep -o '[^"]*$')\\nprintf "\${SECRET}"|tee $(results.secret-value.path)", "workingDir": undefined, }, ], diff --git a/test/files/retrieve-secret.sh b/test/files/retrieve-secret.sh index 8cdfb93..63c0fc0 100644 --- a/test/files/retrieve-secret.sh +++ b/test/files/retrieve-secret.sh @@ -13,4 +13,4 @@ export AUTH_RESPONSE_JSON=$(curl -s -X POST \ export ACCESS_TOKEN=$(echo $AUTH_RESPONSE_JSON | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$') export SECRET_JSON=$(curl -s -X GET --location --header "Authorization: Bearer ${ACCESS_TOKEN}" --header "Accept: application/json" "$(params.SECRETS_MANAGER_ENDPOINT_URL)/api/v2/secrets/$(params.KEY_ID)") export SECRET=$(echo $SECRET_JSON | grep -o '"payload":"[^"]*' | grep -o '[^"]*$') -printf "${SECRET}" | tee $(results.secret-value.path) \ No newline at end of file +printf "${SECRET}" diff --git a/test/taskbuilder.test.ts b/test/taskbuilder.test.ts index ad36cbf..3ba2da9 100644 --- a/test/taskbuilder.test.ts +++ b/test/taskbuilder.test.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import { Chart, Testing } from 'cdk8s'; import { ChartProps } from 'cdk8s/lib/chart'; import { Construct } from 'constructs'; -import { buildParam, buildWorkingDir, secretKeyRef, TaskBuilder, TaskStepBuilder, valueFrom, WorkspaceBuilder, ParameterBuilder } from '../src'; +import { usingBuildParameter, usingWorkspacePath, secretKeyRef, TaskBuilder, TaskStepBuilder, valueFrom, WorkspaceBuilder, ParameterBuilder } from '../src'; /** * Using "ansible-runner" as the reference task that I want this test builder to @@ -35,8 +35,8 @@ class TestBasicTaskBuild extends Chart { .withName('run-playbook') .withImage(imageName) .withCommand(['entrypoint']) - .withArgs(['ansible-runner', 'run', buildParam('args'), buildParam('project-dir')]) - .withWorkingDir(buildWorkingDir('runner-dir'))) + .withArgs(['ansible-runner', 'run', usingBuildParameter('args'), usingBuildParameter('project-dir')]) + .withWorkingDir(usingWorkspacePath('runner-dir'))) .buildTask(); } } @@ -124,10 +124,6 @@ class TestIBMCloudSecretsManagerGet extends Chart { constructor(scope: Construct, id: string, props?: ChartProps) { super(scope, id, props); - // Build the task, using the https://github.com/tektoncd/catalog/blob/main/task/pull-request/0.1/pull-request.yaml - // as the example, just like with the `task.test.ts`. At some point, it would - // be nice to compare the snapshots with each other just to make sure that the - // builder does build the exact same object as the longer, non-builder method. new TaskBuilder(this, 'ibmcloud-secrets-manager-get') .withName('ibmcloud-secrets-manager-get') .withLabel('app.kubernetes.io/version', '0.1') @@ -140,9 +136,13 @@ class TestIBMCloudSecretsManagerGet extends Chart { .withStringParam(new ParameterBuilder('KEY_ID') .withDefaultValue('968d7819-f2c5-7b67-c420-3c6bfd51521e') .withDescription('An IBM Cloud Secrets Manager key ID')) + .withStringParam(new ParameterBuilder('SECRETS_MANAGER_ENDPOINT_URL') + .withDefaultValue('https://{instance_ID}.us-south.secrets-manager.appdomain.cloud') + .withDescription('An IBM Cloud Secrets Manager instance endpoint URL (https://cloud.ibm.com/apidocs/secrets-manager/secrets-manager-v2#endpoints)')) + .withResult('secret-value', ' A secret value retrieved using the provided KEY_ID') .withStep(new TaskStepBuilder().withName('retrieve-key') .withImage('quay.io/openshift/origin-cli:4.7') - .fromScriptUrl('test/files/retrieve-secret.sh')) + .fromScriptUrlToResults('test/files/retrieve-secret.sh', 'secret-value')) .buildTask(); } } @@ -178,7 +178,7 @@ class TestPullRequestTaskBuild extends Chart { .withName('pullrequest-init') .withImage('gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/pullrequest-init@sha256:69633ecd0e948f6462c61bb9e008b940a05b143ef51c67e6e4093278a23dac53') .withCommand(['/ko-app/pullrequest-init']) - .withEnv('AUTH_TOKEN', valueFrom(secretKeyRef(buildParam('secret-key-ref'), 'token'))) + .withEnv('AUTH_TOKEN', valueFrom(secretKeyRef(usingBuildParameter('secret-key-ref'), 'token'))) .withArgs([ '-url', '$(params.url)', @@ -203,7 +203,7 @@ describe('TaskBuilderTest', () => { const results = Testing.synth(chart); expect(results).toMatchSnapshot(); }); - test('TaskBuilderIBMSecretGet', () => { + test('TestIBMCloudSecretsManagerGet', () => { const app = Testing.app(); const chart = new TestIBMCloudSecretsManagerGet(app, 'test-get-secret'); const results = Testing.synth(chart); From 6d2897b1bb31d4d6afe3aa22d7456078a6af155d Mon Sep 17 00:00:00 2001 From: Nathan Good Date: Thu, 21 Dec 2023 08:54:40 -0600 Subject: [PATCH 2/3] re-generated artifacts Signed-off-by: Nathan Good --- API.md | 29 +++++++++++++++++++-- test/__snapshots__/taskbuilder.test.ts.snap | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 7767c2e..6e94a25 100644 --- a/API.md +++ b/API.md @@ -3109,7 +3109,7 @@ new TaskBuilder(scope: Construct, id: string) | withDescription | Sets the `description` of the `Task` being built. | | withLabel | Adds a label to the `Task` with the provided label key and value. | | withName | Sets the name of the `Task` being built. | -| withResult | Allows you to add an result to the Task. | +| withResult | Allows you to add a result to the Task. | | withStep | Adds the given `step` (`TaskStepBuilder`) to the `Task`. | | withStringParam | Adds a parameter of type string to the `Task`. | | withWorkspace | Adds the specified workspace to the `Task`. | @@ -3206,7 +3206,7 @@ Sets the name of the `Task` being built. public withResult(name: string, description: string): TaskBuilder ``` -Allows you to add an result to the Task. +Allows you to add a result to the Task. > [https://tekton.dev/docs/pipelines/tasks/#emitting-results](https://tekton.dev/docs/pipelines/tasks/#emitting-results) @@ -3410,6 +3410,7 @@ new TaskStepBuilder() | fromScriptData | If supplied, uses the provided script data as-is for the script value. | | fromScriptObject | If supplied, uses the cdk8s `ApiObject` supplied as the body of the `script` for the `Task`. | | fromScriptUrl | If supplied, uses the content found at the given URL for the `script` value of the step. | +| fromScriptUrlToResults | If supplied, uses the content found at the given URL for the `script` value of the step and writes its output to the `results`. | | withArgs | The args to use with the `command`. | | withCommand | The name of the command to use when running the `Step` of the `Task`. | | withEnv | *No description.* | @@ -3483,6 +3484,30 @@ If you supply this, do not supply a value for `fromScriptObject`. --- +##### `fromScriptUrlToResults` + +```typescript +public fromScriptUrlToResults(url: string, resultsName: string): TaskStepBuilder +``` + +If supplied, uses the content found at the given URL for the `script` value of the step and writes its output to the `results`. + +Use this as an +alternative to "heredoc", which is embedding hard-coded shell or other +scripts in the step. + +###### `url`Required + +- *Type:* string + +--- + +###### `resultsName`Required + +- *Type:* string + +--- + ##### `withArgs` ```typescript diff --git a/test/__snapshots__/taskbuilder.test.ts.snap b/test/__snapshots__/taskbuilder.test.ts.snap index be79ec6..dd7d060 100644 --- a/test/__snapshots__/taskbuilder.test.ts.snap +++ b/test/__snapshots__/taskbuilder.test.ts.snap @@ -283,7 +283,7 @@ exports[`TaskBuilderTest TestIBMCloudSecretsManagerGet 1`] = ` "env": undefined, "image": "quay.io/openshift/origin-cli:4.7", "name": "retrieve-key", - "script": "#!/usr/bin/env bash\\nset -x\\n\\n# Retrieves the IBM Cloud API Key configured in a \`deployer\` cluster\\n\\nexport IBMCLOUD_API_KEY=$(oc get secret ibm-secret -n kube-system -o jsonpath='{.data.apiKey}' | base64 -d)\\nexport AUTH_RESPONSE_JSON=$(curl -s -X POST \\\\n "https://iam.cloud.ibm.com/identity/token" \\\\n --header 'Content-Type: application/x-www-form-urlencoded' \\\\n --header 'Accept: application/json' \\\\n --data-urlencode 'grant_type=urn:ibm:params:oauth:grant-type:apikey' \\\\n --data-urlencode "apikey=\${IBMCLOUD_API_KEY}")\\nexport ACCESS_TOKEN=$(echo $AUTH_RESPONSE_JSON | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$')\\nexport SECRET_JSON=$(curl -s -X GET --location --header "Authorization: Bearer \${ACCESS_TOKEN}" --header "Accept: application/json" "$(params.SECRETS_MANAGER_ENDPOINT_URL)/api/v2/secrets/$(params.KEY_ID)")\\nexport SECRET=$(echo $SECRET_JSON | grep -o '"payload":"[^"]*' | grep -o '[^"]*$')\\nprintf "\${SECRET}"|tee $(results.secret-value.path)", + "script": "#!/usr/bin/env bash\\nset -x\\n\\n# Retrieves the IBM Cloud API Key configured in a \`deployer\` cluster\\n\\nexport IBMCLOUD_API_KEY=$(oc get secret ibm-secret -n kube-system -o jsonpath='{.data.apiKey}' | base64 -d)\\nexport AUTH_RESPONSE_JSON=$(curl -s -X POST \\\\n "https://iam.cloud.ibm.com/identity/token" \\\\n --header 'Content-Type: application/x-www-form-urlencoded' \\\\n --header 'Accept: application/json' \\\\n --data-urlencode 'grant_type=urn:ibm:params:oauth:grant-type:apikey' \\\\n --data-urlencode "apikey=\${IBMCLOUD_API_KEY}")\\nexport ACCESS_TOKEN=$(echo $AUTH_RESPONSE_JSON | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$')\\nexport SECRET_JSON=$(curl -s -X GET --location --header "Authorization: Bearer \${ACCESS_TOKEN}" --header "Accept: application/json" "$(params.SECRETS_MANAGER_ENDPOINT_URL)/api/v2/secrets/$(params.KEY_ID)")\\nexport SECRET=$(echo $SECRET_JSON | grep -o '"payload":"[^"]*' | grep -o '[^"]*$')\\nprintf "\${SECRET}"\\n|tee $(results.secret-value.path)", "workingDir": undefined, }, ], From 2b6435892f54533d6e07b851ae722aaaf9d9fb1e Mon Sep 17 00:00:00 2001 From: Nathan Good Date: Thu, 22 Feb 2024 10:30:47 -0700 Subject: [PATCH 3/3] Updated libraries and fixed spacing with tee in results. Signed-off-by: Nathan Good --- .github/workflows/build.yml | 6 +- .github/workflows/release.yml | 8 +- .github/workflows/upgrade-main.yml | 4 + .projen/deps.json | 8 +- .projenrc.ts | 5 +- package.json | 8 +- src/builders.ts | 2 +- test/__snapshots__/taskbuilder.test.ts.snap | 2 +- yarn.lock | 118 +++++++++++++------- 9 files changed, 107 insertions(+), 54 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5561d12..c4d39d2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,10 @@ jobs: with: ref: ${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.x - name: Install dependencies run: yarn install --check-files - name: build @@ -87,7 +91,7 @@ jobs: steps: - uses: actions/setup-node@v3 with: - node-version: 16.x + node-version: 18.x - name: Download build artifacts uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 17f5801..3866ce2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,6 +24,10 @@ jobs: run: |- git config user.name "github-actions" git config user.email "github-actions@github.com" + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.x - name: Install dependencies run: yarn install --check-files --frozen-lockfile - name: release @@ -51,7 +55,7 @@ jobs: steps: - uses: actions/setup-node@v3 with: - node-version: 16.x + node-version: 18.x - name: Download build artifacts uses: actions/download-artifact@v3 with: @@ -80,7 +84,7 @@ jobs: steps: - uses: actions/setup-node@v3 with: - node-version: 16.x + node-version: 18.x - name: Download build artifacts uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/upgrade-main.yml b/.github/workflows/upgrade-main.yml index 0e65db0..85db004 100644 --- a/.github/workflows/upgrade-main.yml +++ b/.github/workflows/upgrade-main.yml @@ -18,6 +18,10 @@ jobs: uses: actions/checkout@v3 with: ref: main + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.x - name: Install dependencies run: yarn install --check-files --frozen-lockfile - name: Upgrade dependencies diff --git a/.projen/deps.json b/.projen/deps.json index 22f60f4..956871a 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -29,7 +29,7 @@ }, { "name": "cdk8s", - "version": "2.30.0", + "version": "2.68.30", "type": "build" }, { @@ -77,12 +77,12 @@ }, { "name": "jsii-rosetta", - "version": "~5.0.0", + "version": "~5.2.0", "type": "build" }, { "name": "jsii", - "version": "~5.0.0", + "version": "~5.2.0", "type": "build" }, { @@ -113,7 +113,7 @@ }, { "name": "cdk8s", - "version": "^2.30.0", + "version": "^2.68.30", "type": "peer" }, { diff --git a/.projenrc.ts b/.projenrc.ts index 77f85d9..fd80ab7 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -5,8 +5,9 @@ const project = new cdk8s.ConstructLibraryCdk8s({ defaultReleaseBranch: 'main', author: 'Nathan Good', authorAddress: 'nathan.good@ibm.com', - cdk8sVersion: '2.30.0', - jsiiVersion: '~5.0.0', + cdk8sVersion: '2.68.30', + jsiiVersion: '~5.2.0', + workflowNodeVersion: '18.x', projenrcTs: true, peerDeps: [ 'cdk8s', diff --git a/package.json b/package.json index 9d232e0..51cf616 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@types/node": "^16", "@typescript-eslint/eslint-plugin": "^5", "@typescript-eslint/parser": "^5", - "cdk8s": "2.30.0", + "cdk8s": "2.68.30", "cdk8s-plus-27": "^2.7.5", "constructs": "10.0.0", "eslint": "^8", @@ -48,11 +48,11 @@ "eslint-plugin-import": "^2.28.0", "jest": "^29.6.2", "jest-junit": "^15", - "jsii": "~5.0.0", + "jsii": "~5.2.0", "jsii-diff": "^1.86.1", "jsii-docgen": "^9.1.2", "jsii-pacmak": "^1.86.1", - "jsii-rosetta": "~5.0.0", + "jsii-rosetta": "~5.2.0", "npm-check-updates": "^16", "projen": "^0.72.7", "standard-version": "^9", @@ -61,7 +61,7 @@ "typescript": "^5.1.6" }, "peerDependencies": { - "cdk8s": "^2.30.0", + "cdk8s": "^2.68.30", "constructs": "^10.0.0" }, "keywords": [ diff --git a/src/builders.ts b/src/builders.ts index bd48823..639d054 100644 --- a/src/builders.ts +++ b/src/builders.ts @@ -318,7 +318,7 @@ class UrlScriptToResultsResolver implements ScriptResolver { } public scriptData(): string { - return [this._resolver.scriptData(), `tee ${usingResultsPath(this._resultsName)}`].join('|'); + return [this._resolver.scriptData(), `tee ${usingResultsPath(this._resultsName)}`].join(' | '); } } diff --git a/test/__snapshots__/taskbuilder.test.ts.snap b/test/__snapshots__/taskbuilder.test.ts.snap index dd7d060..663a4a1 100644 --- a/test/__snapshots__/taskbuilder.test.ts.snap +++ b/test/__snapshots__/taskbuilder.test.ts.snap @@ -283,7 +283,7 @@ exports[`TaskBuilderTest TestIBMCloudSecretsManagerGet 1`] = ` "env": undefined, "image": "quay.io/openshift/origin-cli:4.7", "name": "retrieve-key", - "script": "#!/usr/bin/env bash\\nset -x\\n\\n# Retrieves the IBM Cloud API Key configured in a \`deployer\` cluster\\n\\nexport IBMCLOUD_API_KEY=$(oc get secret ibm-secret -n kube-system -o jsonpath='{.data.apiKey}' | base64 -d)\\nexport AUTH_RESPONSE_JSON=$(curl -s -X POST \\\\n "https://iam.cloud.ibm.com/identity/token" \\\\n --header 'Content-Type: application/x-www-form-urlencoded' \\\\n --header 'Accept: application/json' \\\\n --data-urlencode 'grant_type=urn:ibm:params:oauth:grant-type:apikey' \\\\n --data-urlencode "apikey=\${IBMCLOUD_API_KEY}")\\nexport ACCESS_TOKEN=$(echo $AUTH_RESPONSE_JSON | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$')\\nexport SECRET_JSON=$(curl -s -X GET --location --header "Authorization: Bearer \${ACCESS_TOKEN}" --header "Accept: application/json" "$(params.SECRETS_MANAGER_ENDPOINT_URL)/api/v2/secrets/$(params.KEY_ID)")\\nexport SECRET=$(echo $SECRET_JSON | grep -o '"payload":"[^"]*' | grep -o '[^"]*$')\\nprintf "\${SECRET}"\\n|tee $(results.secret-value.path)", + "script": "#!/usr/bin/env bash\\nset -x\\n\\n# Retrieves the IBM Cloud API Key configured in a \`deployer\` cluster\\n\\nexport IBMCLOUD_API_KEY=$(oc get secret ibm-secret -n kube-system -o jsonpath='{.data.apiKey}' | base64 -d)\\nexport AUTH_RESPONSE_JSON=$(curl -s -X POST \\\\n "https://iam.cloud.ibm.com/identity/token" \\\\n --header 'Content-Type: application/x-www-form-urlencoded' \\\\n --header 'Accept: application/json' \\\\n --data-urlencode 'grant_type=urn:ibm:params:oauth:grant-type:apikey' \\\\n --data-urlencode "apikey=\${IBMCLOUD_API_KEY}")\\nexport ACCESS_TOKEN=$(echo $AUTH_RESPONSE_JSON | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$')\\nexport SECRET_JSON=$(curl -s -X GET --location --header "Authorization: Bearer \${ACCESS_TOKEN}" --header "Accept: application/json" "$(params.SECRETS_MANAGER_ENDPOINT_URL)/api/v2/secrets/$(params.KEY_ID)")\\nexport SECRET=$(echo $SECRET_JSON | grep -o '"payload":"[^"]*' | grep -o '[^"]*$')\\nprintf "\${SECRET}"\\n | tee $(results.secret-value.path)", "workingDir": undefined, }, ], diff --git a/yarn.lock b/yarn.lock index cf02540..781b18c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -651,14 +651,6 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@jsii/check-node@1.85.0": - version "1.85.0" - resolved "https://registry.yarnpkg.com/@jsii/check-node/-/check-node-1.85.0.tgz#548d03f3f98d8b0edd9f4aeac7e128940dfd290d" - integrity sha512-dOrye7NuafkHADt3jk0TxMu/2sOHXxOYTwAuKj9L1/Te1xFfw2fzni80J12rTBQeVQxLVFNgDynsl2J7cuFFtQ== - dependencies: - chalk "^4.1.2" - semver "^7.5.1" - "@jsii/check-node@1.86.1": version "1.86.1" resolved "https://registry.yarnpkg.com/@jsii/check-node/-/check-node-1.86.1.tgz#ceffe3e06cf8208c2b5a16e60ff55faa72cd79a2" @@ -667,6 +659,14 @@ chalk "^4.1.2" semver "^7.5.4" +"@jsii/check-node@1.93.0": + version "1.93.0" + resolved "https://registry.yarnpkg.com/@jsii/check-node/-/check-node-1.93.0.tgz#3adcc6012654bb69fb8dc508e757b83ea9cd1708" + integrity sha512-NLn1Js6wEG2hYjH7gE5Q8s/hPlp3I+KhK/T8ykGdYVod7iODnk/0QVSZsk2iEyuw8NzvvgXUDBWreadUIWSz+g== + dependencies: + chalk "^4.1.2" + semver "^7.5.4" + "@jsii/spec@1.86.1", "@jsii/spec@^1.85.0", "@jsii/spec@^1.86.1": version "1.86.1" resolved "https://registry.yarnpkg.com/@jsii/spec/-/spec-1.86.1.tgz#0f8911f5d5cfb2606628f143ac7d195b7870c890" @@ -674,6 +674,13 @@ dependencies: ajv "^8.12.0" +"@jsii/spec@^1.93.0": + version "1.94.0" + resolved "https://registry.yarnpkg.com/@jsii/spec/-/spec-1.94.0.tgz#a4584179cd83e50110169a3f5ec1b6ab4ad362f4" + integrity sha512-ur1aUMPsdZgflUIZC4feyJzrkGYzvtiIJxRowkSxr7Ip/sLCKvi61dvImWtJY9ZhEAl7Kiq7I/R32WVyxW0JrQ== + dependencies: + ajv "^8.12.0" + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -1770,14 +1777,14 @@ cdk8s-plus-27@^2.7.5: optionalDependencies: backport "8.5.0" -cdk8s@2.30.0: - version "2.30.0" - resolved "https://registry.yarnpkg.com/cdk8s/-/cdk8s-2.30.0.tgz#a1e39dadc8cc163e8e02cca3753a1e7b5117c46e" - integrity sha512-v4tfvGI7TEb9YxrL31VAFsaZKDa9apxXaj/Cqja+0TAJJCXY25TibyVcxlpDXVY6tvxrUftjCFzLI1+VPQBw7Q== +cdk8s@2.68.30: + version "2.68.30" + resolved "https://registry.yarnpkg.com/cdk8s/-/cdk8s-2.68.30.tgz#08665698caf6f8154d9a38dd885c80c773ed15c2" + integrity sha512-/AdOwcSY2YOIoQ02l/580KLwjWaFfcM8aKgsfc6W6/rAWhaWHAtNCCQHjPCZjDKqjKHeQX/x7Z+3adTH/zo3Vw== dependencies: fast-json-patch "^3.1.1" follow-redirects "^1.15.2" - yaml "2.3.1" + yaml "2.3.2" optionalDependencies: backport "8.5.0" @@ -2847,6 +2854,17 @@ fast-glob@^3.2.9, fast-glob@^3.3.1: merge2 "^1.3.0" micromatch "^4.0.4" +fast-glob@^3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.2.tgz#a904501e57cfdd2ffcded45e99a54fef55e46129" + integrity sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow== + dependencies: + "@nodelib/fs.stat" "^2.0.2" + "@nodelib/fs.walk" "^1.2.3" + glob-parent "^5.1.2" + merge2 "^1.3.0" + micromatch "^4.0.4" + fast-json-patch@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/fast-json-patch/-/fast-json-patch-3.1.1.tgz#85064ea1b1ebf97a3f7ad01e23f9337e72c66947" @@ -4345,23 +4363,23 @@ jsii-rosetta@^1.86.1: workerpool "^6.4.0" yargs "^16.2.0" -jsii-rosetta@~5.0.0: - version "5.0.19" - resolved "https://registry.yarnpkg.com/jsii-rosetta/-/jsii-rosetta-5.0.19.tgz#b074890be221f6c5ff0060b9dfe5ad3ff23f79e9" - integrity sha512-dpM/N1HMsGszVWlpebgPFcJR3D/KZ+eI73a9jXUNxGZ62h6uS+lAf3MD8glKGyZSF/2FrhzzLICa5MjEDhDOHA== +jsii-rosetta@~5.2.0: + version "5.2.11" + resolved "https://registry.yarnpkg.com/jsii-rosetta/-/jsii-rosetta-5.2.11.tgz#7b8ccb229332674c3a4fc570850fb903c6fec62c" + integrity sha512-MtzCWfXX835kUc6sNnncXzpc5g88MdS+paWj3n97DnYnJQCl3OMxytkG1jjICJE0oxlrbvC44OiJb28+0jEmAg== dependencies: - "@jsii/check-node" "1.85.0" - "@jsii/spec" "^1.85.0" + "@jsii/check-node" "1.93.0" + "@jsii/spec" "^1.93.0" "@xmldom/xmldom" "^0.8.10" chalk "^4" commonmark "^0.30.0" - fast-glob "^3.3.1" - jsii "~5.0.5" + fast-glob "^3.3.2" + jsii "~5.2.5" semver "^7.5.4" - semver-intersect "^1.4.0" + semver-intersect "^1.5.0" stream-json "^1.8.0" - typescript "~5.0.4" - workerpool "^6.4.0" + typescript "~5.2.2" + workerpool "^6.5.1" yargs "^17.7.2" jsii@1.86.1: @@ -4383,23 +4401,23 @@ jsii@1.86.1: typescript "~3.9.10" yargs "^16.2.0" -jsii@~5.0.0, jsii@~5.0.5: - version "5.0.19" - resolved "https://registry.yarnpkg.com/jsii/-/jsii-5.0.19.tgz#dd5e9e6c566467679c28865bbe431cb09776e73a" - integrity sha512-3yjTeMhA11cNIAvppJ9SsLlr3zEr/1nTya9026wUraK73kqdS6mN1/pt6D42uvqYOZK63sVtIRPu1beipeYXBg== +jsii@~5.2.0, jsii@~5.2.5: + version "5.2.44" + resolved "https://registry.yarnpkg.com/jsii/-/jsii-5.2.44.tgz#7a768412f1a28f5f1ff3e92ab5f5b7e7430c3ae1" + integrity sha512-Z7sTqYzQ5yoJU/ie+svjqSzrOF5rl4pW/bojvCb/7MfJ+SaGqhMUQMxQGTfqmSvauME8JoVYqwMH89x6qreJ8A== dependencies: - "@jsii/check-node" "1.85.0" - "@jsii/spec" "^1.85.0" + "@jsii/check-node" "1.93.0" + "@jsii/spec" "^1.93.0" case "^1.6.3" chalk "^4" downlevel-dts "^0.11.0" fast-deep-equal "^3.1.3" log4js "^6.9.1" semver "^7.5.4" - semver-intersect "^1.4.0" + semver-intersect "^1.5.0" sort-json "^2.0.1" - spdx-license-list "^6.6.0" - typescript "~5.0.4" + spdx-license-list "^6.8.0" + typescript "~5.2" yargs "^17.7.2" json-buffer@3.0.1: @@ -5891,6 +5909,13 @@ semver-intersect@^1.4.0: dependencies: semver "^5.0.0" +semver-intersect@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/semver-intersect/-/semver-intersect-1.5.0.tgz#bb3aa0ea504935410d34cf15f49818d56906bd48" + integrity sha512-BDjWX7yCC0haX4W/zrnV2JaMpVirwaEkGOBmgRQtH++F1N3xl9v7k9H44xfTqwl+yLNNSbMKosoVSTIiJVQ2Pw== + dependencies: + semver "^6.3.0" + semver-utils@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/semver-utils/-/semver-utils-1.1.4.tgz#cf0405e669a57488913909fc1c3f29bf2a4871e2" @@ -5906,7 +5931,7 @@ semver@^6.0.0, semver@^6.3.0, semver@^6.3.1: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== -semver@^7.0.0, semver@^7.1.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.5.1, semver@^7.5.3, semver@^7.5.4: +semver@^7.0.0, semver@^7.1.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.5.3, semver@^7.5.4: version "7.5.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== @@ -6083,6 +6108,11 @@ spdx-license-list@^6.6.0: resolved "https://registry.yarnpkg.com/spdx-license-list/-/spdx-license-list-6.6.0.tgz#403e1807fd87ef2b4781677bc91896d23eaed4ea" integrity sha512-vLwdf9AWgdJQmG8cai2HKfkInFsliKaCCOwXmdVonClIhdURTX61KdDOoXC1qcQ7gDaZj+CUTcrMJeAdnCtrKA== +spdx-license-list@^6.8.0: + version "6.9.0" + resolved "https://registry.yarnpkg.com/spdx-license-list/-/spdx-license-list-6.9.0.tgz#5543abb3a15f985a12808f642a622d2721c372ad" + integrity sha512-L2jl5vc2j6jxWcNCvcVj/BW9A8yGIG02Dw+IUw0ZxDM70f7Ylf5Hq39appV1BI9yxyWQRpq2TQ1qaXvf+yjkqA== + split2@^3.0.0: version "3.2.2" resolved "https://registry.yarnpkg.com/split2/-/split2-3.2.2.tgz#bf2cf2a37d838312c249c89206fd7a17dd12365f" @@ -6614,10 +6644,10 @@ typescript@~3.9.10: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8" integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q== -typescript@~5.0.4: - version "5.0.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" - integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== +typescript@~5.2, typescript@~5.2.2: + version "5.2.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78" + integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w== uglify-js@^3.1.4: version "3.17.4" @@ -6867,6 +6897,11 @@ workerpool@^6.4.0: resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.4.0.tgz#f8d5cfb45fde32fa3b7af72ad617c3369567a462" integrity sha512-i3KR1mQMNwY2wx20ozq2EjISGtQWDIfV56We+yGJ5yDs8jTwQiLLaqHlkBHITlCuJnYlVRmXegxFxZg7gqI++A== +workerpool@^6.5.1: + version "6.5.1" + resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544" + integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA== + "wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" @@ -6962,7 +6997,12 @@ yallist@^4.0.0: resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== -yaml@2.3.1, yaml@^2.2.2: +yaml@2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.2.tgz#f522db4313c671a0ca963a75670f1c12ea909144" + integrity sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg== + +yaml@^2.2.2: version "2.3.1" resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==