From c8ceecbf553d4ff4f2c00f2f2612ed9cf374d698 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Fri, 14 Jul 2023 13:44:28 +0200 Subject: [PATCH] Pass basic auth flags for both API and Filesystem commands --- main.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 36c802b8b..2e4c78a37 100644 --- a/main.go +++ b/main.go @@ -61,10 +61,12 @@ var CLI struct { PrometheusBasicAuthPassword promconfig.Secret `default:"" help:"The HTTP basic authentication password"` } `cmd:"" help:"Runs Pyrra's API and UI."` Filesystem struct { - ConfigFiles string `default:"/etc/pyrra/*.yaml" help:"The folder where Pyrra finds the config files to use."` - PrometheusURL *url.URL `default:"http://localhost:9090" help:"The URL to the Prometheus to query."` - PrometheusFolder string `default:"/etc/prometheus/pyrra/" help:"The folder where Pyrra writes the generates Prometheus rules and alerts."` - GenericRules bool `default:"false" help:"Enabled generic recording rules generation to make it easier for tools like Grafana."` + ConfigFiles string `default:"/etc/pyrra/*.yaml" help:"The folder where Pyrra finds the config files to use."` + PrometheusURL *url.URL `default:"http://localhost:9090" help:"The URL to the Prometheus to query."` + PrometheusFolder string `default:"/etc/prometheus/pyrra/" help:"The folder where Pyrra writes the generates Prometheus rules and alerts."` + GenericRules bool `default:"false" help:"Enabled generic recording rules generation to make it easier for tools like Grafana."` + PrometheusBasicAuthUsername string `default:"" help:"The HTTP basic authentication username"` + PrometheusBasicAuthPassword promconfig.Secret `default:"" help:"The HTTP basic authentication password"` } `cmd:"" help:"Runs Pyrra's filesystem operator and backend for the API."` Kubernetes struct { MetricsAddr string `default:":8080" help:"The address the metric endpoint binds to."` @@ -94,19 +96,25 @@ func main() { ) var prometheusURL *url.URL + var basicAuthUsername string + var basicAuthPassword promconfig.Secret switch ctx.Command() { case "api": prometheusURL = CLI.API.PrometheusURL + basicAuthUsername = CLI.API.PrometheusBasicAuthUsername + basicAuthPassword = CLI.API.PrometheusBasicAuthPassword case "filesystem": prometheusURL = CLI.Filesystem.PrometheusURL + basicAuthUsername = CLI.Filesystem.PrometheusBasicAuthUsername + basicAuthPassword = CLI.Filesystem.PrometheusBasicAuthPassword default: prometheusURL, _ = url.Parse("http://localhost:9090") } roundTripper, err := promconfig.NewRoundTripperFromConfig(promconfig.HTTPClientConfig{ BasicAuth: &promconfig.BasicAuth{ - Username: CLI.API.PrometheusBasicAuthUsername, - Password: CLI.API.PrometheusBasicAuthPassword, + Username: basicAuthUsername, + Password: basicAuthPassword, }, BearerTokenFile: CLI.API.PrometheusBearerTokenPath, }, "pyrra")