Skip to content

Commit

Permalink
Small wording and formatting changes, moved Getenv inline
Browse files Browse the repository at this point in the history
  • Loading branch information
dewey committed Mar 21, 2024
1 parent c7792a0 commit 40a4e08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 6 additions & 9 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 40a4e08

Please sign in to comment.