From 86ae2302614d26be5dff7fc66ac91e87178cce76 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 20:30:58 -0700 Subject: [PATCH] refactored existing tests to use #TransformSecret Signed-off-by: Richard Jones --- tests/tasks/build/build_auth.cue | 36 ++++++++++++++++++---------- tests/tasks/gitpull/private_repo.cue | 20 ++++++++++++---- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/tests/tasks/build/build_auth.cue b/tests/tasks/build/build_auth.cue index 79d2fa05..d7505a0d 100644 --- a/tests/tasks/build/build_auth.cue +++ b/tests/tasks/build/build_auth.cue @@ -2,26 +2,38 @@ package testing import ( "dagger.io/dagger/engine" + "encoding/yaml" ) engine.#Plan & { inputs: { directories: testdata: path: "./testdata" - secrets: dockerHubToken: command: { + secrets: sops: command: { name: "sops" - args: ["exec-env", "../../secrets_sops.yaml", "echo $DOCKERHUB_TOKEN"] + args: ["-d", "../../secrets_sops.yaml"] } } - actions: build: engine.#Build & { - source: inputs.directories.testdata.contents - auth: [{ - target: "daggerio/ci-test:private-pull" - username: "daggertest" - secret: inputs.secrets.dockerHubToken.contents - }] - dockerfile: contents: """ - FROM daggerio/ci-test:private-pull@sha256:c74f1b1166784193ea6c8f9440263b9be6cae07dfe35e32a5df7a31358ac2060 - """ + actions: { + dockerHubToken: engine.#TransformSecret & { + input: inputs.secrets.sops.contents + #function: { + input: _ + output: yaml.Unmarshal(input).DOCKERHUB_TOKEN + } + } + + build: engine.#Build & { + source: inputs.directories.testdata.contents + auth: [{ + target: "daggerio/ci-test:private-pull" + username: "daggertest" + + secret: dockerHubToken.output + }] + dockerfile: contents: """ + FROM daggerio/ci-test:private-pull@sha256:c74f1b1166784193ea6c8f9440263b9be6cae07dfe35e32a5df7a31358ac2060 + """ + } } } diff --git a/tests/tasks/gitpull/private_repo.cue b/tests/tasks/gitpull/private_repo.cue index 028852a2..b9b84dc1 100644 --- a/tests/tasks/gitpull/private_repo.cue +++ b/tests/tasks/gitpull/private_repo.cue @@ -1,24 +1,36 @@ package main -import "dagger.io/dagger/engine" +import ( + "encoding/yaml" + "dagger.io/dagger/engine" +) engine.#Plan & { - inputs: secrets: token: command: { + inputs: secrets: sops: command: { name: "sops" - args: ["exec-env", "../../secrets_sops.yaml", "echo $TestPAT"] + args: ["-d", "../../secrets_sops.yaml"] } actions: { + alpine: engine.#Pull & { source: "alpine:3.15.0" } + repoPassword: engine.#TransformSecret & { + input: inputs.secrets.sops.contents + #function: { + input: _ + output: yaml.Unmarshal(input).TestPAT + } + } + testRepo: engine.#GitPull & { remote: "https://github.com/dagger/dagger.git" ref: "main" auth: { username: "dagger-test" - password: inputs.secrets.token.contents + password: repoPassword.output } }