From 2c278edbd5ad44639b5a245bd972e1f8686d5d8c Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Tue, 8 Oct 2024 23:40:20 +0200 Subject: [PATCH] chore(dblab): curl the apis to achieve greatness --- knowledge base/dblab.md | 52 ++++++++++++++++++++++++++++++++++++++--- snippets/dblab.fish | 30 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 snippets/dblab.fish diff --git a/knowledge base/dblab.md b/knowledge base/dblab.md index 04f3994..3cf23c8 100644 --- a/knowledge base/dblab.md +++ b/knowledge base/dblab.md @@ -31,24 +31,69 @@ dblab instance status # Create clones. dblab clone create --username 'dblab_user_1' --password 'secret_password' --id 'my_first_clone' +curl -X 'POST' 'https://dblab.instance.fqdn/api/clone' -H 'Verification-Token: verification-token-here' \ + -H 'accept: application/json' -H 'content-type: application/json' \ + -d '{ "protected": true, "db": { "username": "user", "password": "password", "db_name": "db" }, "id": "clone-id" }' + +# Get clones' information. +curl -X 'GET' 'https://dblab.instance.fqdn/api/clone/clone-id' -H 'Verification-Token: verification-token-here' + +# Reset clones. +curl -X 'POST' 'https://dblab.instance.fqdn/api/clone/clone-id/reset' -H 'Verification-Token: verification-token-here' \ + -H 'accept: application/json' -H 'content-type: application/json' \ + -d '{ "latest": true }' +curl -X 'POST' 'https://dblab.instance.fqdn/api/clone/clone-id/reset' -H 'Verification-Token: verification-token-here' \ + -H 'accept: application/json' -H 'content-type: application/json' \ + -d '{ "latest": false, "snapshotID": "2024-09-09T12:12:13Z" }' + +# Change clones' properties. +curl -X 'PATCH' 'https://dblab.instance.fqdn/api/clone/clone-id' -H 'Verification-Token: verification-token-here' \ + -H 'accept: application/json' -H 'content-type: application/json' \ + -d '{ "protected": false }' + +# Delete clones. +curl -X 'DELETE' 'https://dblab.instance.fqdn/api/clone/clone-id/reset' -H 'Verification-Token: verification-token-here' ``` - ## Further readings - [Database Lab] - [Database Lab Client CLI reference (dblab)] +- [API reference] ### Sources @@ -65,7 +110,8 @@ dblab clone create --username 'dblab_user_1' --password 'secret_password' --id ' -[how to install and initialize database lab cli]: https://postgres.ai/docs/how-to-guides/cli/cli-install-init +[api reference]: https://dblab.readme.io/reference/ [database lab client cli reference (dblab)]: https://postgres.ai/docs/reference-guides/dblab-client-cli-reference +[how to install and initialize database lab cli]: https://postgres.ai/docs/how-to-guides/cli/cli-install-init diff --git a/snippets/dblab.fish b/snippets/dblab.fish new file mode 100644 index 0000000..7e69972 --- /dev/null +++ b/snippets/dblab.fish @@ -0,0 +1,30 @@ +#!/usr/bin/env fish + +# Create clones +curl -X 'POST' 'https://dblab.company.com:1234/api/clone' -H "Verification-Token: $(gopass show -o 'dblab')" \ + -H 'accept: application/json' -H 'content-type: application/json' \ + -d '{ + "id": "smth", + "protected": true, + "db": { + "username": "master", + "password": "ofPuppets", + "db_name": "puppet" + } + }' + +# Get clones' information +curl 'https://dblab.company.com:1234/api/clone/smth' -H "Verification-Token: $(gopass show -o 'dblab')" + +# Reset clones +curl -X 'POST' 'https://dblab.company.com:1234/api/clone/smth/reset' -H "Verification-Token: $(gopass show -o 'dblab')" \ + -H 'accept: application/json' -H 'content-type: application/json' \ + -d '{ "latest": true }' + +# Unprotect clones +curl -X 'PATCH' 'https://dblab.company.com:1234/api/clone/smth' -H "Verification-Token: $(gopass show -o 'dblab')" \ + -H 'accept: application/json' -H 'content-type: application/json' \ + -d '{ "protected": false }' + +# Delete clones +curl -X 'DELETE' 'https://dblab.company.com:1234/api/clone/smth' -H "Verification-Token: $(gopass show -o 'dblab')"