Commit fafe437d authored by peter.oettig's avatar peter.oettig
Browse files

Fixed collision problem with environment variables

parent f7fff1cb
Pipeline #240917 passed with stages
in 2 minutes
0.4.0
\ No newline at end of file
0.4.1
\ No newline at end of file
......@@ -26,32 +26,32 @@ func CommonGlobalFlags(appName string, rootCmd *cobra.Command) {
viper.SetConfigName(appName)
rootCmd.PersistentFlags().SortFlags = false
//viper.SetConfigType("env")
rootCmd.PersistentFlags().StringP("config", "c", "", "Path to NETVS config file containing api token [NETDB_CONFIG_FILE, NETVS_CONFIG_FILE]")
rootCmd.PersistentFlags().StringP("config", "c", "", "Path to NETVS config file containing api token [NETDB_CONFIG_FILE, NETVS_CONFIG_FILE, ACME4NETVS_CONFIG]")
viper.MustBindEnv("config", "NETDB_CONFIG_FILE", "NETVS_CONFIG_FILE")
rootCmd.PersistentFlags().String("apiversion", DefaultAPIVersion, "NETDB API version (setting this is a last resort; should normally be set in this binary) [NETDB_API_VERSION, NETVS_API_VERSION]")
rootCmd.PersistentFlags().String("apiversion", DefaultAPIVersion, "NETDB API version (setting this is a last resort; should normally be set in this binary) [NETDB_API_VERSION, NETVS_API_VERSION, ACME4NETVS_APIVERSION]")
rootCmd.PersistentFlags().MarkHidden("apiversion")
viper.MustBindEnv("apiversion", "NETDB_API_VERSION", "NETVS_API_VERSION")
viper.SetDefault("apiversion", DefaultAPIVersion)
rootCmd.PersistentFlags().StringP("apikey", "a", "", "NETDB API token string [NETDB_API_TOKEN, NETVS_API_TOKEN]")
viper.MustBindEnv("apikey", "NETDB_API_TOKEN", "NETVS_API_TOKEN")
rootCmd.PersistentFlags().StringP("apitoken", "a", "", "NETDB API token string [NETDB_API_TOKEN, NETVS_API_TOKEN, ACME4NETVS_APITOKEN]")
viper.MustBindEnv("apitoken", "NETDB_API_TOKEN", "NETVS_API_TOKEN")
rootCmd.PersistentFlags().StringP("endpoint", "e", "", `Alternative NETVS API endpoint (either "prod|test|devel" or an existing section from netdb_client.ini) [NETDB_ENDPOINT, NETVS_ENDPOINT]`)
rootCmd.PersistentFlags().StringP("endpoint", "e", "", `Alternative NETVS API endpoint (either "prod|test|devel" or an existing section from netdb_client.ini) [NETDB_ENDPOINT, NETVS_ENDPOINT, ACME4NETVS_ENDPOINT]`)
viper.MustBindEnv("endpoint", "NETDB_ENDPOINT", "NETVS_ENDPOINT")
rootCmd.PersistentFlags().BoolP("quiet", "q", false, "Disable verbose output [QUIET]")
rootCmd.PersistentFlags().BoolP("quiet", "q", false, "Disable verbose output [ACME4NETVS_QUIET]")
viper.MustBindEnv("quiet", "QUIET")
}
func CommonDNSWaitFlags(rootCmd *cobra.Command) {
rootCmd.PersistentFlags().BoolP("dns-wait", "w", true, "Wait until challenge is propagated to all DNS servers [DNS_WAIT]")
rootCmd.PersistentFlags().BoolP("dns-wait", "w", true, "Wait until challenge is propagated to all DNS servers [ACME4NETVS_DNS_WAIT]")
viper.MustBindEnv("dns-wait", "DNS_WAIT")
rootCmd.PersistentFlags().Duration("dns-wait-timeout", time.Hour*12, "Time after which the DNS check will fail automatically [DNS_WAIT_TIMEOUT]")
rootCmd.PersistentFlags().Duration("dns-wait-timeout", time.Hour*12, "Time after which the DNS check will fail automatically [ACME4NETVS_DNS_WAIT_TIMEOUT]")
viper.MustBindEnv("dns-wait-timeout", "DNS_WAIT_TIMEOUT")
rootCmd.PersistentFlags().Duration("dns-wait-between", time.Second*10, "Time to wait between consecutive DNS checks [DNS_WAIT_BETWEEN]")
rootCmd.PersistentFlags().Duration("dns-wait-between", time.Second*10, "Time to wait between consecutive DNS checks [ACME4NETVS_DNS_WAIT_BETWEEN]")
viper.MustBindEnv("dns-wait-between", "DNS_WAIT_BETWEEN")
}
......@@ -64,6 +64,7 @@ func FinalizeViperSetup(rootCmd *cobra.Command) DebugPrintfFunc {
// bind settings to environment variables with the same name
viper.AutomaticEnv()
viper.SetEnvPrefix("acme4netvs")
// setup logging
log.SetFlags(log.Lshortfile | log.Ltime)
......
......@@ -123,7 +123,7 @@ test_certbot "NETVS Token from environment variable" "$domain_to_test"
test_dehydrated "NETVS Token from environment variable" "$domain_to_test"
unset NETDB_API_TOKEN
hook_options="--apikey $api_token"
hook_options="--apitoken $api_token"
test_certbot "NETVS Token from command line option" "$domain_to_test" "$hook_options"
test_dehydrated "NETVS Token from command line option" "$domain_to_test" "$hook_options"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment