Skip to content

Allow string parameter for withSecretVariable #5000

Closed as not planned
Closed as not planned

Description

@kpenfound

Currently, withSecretVariable takes a dagger.Secret. The dx for this looks like:

mysecret := client.SetSecret('my-var', 'secret value')

mycontainer := client.Container().From('alpine').WithSecretVariable('SECRET_ENV', mysecret)

I'm proposing we also have an option to pass a string instead of a dagger.Secret and skip the first step, like:

mycontainer := client.Container().From('alpine').WithSecretVariable('SECRET_ENV', 'secret value')

Thoughts?

Activity

  1. helderco commented on Apr 21, 2023

    @helderco
    Contributor

    Sounds good, but that would be the first case of a union. How would Go handle the value being string | Secret?

  2. helderco commented on Apr 21, 2023

    @helderco
    Contributor

    I know you can use interface{}, just wondering about the reference docs and IDE autocomplete.

    Screenshot 2023-04-21 at 19 43 12

  3. kpenfound commented on Apr 21, 2023

    @kpenfound
    ContributorAuthor

    Yeah good question. I'm not familiar enough with the current workarounds with interface{ string | Secret} for Go. Maybe a good DX docs-wise would be a separate function with different parameters

  4. helderco commented on Apr 21, 2023

    @helderco
    Contributor

    Oops, you can only use unions in return values, not in inputs. You'd need a struct/type with different fields for either string or Secret:

    type SecretValue struct {
        plain string
        secret *Secret
    }

    To do the logic in codegen instead is also a bit tricky:

    • You need custom code in each SDK to handle this specific case (and hardcoded to this specific Container.withSecretVariable field), if it's not coming from the API;
    • In Go, you could provide a variable that's neither type (since you'd have a secret interface{} argument) so how would you handle that error? WithSecretVariable doesn't return an error and we can't assume a panic, can we?

    So best solution is adding a variation of withSecretVariable but can't think of a good name.

    In any case, you also need to assume the secret name is the env variable name.

  5. self-assigned this
    on May 3, 2023
  6. removed their assignment
    on May 16, 2023
  7. added a commit that references this issue on Jul 14, 2023
    ec56928
  8. helderco commented on Jul 18, 2023

    @helderco
    Contributor

    As I said in my last comment, the only viable way to do this is to create another field as a convenience. However, as discussed in #5445 (comment), this doesn't seem worth it mainly for the following reasons:

    • Not much gain from the alternative convenience function.
    • Best to decouple secret creation from its usage.

    Example:

    ctr.WithSecretVariable("FOO", client.SetSecret("FOO", "bar"))
    
    // vs
    
    ctr.WithPlainSecretVariable("FOO", "bar")
  9. TomChv commented on Jul 26, 2023

    @TomChv
    Member

    @helderco Should I write a guide about it then? I closed the PR because it does not make sens anymore to work on it.

  10. helderco commented on Jul 26, 2023

    @helderco
    Contributor

    I also don't think it's worth a guide. Maybe adding a With util in the "using secrets" guide next to the example for getting a value from a host env var as a suggestion for "if you do this often" kind of thing, just as a reminder that you can make your own abstractions.

    Or as an optimization cookbook like https://docs.dagger.io/7442989/cookbook#add-multiple-environment-variables-to-a-container.

  11. TomChv commented on Aug 10, 2023

    @TomChv
    Member

    So should we close this issue @helderco ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions