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

Added option for configuration file #28

Closed
wants to merge 9 commits into from
Closed

Added option for configuration file #28

wants to merge 9 commits into from

Conversation

mjavier2k
Copy link
Owner

  • added option to use config.yaml
  • updated README.md

@mjavier2k mjavier2k marked this pull request as draft July 2, 2020 01:20
@mjavier2k
Copy link
Owner Author

implements #25

Copy link
Collaborator

@neufeldtech neufeldtech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do the settings from viper get bound to the config variables?

@mjavier2k
Copy link
Owner Author

mjavier2k commented Jul 2, 2020

When viper.ReadInConfig() is called, it reads the config file which has the same key as whats on https://github.com/mjavier2k/solidfire-exporter/blob/master/pkg/solidfire/types.go#L8-L14

that becomes the default values for those KV pair which can be override by either flags or env.

@neufeldtech
Copy link
Collaborator

What I meant is that we're not doing any 'reading' of the viper config anywhere after it exists, i.e. viper.Get("endpoint")
We also need to consider the order of operations in terms of if flags will override the config file, etc. Viper could provide some help with this if we adopt the viper-native approach. If we're making breaking changes to the configuration anyway (by removing the option of passing username/password on the CLI via a flag), then we might as well adopt the viper-native approach where it can automatically 'detect' environment variables based on our go variable names, and automatically handle config file and flag order of operations.

@neufeldtech
Copy link
Collaborator

My Bad - I forgot that we are already using viper, so your config file pattern just magically works

Username: viper.GetString(UsernameFlag),
Password: viper.GetString(PasswordFlag),
RPCEndpoint: viper.GetString(EndpointFlag),

@neufeldtech
Copy link
Collaborator

Do we want to drop support for passing in username/password as flags?

@mjavier2k
Copy link
Owner Author

Yeah, lets drop that support. i'll remove the username/password option on the command line flag

@neufeldtech
Copy link
Collaborator

neufeldtech commented Jul 8, 2020

Is there a need for a config flag for the config file itself?
I.e.

-c "path to config.yaml file" (Default ./something.yaml)

@@ -36,12 +36,26 @@ func init() {
} else {
viper.BindEnv(solidfire.ListenPortFlag, solidfire.ListenPortFlagEnv)
}

viper.BindEnv(solidfire.UsernameFlag, solidfire.UsernameFlagEnv)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove these here, can we still pass username/password through an environment variable?
As I recall, we want to support username and password via an Environment variable or config file, but want to drop support for having them as command-line flags.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. thats what we want here. going to update this.

@@ -12,9 +12,10 @@ var (
EndpointFlag = "endpoint"
InsecureSSLFlag = "insecure"
HTTPClientTimeoutFlag = "timeout"
ListenPortFlagEnv = "SOLIDFIRE_PORT"
ConfigFileFlag = "config.yaml"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the flag name not the flag's default value.

You probably meant this to be as such:

Suggested change
ConfigFileFlag = "config.yaml"
ConfigFileFlag = "config"

@mjavier2k mjavier2k closed this Oct 19, 2020
@mjavier2k mjavier2k deleted the config.yml branch December 4, 2020 02:23
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

Successfully merging this pull request may close these issues.

None yet

2 participants