Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🍀 Proposal: Support different types of variables in yaml such as env #1211

Closed
aFlyBird0 opened this issue Oct 31, 2022 · 0 comments
Closed
Labels
enhancement New feature or request

Comments

@aFlyBird0
Copy link
Member

What Would You Like to Add? Why Is This Needed?

Now, we already have a way to render variables in yaml like this:

image

However, sometimes we can't write the original configuration to the yaml file because of data sensitivity, or for some other reason.

For example, when we want to access GITHUB_TOKEN, we will read it from the environment variable. But the problem is that we just tell the user "need to set this environment variable" in the plugin documentation, and we don't write the name in the yaml file, which will cause trouble for the user.

Also, the current environment variables are hard-coded in the code, which can cause difficulties if the user's own environment variables conflict.

Design

Support different types of variables in yaml.

Since we have already used go template to render configs, why not use more features of go template.

We could use [FuncMap](https://pkg.go.dev/text/template#FuncMap) to define custom functions such as env.

e.g.

githubToken: [[ env "GITHUB_TOKEN" ]] # env is a custom function defined by dtm

Furthermore, we could validate all env as soon as configs were loaded to avoid the plugin from running halfway prompting that “the environment variable is not configured”

Anything else

There are times when we may use logic: "takes the first data that is not empty".

For example, first from the output of the previous plugin, then from the environment variable, and then from K8s' Secret. (Getting data from K8s' Secret can also be defined as a go template custom function)

We should consider this at a later stage. Either define a new "use the first data that is not empty" function, or not support this complex definition in the configuration function and write the logic in the code and tell the user our fetching strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants