#secret env var not found when trying to use .env file

1 messages ยท Page 1 of 1 (latest)

tepid horizon
#

Hey, I try to do the following:

echo "TEST=123" > .env
dagger -c 'container | from alpine | with-secret-variable FOO env://TEST | with-exec -- sh -c "echo secret is $FOO" | stdout'

and get
withExec sh -c 'echo secret is $FOO' 0.0s ERROR
! secret env var not found: "TES..."
โœ˜ .stdout: String! 0.0s ERROR
! invalid nil ref
secret env var not found: "TES..."
Time: 0h:00m:05s

How do I work together with .env files and secrets? If I just set a variable using export TEST= it works fine, but I would like to use .env files ๐Ÿ™‚

desert turret
tepid horizon
#

I saw the docs but I seem not to be able to get this running...

#

My actual use case is when using typescript.@desert turret
Code
`import { Secret, object, func, dag } from "@dagger.io/dagger"

@object()
export class Blueprints {
TEST: Secret

constructor(TEST: Secret) {
this.TEST = TEST
}
@func()
async test(): Promise<string> {
return await this.TEST.plaintext()
}

@func()
async testcon(): Promise<string> {
return dag
.container()
.from("curlimages/curl:latest")
.withSecretVariable("PASSWORD", this.TEST)
.withExec(["sh", "-c", "echo $PASSWORD"]).stdout()
}
} Here I get the following errors :12 : Blueprints.test: String!
13 : โ”† Secret.plaintext: String!
13 : โ”† Secret.plaintext ERROR [0.0s]
13 : โ”† ! secret env var not found: "123"
12 : Blueprints.test ERROR [2.9s]
12 : ! secret env var not found: "123"

user default: blueprints(test="123")
user default: blueprints(test="123")
Error: secret env var not found: "123" [traceparent:555b1476f2887e04428e22af3f6f362f-207ab952506c85f6]`

It clearly is able to resolve it somehow, but looks like its having a plain string and not a secret...

desert turret
#

If you put TEST=123 in your .env file that's just a plaintext value, it's not a secret

#

You'll want to use env:// file:// or cmd:// in your .env

#

For example, I pass aws creds like this: MODULENAME_AWSACCESSKEYID=env://AWS_ACCESS_KEY_ID

tepid horizon
#

but then the .env file is just pointing to the actual environment variable? So i need to set a environment variable? My goal was to not set environment variables but specify them in the .env file...

desert turret
#

Well if you paste secrets into your .env they're not secret, they're just env vars

tepid horizon
#

well if i have them in my env vars are there that much more secret? ๐Ÿ˜„

#

i wouldnt say so

desert turret
#

๐Ÿคทโ€โ™‚๏ธ

#

Plaintext -> EnvironmentVariable, secret accessor -> Secret

runic raptor
#

As mentioned by @desert turret , if you want to hardcode a string that lives in the .env file, you need to make your function argument take a string type and not a Secret

tepid horizon
#

okay, thanks for clarifying think it would help having that in the docs