From 40a4e0869afcce0c9e3a0e5d182d3f47b924a974 Mon Sep 17 00:00:00 2001 From: Philipp Defner Date: Thu, 21 Mar 2024 21:00:01 +0900 Subject: [PATCH] Small wording and formatting changes, moved Getenv inline --- README.md | 11 +++++------ job.go | 15 ++++++--------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5e273832..d6f9fe10 100644 --- a/README.md +++ b/README.md @@ -215,13 +215,12 @@ LOGLEVEL=info ./sql_exporter Database specific configurations -------------------------------- -For some database backends some special functionality is available : +For some database backends some special functionality is available: -* cloudsql-postgres: a special `*` caracter can be used to query all databases - accessible by the account -* cloudsql-mysql : same as above -* rds-postgres : this type of URL expects a working AWS configuration - which will use action the equivalent of `rds generate-db-auth-token` +* cloudsql-postgres: A special `*` character can be used to query all databases accessible by the account +* cloudsql-mysql: Same as above +* rds-postgres: This type of URL expects a working AWS configuration + which will use the equivalent of `rds generate-db-auth-token` for the password. For this driver, the `AWS_REGION` environment variable must be set. diff --git a/job.go b/job.go index b737a261..a1d8ac6f 100644 --- a/job.go +++ b/job.go @@ -225,22 +225,19 @@ func (j *Job) updateConnections() { continue } if strings.HasPrefix(conn, "rds-postgres://") { - // reuse postgres SQLDriver by stripping rds- from connexion URL after building the RDS - // authentication token + // Reuse Postgres driver by stripping "rds-" from connection URL after building the RDS authentication token conn = strings.TrimPrefix(conn, "rds-") - // FIXME - parsing twice the conn url to extract host & username u, err := url.Parse(conn) if err != nil { - level.Error(j.log).Log("msg", "Failed to parse URL", "url", conn, "err", err) - continue - } - region := os.Getenv("AWS_REGION") + level.Error(j.log).Log("msg", "failed to parse connection url", "url", conn, "err", err) + continue + } sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) - token, err := rdsutils.BuildAuthToken(u.Host, region, u.User.Username(), sess.Config.Credentials) + token, err := rdsutils.BuildAuthToken(u.Host, os.Getenv("AWS_REGION"), u.User.Username(), sess.Config.Credentials) if err != nil { - level.Error(j.log).Log("msg", "Failed to parse URL", "url", conn, "err", err) + level.Error(j.log).Log("msg", "failed to parse connection url", "url", conn, "err", err) continue } conn = strings.Replace(conn, "AUTHTOKEN", url.QueryEscape(token), 1)