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

Allow to substitute environment variables in configuration #2818

Open
ikatlinsky opened this issue Jun 2, 2023 · 0 comments
Open

Allow to substitute environment variables in configuration #2818

ikatlinsky opened this issue Jun 2, 2023 · 0 comments

Comments

@ikatlinsky
Copy link

Feature request

Please describe your feature

We need a way to dynamically configure dashboard users based on the environment variables. The current implementation of config parsing using Viper does not support such an ability, all values are read as they are, without mapping to the values of the corresponding environment variables.

Describe the solution you'd like

Allow using environment variables in config.yaml in the following format

authentication:
      users:
        - username: $ADMIN_USERNAME_ENV_KEY
          password: $ADMIN_PASSWORD_ENV_KEY

This can be achieved by using Viper decoder hooks

Decoder:

func substituteEnvironmentVariables() mapstructure.DecodeHookFuncKind {
	return func(
		f reflect.Kind,
		t reflect.Kind,
		data interface{}) (interface{}, error) {
		if f != reflect.String || t != reflect.String {
			return data, nil
		}

		return os.ExpandEnv(data.(string)), nil
	}
}

Using a decoder in Viper

viper.Unmarshal(&config, viper.DecodeHook(substituteEnvironmentVariables()))
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