1

Rotating Postgres and Redis credentials using the Heroku Toolbelt is very easy https://blog.heroku.com/archives/2012/7/17/rotate_database_credentials_on_heroku_postgres_

Ideally, I'd need to do this using the API. Is there a way? I can't install the toolbelt in my production environment and fall back to system or backticks to call it, because; ironically, it's running on Heroku.

EDIT: Actually, there is a way to run the Toolbelt in Heroku using this buildpack, but I'd prefer to do it natively through the API.

bbonamin
  • 30,042
  • 7
  • 40
  • 49

2 Answers2

0

That platform API doesn't currently expose an endpoint for this. For now your choices are limited to the CLI/buildpack or via the dashboards for those respective data stores.

RangerRanger
  • 2,455
  • 2
  • 16
  • 36
0

There is no public API to do this.

However, it can be done...

First, you'll need the unique name of your database. You can look that up by it's attachment name/alias, which is usually DATABASE or HEROKU_POSTGRES_[COLOR] by default, or anything custom you might have assigned with heroku addons:{create,attach} --as NAME. Using an alias of DATABASE by default, here's how you might get it using curl and jq:

$ curl -H "Authorization: Bearer $API_KEY" \
       -H "Accept: application/vnd.heroku+json; version=3" \
       https://api.heroku.com/apps/$APP_NAME/addon-attachments/DATABASE \
  | jq .addon.name

  "postgresql-colorful-12345"

Then, assuming that name is saved stored in $DBNAME, you can rotate its credentials like so:

$ curl -X POST -u "x:$API_KEY" \
  https://$DOMAIN/client/v11/databases/$DBNAME/credentials_rotation

{"status":"ok","url":"[REDACTED]","message":"Password reset."}

$DOMAIN will be postgres-api.heroku.com for paid plans and postgres-starter-api.heroku.com for free/hobby plans, IIRC.

This API could change at any time though as it is considered a private API, so factor that into your decision to use it.

Bo Jeanes
  • 6,294
  • 4
  • 42
  • 39