You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow string parameter for withSecretVariable #5000
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
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.
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.
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.
Activity
helderco commentedon Apr 21, 2023
Sounds good, but that would be the first case of a union. How would Go handle the value being
string | Secret?helderco commentedon Apr 21, 2023
I know you can use
interface{}, just wondering about the reference docs and IDE autocomplete.kpenfound commentedon Apr 21, 2023
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 parametershelderco commentedon Apr 21, 2023
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:To do the logic in codegen instead is also a bit tricky:
Container.withSecretVariablefield), if it's not coming from the API;secret interface{}argument) so how would you handle that error?WithSecretVariabledoesn't return an error and we can't assume a panic, can we?So best solution is adding a variation of
withSecretVariablebut can't think of a good name.In any case, you also need to assume the secret name is the env variable name.
feat: add withPlainSecretVariable
helderco commentedon Jul 18, 2023
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:
Example:
TomChv commentedon Jul 26, 2023
@helderco Should I write a guide about it then? I closed the PR because it does not make sens anymore to work on it.
helderco commentedon Jul 26, 2023
I also don't think it's worth a guide. Maybe adding a
Withutil 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.
TomChv commentedon Aug 10, 2023
So should we close this issue @helderco ?