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

CLI - Using templates for different envs #2832

Open
MMMahmoodian opened this issue Dec 3, 2024 · 0 comments
Open

CLI - Using templates for different envs #2832

MMMahmoodian opened this issue Dec 3, 2024 · 0 comments

Comments

@MMMahmoodian
Copy link

MMMahmoodian commented Dec 3, 2024

Feature description

In the export command in CLI we can pass --env=ENV to get desired env secrets but this doesn't work when we use --template. It would be nice if we could dynamically set envSlug in templates as well as other exports.

Why would it be useful?

First of all, it reduces unnecessary duplicate template files for each environment. Second, it makes the CLI tool more consistent.

Additional context

I have 2 ideas that require minimum effort to implement this.
1- Check if envStag is empty, then replace it with --env value. Here is a edited example from agent.go file

return func(projectID, envSlug, secretPath string, args ...string) ([]models.SingleEnvironmentVariable, error) {
		var parsedArguments secretArguments
                if envSlug == '' {
                    envSlug = globalEnvSlug // This can be either value set from --env or default env or env based on git branch
                }
		...

2- Add function to load values from env variables. This way users can implement if-else to set proper envStag. Here is an edited version from agent.go file.

	funcs := template.FuncMap{
		"secret":          secretFunction, // depreciated
		"listSecrets":     secretFunction,
		"dynamic_secret":  dynamicSecretFunction,
		"getSecretByName": getSingleSecretFunction,
		"minus": func(a, b int) int {
			return a - b
		},
		"add": func(a, b int) int {
			return a + b
		},
                "get_env": foo(name string) string {
			return load_from_env(name)
		},
	}

I'm open to contributing to this issue if you give me the green light on this feature.

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

No branches or pull requests

1 participant