Using restish
restish is a command-line client for REST APIs; it reads an API's OpenAPI file and builds one command per listed operation. The sections below cover connecting restish to pgEdge Starfleet Managed Database and running a command.
To follow this page, you need an access token; see Generating an Access Token.
Connecting to the Managed API
Install restish and point it at the Managed API's OpenAPI file.
-
Install restish with Homebrew:
brew install restishFor other installation methods, see the restish installation guide.
-
Verify the installation:
restish --version -
Connect restish to the Managed API:
restish api connect managed https://api.pgedge.com \ --spec https://api.pgedge.com/managed/v1/openapi.jsonThis step saves a profile named
managed.
Authenticating restish
Each request needs a bearer token; set the profile to read it from
PGEDGE_TOKEN rather than storing it directly.
export PGEDGE_TOKEN="<access-token>"
restish api set managed \
'profiles.default.auth: {type: bearer, params: {token: env:PGEDGE_TOKEN}}'
Because the token is short-lived, exporting it for the current shell session is fine. Avoid keeping the token in a shell profile file.
The access token expires after the seconds given in expires_in.
Repeat the steps in
Generating an Access Token to
get a new token.
Running a Command
Each command's name comes from its operationId. The following table
displays how an operationId maps to its restish command:
| operationId | Command |
|---|---|
ListManagedDatabases |
list-managed-databases |
GetManagedDatabase |
get-managed-database |
UpdateManagedDatabase |
update-managed-database |
List every database the token's client can reach:
restish managed list-managed-databases
Updating a Database from a File
-
List your databases and note the
idof the one to update:restish managed list-managed-databases -
Write the fields to change to a file, named for the database.
cat > orders-db.json <<'EOF' { "display_name": "Production Orders DB", "deletion_protection": true } EOFAny field left out of the file keeps its current value.
-
Apply the file against that database's
id.restish managed update-managed-database <database-id> < orders-db.json