From 4073edbfcbad3fef2ef608ab57db77eed75c0267 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 22 Nov 2023 18:31:40 +0100 Subject: [PATCH 01/15] api-v1 initial commit --- build.gradle | 8 ++++---- garage | 2 +- garage-admin-sdk-golang | 2 +- garage-admin-sdk-js | 2 +- garage-admin-sdk-python | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 3863d3a..4114582 100644 --- a/build.gradle +++ b/build.gradle @@ -3,13 +3,13 @@ plugins { } task validate(type: org.openapitools.generator.gradle.plugin.tasks.ValidateTask){ - inputSpec = "./garage/doc/api/garage-admin-v0.yml" + inputSpec = "./garage/doc/api/garage-admin-v1.yml" recommend = true } task buildPythonClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { generatorName = "python" - inputSpec = "./garage/doc/api/garage-admin-v0.yml" + inputSpec = "./garage/doc/api/garage-admin-v1.yml" outputDir = "$rootDir/garage-admin-sdk-python" gitHost = "git.deuxfleurs.fr" gitUserId = "garage-sdk" @@ -23,7 +23,7 @@ task buildPythonClient(type: org.openapitools.generator.gradle.plugin.tasks.Gene task buildGoClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { generatorName = "go" - inputSpec = "./garage/doc/api/garage-admin-v0.yml" + inputSpec = "./garage/doc/api/garage-admin-v1.yml" outputDir = "$rootDir/garage-admin-sdk-golang" gitHost = "git.deuxfleurs.fr" gitUserId = "garage-sdk" @@ -36,7 +36,7 @@ task buildGoClient(type: org.openapitools.generator.gradle.plugin.tasks.Generate task buildJavascriptClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { generatorName = "javascript" - inputSpec = "./garage/doc/api/garage-admin-v0.yml" + inputSpec = "./garage/doc/api/garage-admin-v1.yml" outputDir = "$rootDir/garage-admin-sdk-js" gitHost = "git.deuxfleurs.fr" gitUserId = "garage-sdk" diff --git a/garage b/garage index 30f1636..3684c29 160000 --- a/garage +++ b/garage @@ -1 +1 @@ -Subproject commit 30f1636a00ffc60d1c9ac1d3781ccee21669e54d +Subproject commit 3684c29ad05458500b154428bfec6a8c15b2cdef diff --git a/garage-admin-sdk-golang b/garage-admin-sdk-golang index c965fe7..bdb4b9b 160000 --- a/garage-admin-sdk-golang +++ b/garage-admin-sdk-golang @@ -1 +1 @@ -Subproject commit c965fe7f7dc93b9b9a65ec4015c4e7ede0f6121b +Subproject commit bdb4b9b29f5bef65fe7e700baa61d60aa9ee7294 diff --git a/garage-admin-sdk-js b/garage-admin-sdk-js index 635d3c1..c31d1d0 160000 --- a/garage-admin-sdk-js +++ b/garage-admin-sdk-js @@ -1 +1 @@ -Subproject commit 635d3c1517482099289de1e01c21877b4659208e +Subproject commit c31d1d046f91ec0f67d661ef881a2d572f3e374a diff --git a/garage-admin-sdk-python b/garage-admin-sdk-python index f48df53..715450c 160000 --- a/garage-admin-sdk-python +++ b/garage-admin-sdk-python @@ -1 +1 @@ -Subproject commit f48df53ba21b9b544a503801fe0762c70bd1a5ae +Subproject commit 715450cfe62f67f2957ed5026505750ca2bf8a1a -- 2.45.2 From 1428c6d627fd81d706be98035d50ff873d58036d Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 22 Nov 2023 18:49:08 +0100 Subject: [PATCH 02/15] partially fix python examples --- README.md | 6 +++--- build.gradle | 6 +++--- example/python/configure_single_node.py | 13 +++++++------ example/python/requirements.txt | 2 +- example/python/short.py | 11 ++++++----- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2adaf2a..f7329b9 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ from garage_admin_sdk.apis import * from garage_admin_sdk.models import * configuration = garage_admin_sdk.Configuration( - host = "http://localhost:3903/v0", + host = "http://localhost:3903/v1", access_token = "s3cr3t" ) @@ -108,9 +108,9 @@ npm install --save git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js. A short example: ```javascript -const garage = require('garage_administration_api_v0garage_v0_8_0'); +const garage = require('garage_administration_api_v1garage_v0_9_0'); -const api = new garage.ApiClient("http://127.0.0.1:3903/v0"); +const api = new garage.ApiClient("http://127.0.0.1:3903/v1"); api.authentications['bearerAuth'].accessToken = "s3cr3t"; const [node, layout, key, bucket] = [ diff --git a/build.gradle b/build.gradle index 4114582..27f8048 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ task buildPythonClient(type: org.openapitools.generator.gradle.plugin.tasks.Gene gitRepoId = "garage-admin-sdk-python" configOptions = [ packageName: "garage_admin_sdk", - packageVersion: "0.8.0", + packageVersion: "0.9.0", projectName: "garage-admin-sdk-python" ] } @@ -30,7 +30,7 @@ task buildGoClient(type: org.openapitools.generator.gradle.plugin.tasks.Generate gitRepoId = "garage-admin-sdk-golang" configOptions = [ packageName: "garage", - packageVersion: "0.8.0" + packageVersion: "0.9.0" ] } @@ -46,7 +46,7 @@ task buildJavascriptClient(type: org.openapitools.generator.gradle.plugin.tasks. moduleName: "garage", npmName: "garage-admin-sdk-js", npmRepository: "@dxflrs/garage-admin-sdk-js", - packageVersion: "0.8.0", + packageVersion: "0.9.0", usePromises: "true", ] } diff --git a/example/python/configure_single_node.py b/example/python/configure_single_node.py index f9bb0d3..1a06b09 100644 --- a/example/python/configure_single_node.py +++ b/example/python/configure_single_node.py @@ -3,7 +3,7 @@ from garage_admin_sdk.apis import * from garage_admin_sdk.models import * configuration = garage_admin_sdk.Configuration( - host = "http://localhost:3903/v0", + host = "http://localhost:3903/v1", access_token = "s3cr3t" ) @@ -25,13 +25,14 @@ with garage_admin_sdk.ApiClient(configuration) as api_client: exit(1) print("it seems to be a fresh node, continuing the configuration") - layout.add_layout({ - status.node: NodeClusterInfo( + layout.add_layout([ + NodeRoleChange( + id = status.node, zone = "dc1", - capacity = 1, + capacity = 1000000000, tags = [ "dev" ], ) - }) + ]) print("added myself to the layout") current = layout.get_layout() @@ -63,7 +64,7 @@ with garage_admin_sdk.ApiClient(configuration) as api_client: print(f"key {kinfo.access_key_id} can now create buckets") # update key info - kinfo = keys.search_key("openapi") + kinfo = keys.search_key("openapi", show_secret_key=True) print(f"key permissions: {kinfo.permissions}") # ---- THE END --- diff --git a/example/python/requirements.txt b/example/python/requirements.txt index 3bd33b2..61267bb 100644 --- a/example/python/requirements.txt +++ b/example/python/requirements.txt @@ -1 +1 @@ -git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-python@f48df53 +git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-python@715450cfe6 diff --git a/example/python/short.py b/example/python/short.py index 9c82253..058175e 100644 --- a/example/python/short.py +++ b/example/python/short.py @@ -3,7 +3,7 @@ from garage_admin_sdk.apis import * from garage_admin_sdk.models import * configuration = garage_admin_sdk.Configuration( - host = "http://localhost:3903/v0", + host = "http://localhost:3903/v1", access_token = "s3cr3t" ) @@ -17,13 +17,14 @@ print(f"running garage {status.garage_version}, node_id {status.node}") # Change layout of this node current = layout.get_layout() -layout.add_layout({ - status.node: NodeClusterInfo( +layout.add_layout([ + NodeRoleChange( + id = status.node, zone = "dc1", - capacity = 1, + capacity = 1000000000, tags = [ "dev" ], ) -}) +]) layout.apply_layout(LayoutVersion( version = current.version + 1 )) -- 2.45.2 From f3cc4f21dc59a2c39af2ca72cc999f73134b97d7 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 22 Nov 2023 18:51:47 +0100 Subject: [PATCH 03/15] fix readme python code --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f7329b9..b0446e0 100644 --- a/README.md +++ b/README.md @@ -55,13 +55,14 @@ print(f"running garage {status.garage_version}, node_id {status.node}") # Change layout of this node current = layout.get_layout() -layout.add_layout({ - status.node: NodeClusterInfo( +layout.add_layout([ + NodeRoleChange( + id = status.node, zone = "dc1", - capacity = 1, + capacity = 1000000000, tags = [ "dev" ], ) -}) +]) layout.apply_layout(LayoutVersion( version = current.version + 1 )) -- 2.45.2 From 1c001906ac73da3103dea7be63dfc7c934a4dd48 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 22 Nov 2023 21:18:47 +0100 Subject: [PATCH 04/15] 2nd iteration --- example/python/configure_single_node.py | 4 ++-- example/python/requirements.txt | 2 +- garage | 2 +- garage-admin-sdk-golang | 2 +- garage-admin-sdk-js | 2 +- garage-admin-sdk-python | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/python/configure_single_node.py b/example/python/configure_single_node.py index 1a06b09..7a0e18d 100644 --- a/example/python/configure_single_node.py +++ b/example/python/configure_single_node.py @@ -56,7 +56,7 @@ with garage_admin_sdk.ApiClient(configuration) as api_client: # --- UPDATE KEY --- # not required here, just to demo the API - kinfo = keys.search_key("openapi") + kinfo = keys.get_key(search="openapi") allow_create = UpdateKeyRequestAllow(create_bucket=True) kreq = UpdateKeyRequest(allow=allow_create) @@ -64,7 +64,7 @@ with garage_admin_sdk.ApiClient(configuration) as api_client: print(f"key {kinfo.access_key_id} can now create buckets") # update key info - kinfo = keys.search_key("openapi", show_secret_key=True) + kinfo = keys.get_key(search="openapi", show_secret_key="true") print(f"key permissions: {kinfo.permissions}") # ---- THE END --- diff --git a/example/python/requirements.txt b/example/python/requirements.txt index 61267bb..df3b534 100644 --- a/example/python/requirements.txt +++ b/example/python/requirements.txt @@ -1 +1 @@ -git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-python@715450cfe6 +git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-python@e02326f5dbdf467c380663a7ecb14bcdfdc88149 diff --git a/garage b/garage index 3684c29..2d37e7f 160000 --- a/garage +++ b/garage @@ -1 +1 @@ -Subproject commit 3684c29ad05458500b154428bfec6a8c15b2cdef +Subproject commit 2d37e7fa391679ad4daa0725d2af9681e4dd9635 diff --git a/garage-admin-sdk-golang b/garage-admin-sdk-golang index bdb4b9b..f442d10 160000 --- a/garage-admin-sdk-golang +++ b/garage-admin-sdk-golang @@ -1 +1 @@ -Subproject commit bdb4b9b29f5bef65fe7e700baa61d60aa9ee7294 +Subproject commit f442d10b102d92ec22cf2ab1bde5b8c6d78a1f62 diff --git a/garage-admin-sdk-js b/garage-admin-sdk-js index c31d1d0..4e3e8ea 160000 --- a/garage-admin-sdk-js +++ b/garage-admin-sdk-js @@ -1 +1 @@ -Subproject commit c31d1d046f91ec0f67d661ef881a2d572f3e374a +Subproject commit 4e3e8ea9986e427f969ab31be116b7ed95ae8362 diff --git a/garage-admin-sdk-python b/garage-admin-sdk-python index 715450c..e02326f 160000 --- a/garage-admin-sdk-python +++ b/garage-admin-sdk-python @@ -1 +1 @@ -Subproject commit 715450cfe62f67f2957ed5026505750ca2bf8a1a +Subproject commit e02326f5dbdf467c380663a7ecb14bcdfdc88149 -- 2.45.2 From 6b641dd60739592374693c22996f522f0e4460f3 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 22 Nov 2023 21:28:55 +0100 Subject: [PATCH 05/15] Upgrade golang + javascript examples --- README.md | 2 +- example/golang/go.mod | 2 +- example/golang/go.sum | 2 ++ example/golang/main.go | 2 +- example/javascript/package-lock.json | 15 ++++++++------- example/javascript/package.json | 2 +- example/javascript/short.js | 4 ++-- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b0446e0..276dbd6 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ func main() { } // Process the response - fmt.Fprintf(os.Stdout, "Target hostname: %v\n", resp.KnownNodes[resp.Node].Hostname) + fmt.Fprintf(os.Stdout, "Target hostname: %v\n", resp.KnownNodes[0].Hostname) } ``` diff --git a/example/golang/go.mod b/example/golang/go.mod index 1085098..3793948 100644 --- a/example/golang/go.mod +++ b/example/golang/go.mod @@ -3,7 +3,7 @@ module garage-admin-example go 1.18 require ( - git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20221113145120-d012cff7c554 // indirect + git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231122201735-f442d10b102d // indirect github.com/golang/protobuf v1.4.2 // indirect golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 // indirect diff --git a/example/golang/go.sum b/example/golang/go.sum index bf5d193..7ab1662 100644 --- a/example/golang/go.sum +++ b/example/golang/go.sum @@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20221113145120-d012cff7c554 h1:GAQabea9CjkmQIDm4MxbG064enYVL69swewbjRfl5G8= git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20221113145120-d012cff7c554/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231122201735-f442d10b102d h1:GxlTiFj3WwYjULWp/MvW2iETmDf7TpOtEP2Qst2TkwU= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231122201735-f442d10b102d/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/example/golang/main.go b/example/golang/main.go index d2e9484..bdb862d 100644 --- a/example/golang/main.go +++ b/example/golang/main.go @@ -27,5 +27,5 @@ func main() { } // Process the response - fmt.Fprintf(os.Stdout, "Target hostname: %v\n", resp.KnownNodes[resp.Node].Hostname) + fmt.Fprintf(os.Stdout, "Target hostname: %v\n", resp.KnownNodes[0].Hostname) } diff --git a/example/javascript/package-lock.json b/example/javascript/package-lock.json index 1cd8476..2eeac16 100644 --- a/example/javascript/package-lock.json +++ b/example/javascript/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "garage_administration_api_v0garage_v0_8_0": "git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git" + "garage_administration_api_v1garage_v0_9_0": "git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git#4e3e8ea9986e427f969ab31be116b7ed95ae8362" } }, "node_modules/@ampproject/remapping": { @@ -736,9 +736,10 @@ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, - "node_modules/garage_administration_api_v0garage_v0_8_0": { - "version": "v0.8.0", - "resolved": "git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git#635d3c1517482099289de1e01c21877b4659208e", + "node_modules/garage_administration_api_v1garage_v0_9_0": { + "name": "garage_administration_api_v0garage_v0_9_0", + "version": "v0.9.0", + "resolved": "git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git#4e3e8ea9986e427f969ab31be116b7ed95ae8362", "license": "Unlicense", "dependencies": { "@babel/cli": "^7.0.0", @@ -1813,9 +1814,9 @@ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, - "garage_administration_api_v0garage_v0_8_0": { - "version": "git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git#635d3c1517482099289de1e01c21877b4659208e", - "from": "garage_administration_api_v0garage_v0_8_0@git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git", + "garage_administration_api_v1garage_v0_9_0": { + "version": "git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git#4e3e8ea9986e427f969ab31be116b7ed95ae8362", + "from": "garage_administration_api_v1garage_v0_9_0@git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git#4e3e8ea9986e427f969ab31be116b7ed95ae8362", "requires": { "@babel/cli": "^7.0.0", "superagent": "^5.3.0" diff --git a/example/javascript/package.json b/example/javascript/package.json index 68a0c82..bc36988 100644 --- a/example/javascript/package.json +++ b/example/javascript/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "dependencies": { - "garage_administration_api_v0garage_v0_8_0": "git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git" + "garage_administration_api_v1garage_v0_9_0": "git+https://git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-js.git#4e3e8ea9986e427f969ab31be116b7ed95ae8362" } } diff --git a/example/javascript/short.js b/example/javascript/short.js index 7de84ec..05b2856 100644 --- a/example/javascript/short.js +++ b/example/javascript/short.js @@ -1,6 +1,6 @@ -const garage = require('garage_administration_api_v0garage_v0_8_0'); +const garage = require('garage_administration_api_v1garage_v0_9_0'); -const api = new garage.ApiClient("http://127.0.0.1:3903/v0"); +const api = new garage.ApiClient("http://127.0.0.1:3903/v1"); api.authentications['bearerAuth'].accessToken = "s3cr3t"; const [node, layout, key, bucket] = [ -- 2.45.2 From 39ae8b7c755954b1fac485a080e4127da407ac9e Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 23 Nov 2023 08:58:26 +0100 Subject: [PATCH 06/15] fix query parameters for key --- garage | 2 +- garage-admin-sdk-golang | 2 +- garage-admin-sdk-js | 2 +- garage-admin-sdk-python | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/garage b/garage index 2d37e7f..814b3e1 160000 --- a/garage +++ b/garage @@ -1 +1 @@ -Subproject commit 2d37e7fa391679ad4daa0725d2af9681e4dd9635 +Subproject commit 814b3e11d4486b6d4c291b4e47b845521ddfb25c diff --git a/garage-admin-sdk-golang b/garage-admin-sdk-golang index f442d10..d89dcef 160000 --- a/garage-admin-sdk-golang +++ b/garage-admin-sdk-golang @@ -1 +1 @@ -Subproject commit f442d10b102d92ec22cf2ab1bde5b8c6d78a1f62 +Subproject commit d89dcefca5d0170cccc8d96c98e1c208549bd5f4 diff --git a/garage-admin-sdk-js b/garage-admin-sdk-js index 4e3e8ea..94a2301 160000 --- a/garage-admin-sdk-js +++ b/garage-admin-sdk-js @@ -1 +1 @@ -Subproject commit 4e3e8ea9986e427f969ab31be116b7ed95ae8362 +Subproject commit 94a2301408ad75d698266e835f7f125d31e0dc13 diff --git a/garage-admin-sdk-python b/garage-admin-sdk-python index e02326f..8fa1cac 160000 --- a/garage-admin-sdk-python +++ b/garage-admin-sdk-python @@ -1 +1 @@ -Subproject commit e02326f5dbdf467c380663a7ecb14bcdfdc88149 +Subproject commit 8fa1cac54f7d1f719161f5482f09663da6cb9cf8 -- 2.45.2 From 5cedde9b9fb6e0f732623b31221aef84d5aa5207 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 23 Nov 2023 10:29:26 +0100 Subject: [PATCH 07/15] golang example layout --- example/golang/go.mod | 2 +- example/golang/go.sum | 6 ++++++ example/golang/main.go | 30 ++++++++++++++++++++++++++++-- garage | 2 +- garage-admin-sdk-golang | 2 +- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/example/golang/go.mod b/example/golang/go.mod index 3793948..029bab5 100644 --- a/example/golang/go.mod +++ b/example/golang/go.mod @@ -3,7 +3,7 @@ module garage-admin-example go 1.18 require ( - git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231122201735-f442d10b102d // indirect + git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123092113-ffd9578e975e // indirect github.com/golang/protobuf v1.4.2 // indirect golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 // indirect diff --git a/example/golang/go.sum b/example/golang/go.sum index 7ab1662..5c79610 100644 --- a/example/golang/go.sum +++ b/example/golang/go.sum @@ -35,6 +35,12 @@ git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20221113145120-d012c git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20221113145120-d012cff7c554/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231122201735-f442d10b102d h1:GxlTiFj3WwYjULWp/MvW2iETmDf7TpOtEP2Qst2TkwU= git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231122201735-f442d10b102d/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123075451-d89dcefca5d0 h1:lhvMeTcFi72W1+nBg5LVueuFuNaP+2lIn+1Vg4yZvek= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123075451-d89dcefca5d0/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123090411-96f080c89ec4 h1:c7xX/UITgwb+7+m4uOB7BXg/pA+BB7EHhsXNMr8UMNY= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123090411-96f080c89ec4/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123092113-ffd9578e975e h1:C/D3P1+mWBTHiO3MeiNWB2S1AJ3A/m7OYGX4iS8nbtA= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123092113-ffd9578e975e/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/example/golang/main.go b/example/golang/main.go index bdb862d..7a2e4c7 100644 --- a/example/golang/main.go +++ b/example/golang/main.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "strings" garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang" ) @@ -22,10 +23,35 @@ func main() { // Send a request resp, r, err := client.NodesApi.GetNodes(ctx).Execute() if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `NodesApi.GetNodes``: %v\n", err) + fmt.Fprintf(os.Stderr, "Error when calling `NodesApi.GetNodes`\n") fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) } // Process the response - fmt.Fprintf(os.Stdout, "Target hostname: %v\n", resp.KnownNodes[0].Hostname) + fmt.Fprintf(os.Stdout, "First hostname: %v\n", resp.KnownNodes[0].Hostname) + + // Layout + capa := int64(1000000000) + change := []garage.NodeRoleChange{ + garage.NodeRoleChange{NodeRoleUpdate: &garage.NodeRoleUpdate { + Id: *resp.KnownNodes[0].Id, + Zone: "dc1", + Capacity: *garage.NewNullableInt64(&capa), + Tags: []string{ "fast", "amd64" }, + }}, + } + staged, r, err := client.LayoutApi.AddLayout(ctx).NodeRoleChange(change).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LayoutApi.AddLayout`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + msg, r, err := client.LayoutApi.ApplyLayout(ctx).LayoutVersion(*garage.NewLayoutVersion(staged.Version + 1)).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LayoutApi.ApplyLayout`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + fmt.Printf(strings.Join(msg.Message, "\n")) } diff --git a/garage b/garage index 814b3e1..68d23cc 160000 --- a/garage +++ b/garage @@ -1 +1 @@ -Subproject commit 814b3e11d4486b6d4c291b4e47b845521ddfb25c +Subproject commit 68d23cccdfc650cb8fa48fb2871ca4dfe7014d44 diff --git a/garage-admin-sdk-golang b/garage-admin-sdk-golang index d89dcef..ffd9578 160000 --- a/garage-admin-sdk-golang +++ b/garage-admin-sdk-golang @@ -1 +1 @@ -Subproject commit d89dcefca5d0170cccc8d96c98e1c208549bd5f4 +Subproject commit ffd9578e975e886d9075a4f2e710117893de8ac7 -- 2.45.2 From eb29f67298c42485b3b1a9d0421b3073e29f4a0c Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 23 Nov 2023 10:46:14 +0100 Subject: [PATCH 08/15] improve golang example --- example/golang/main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/example/golang/main.go b/example/golang/main.go index 7a2e4c7..47208b9 100644 --- a/example/golang/main.go +++ b/example/golang/main.go @@ -54,4 +54,33 @@ func main() { panic(err) } fmt.Printf(strings.Join(msg.Message, "\n")) + + // Key + // -- create + key := "openapi-key" + keyInfo, r, err := client.KeyApi.AddKey(ctx).AddKeyRequest(garage.AddKeyRequest{Name: *garage.NewNullableString(&key) }).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyApi.AddKey`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get()) + + // Bucket + // -- create + global_name := "global-ns-openapi-bucket" + local_name := "local-ns-openapi-bucket" + bucketInfo, r, err := client.BucketApi.CreateBucket(ctx).CreateBucketRequest(garage.CreateBucketRequest{ + GlobalAlias: &global_name, + LocalAlias: &garage.CreateBucketRequestLocalAlias { + AccessKeyId: keyInfo.AccessKeyId, + Alias: &local_name, + }, + }).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `BucketApi.CreateBucket`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + fmt.Printf("Bucket id: %s\n", *bucketInfo.Id) } -- 2.45.2 From 3fd7d34e50b671d3c8d89c6f19a075a0ba41e2c8 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 23 Nov 2023 10:47:43 +0100 Subject: [PATCH 09/15] various fixes --- garage-admin-sdk-js | 2 +- garage-admin-sdk-python | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/garage-admin-sdk-js b/garage-admin-sdk-js index 94a2301..f7b4e20 160000 --- a/garage-admin-sdk-js +++ b/garage-admin-sdk-js @@ -1 +1 @@ -Subproject commit 94a2301408ad75d698266e835f7f125d31e0dc13 +Subproject commit f7b4e20e4292883f1eaa5cd6cd5287aa550ff605 diff --git a/garage-admin-sdk-python b/garage-admin-sdk-python index 8fa1cac..8c3a7da 160000 --- a/garage-admin-sdk-python +++ b/garage-admin-sdk-python @@ -1 +1 @@ -Subproject commit 8fa1cac54f7d1f719161f5482f09663da6cb9cf8 +Subproject commit 8c3a7daa8a6d305dc0ee9082ce1f28682951e7b8 -- 2.45.2 From 53bf952a9e158cf7dbb46d94f3196876fd7f6840 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 Nov 2023 14:33:37 +0100 Subject: [PATCH 10/15] add cluster health to sdks --- example/golang/main.go | 16 ++++++++++++++++ garage | 2 +- garage-admin-sdk-golang | 2 +- garage-admin-sdk-js | 2 +- garage-admin-sdk-python | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/example/golang/main.go b/example/golang/main.go index 47208b9..6a56348 100644 --- a/example/golang/main.go +++ b/example/golang/main.go @@ -55,6 +55,8 @@ func main() { } fmt.Printf(strings.Join(msg.Message, "\n")) + // Check health + // Key // -- create key := "openapi-key" @@ -66,6 +68,13 @@ func main() { } fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get()) + // -- update + + // -- delete + defer func() { + // todo delete key + }() + // Bucket // -- create global_name := "global-ns-openapi-bucket" @@ -83,4 +92,11 @@ func main() { panic(err) } fmt.Printf("Bucket id: %s\n", *bucketInfo.Id) + + // update bucket + + // delete bucket + defer func() { + // todo delete bucket + }() } diff --git a/garage b/garage index 68d23cc..3908619 160000 --- a/garage +++ b/garage @@ -1 +1 @@ -Subproject commit 68d23cccdfc650cb8fa48fb2871ca4dfe7014d44 +Subproject commit 3908619eac7c46c0d1b065adb4b79db798bc8d22 diff --git a/garage-admin-sdk-golang b/garage-admin-sdk-golang index ffd9578..d1fd358 160000 --- a/garage-admin-sdk-golang +++ b/garage-admin-sdk-golang @@ -1 +1 @@ -Subproject commit ffd9578e975e886d9075a4f2e710117893de8ac7 +Subproject commit d1fd35809073b801031b8f47475311dd1f250eab diff --git a/garage-admin-sdk-js b/garage-admin-sdk-js index f7b4e20..2d012ad 160000 --- a/garage-admin-sdk-js +++ b/garage-admin-sdk-js @@ -1 +1 @@ -Subproject commit f7b4e20e4292883f1eaa5cd6cd5287aa550ff605 +Subproject commit 2d012ad1b9e0f92980ea59a4fd4b7bf70932c83b diff --git a/garage-admin-sdk-python b/garage-admin-sdk-python index 8c3a7da..972ab05 160000 --- a/garage-admin-sdk-python +++ b/garage-admin-sdk-python @@ -1 +1 @@ -Subproject commit 8c3a7daa8a6d305dc0ee9082ce1f28682951e7b8 +Subproject commit 972ab05d71eaf8a75f326bce94f407e2dbe70fa3 -- 2.45.2 From 0a681b740c60436fbdb9b4b58e808130d7b6d504 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 Nov 2023 15:23:05 +0100 Subject: [PATCH 11/15] manually patch the golang sdk --- garage-admin-sdk-golang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/garage-admin-sdk-golang b/garage-admin-sdk-golang index d1fd358..9dd59cf 160000 --- a/garage-admin-sdk-golang +++ b/garage-admin-sdk-golang @@ -1 +1 @@ -Subproject commit d1fd35809073b801031b8f47475311dd1f250eab +Subproject commit 9dd59cf12c08824bde465a30a1638579b0d1f041 -- 2.45.2 From 9bdd615b334f892f135afb34e7a7c7d2ba9951f0 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 Nov 2023 15:25:08 +0100 Subject: [PATCH 12/15] cluster health is working --- example/golang/go.mod | 2 +- example/golang/go.sum | 4 ++++ example/golang/main.go | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/example/golang/go.mod b/example/golang/go.mod index 029bab5..30f4e0e 100644 --- a/example/golang/go.mod +++ b/example/golang/go.mod @@ -3,7 +3,7 @@ module garage-admin-example go 1.18 require ( - git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123092113-ffd9578e975e // indirect + git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128142223-9dd59cf12c08 // indirect github.com/golang/protobuf v1.4.2 // indirect golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 // indirect diff --git a/example/golang/go.sum b/example/golang/go.sum index 5c79610..ca3ab7b 100644 --- a/example/golang/go.sum +++ b/example/golang/go.sum @@ -41,6 +41,10 @@ git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123090411-96f08 git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123090411-96f080c89ec4/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123092113-ffd9578e975e h1:C/D3P1+mWBTHiO3MeiNWB2S1AJ3A/m7OYGX4iS8nbtA= git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231123092113-ffd9578e975e/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128133246-d1fd35809073 h1:2i4BlF34l5ZuCe9rDQbSnvigGxHMtc99qxP55oUuPt4= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128133246-d1fd35809073/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128142223-9dd59cf12c08 h1:pPjSXww/2ebfJ4iHt2NI8/cs/eBV+VC9YLQIW0N3E54= +git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128142223-9dd59cf12c08/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/example/golang/main.go b/example/golang/main.go index 6a56348..e26c3b6 100644 --- a/example/golang/main.go +++ b/example/golang/main.go @@ -56,6 +56,17 @@ func main() { fmt.Printf(strings.Join(msg.Message, "\n")) // Check health + health, r, err := client.NodesApi.GetHealth(ctx).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `NodesApi.GetHealth`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + fmt.Printf("Status: %s\n", health.Status) + fmt.Printf("All nodes: %v/%v healthy\n", health.ConnectedNodes, health.KnownNodes) + fmt.Printf("Storage nodes: %v/%v healthy\n", health.StorageNodesOk, health.StorageNodes) + fmt.Printf("Partitions: %v/%v healthy\n", health.PartitionsAllOk, health.Partitions) + // Key // -- create @@ -69,6 +80,7 @@ func main() { fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get()) // -- update + //update, r, err := apiClient.KeyApi.UpdateKey(context.Background()).Id(id).UpdateKeyRequest(updateKeyRequest).Execute() // -- delete defer func() { -- 2.45.2 From 2c4a602172312c3050fd14e966ef903b40f15e89 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 Nov 2023 16:02:19 +0100 Subject: [PATCH 13/15] improve golang example --- example/golang/main.go | 78 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/example/golang/main.go b/example/golang/main.go index e26c3b6..4774365 100644 --- a/example/golang/main.go +++ b/example/golang/main.go @@ -21,6 +21,7 @@ func main() { ctx := context.WithValue(context.Background(), garage.ContextAccessToken, "s3cr3t") // Send a request + fmt.Println("--- nodes ---") resp, r, err := client.NodesApi.GetNodes(ctx).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `NodesApi.GetNodes`\n") @@ -69,6 +70,7 @@ func main() { // Key + fmt.Println("\n--- key ---") // -- create key := "openapi-key" keyInfo, r, err := client.KeyApi.AddKey(ctx).AddKeyRequest(garage.AddKeyRequest{Name: *garage.NewNullableString(&key) }).Execute() @@ -79,15 +81,41 @@ func main() { } fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get()) - // -- update - //update, r, err := apiClient.KeyApi.UpdateKey(context.Background()).Id(id).UpdateKeyRequest(updateKeyRequest).Execute() - // -- delete defer func() { - // todo delete key + r, err := client.KeyApi.DeleteKey(ctx).Id(*keyInfo.AccessKeyId).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyApi.DeleteKey`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } }() + // -- update + id := *keyInfo.AccessKeyId + canCreateBucket := true + updateKeyRequest := *garage.NewUpdateKeyRequest() + updateKeyRequest.SetName("openapi-key-updated") + updateKeyRequest.SetAllow(garage.UpdateKeyRequestAllow { CreateBucket: &canCreateBucket }) + update, r, err := client.KeyApi.UpdateKey(ctx).Id(id).UpdateKeyRequest(updateKeyRequest).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyApi.UpdateKey`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + fmt.Printf("Updated %v with key name %v\n", *update.AccessKeyId, *update.Name) + + // -- list + keyList, r, err := client.KeyApi.ListKeys(ctx).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyApi.ListKeys`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + fmt.Printf("Keys count: %v\n", len(keyList)) + // Bucket + fmt.Println("\n--- bucket ---") // -- create global_name := "global-ns-openapi-bucket" local_name := "local-ns-openapi-bucket" @@ -105,10 +133,44 @@ func main() { } fmt.Printf("Bucket id: %s\n", *bucketInfo.Id) - // update bucket - - // delete bucket + // -- delete defer func() { - // todo delete bucket + r, err := client.BucketApi.DeleteBucket(ctx).Id(*bucketInfo.Id).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `BucketApi.DeleteBucket`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } }() + + // -- update + updateBucketRequest := *garage.NewUpdateBucketRequest() + + website := garage.NewUpdateBucketRequestWebsiteAccess() + website.SetEnabled(true) + website.SetIndexDocument("index.html") + website.SetErrorDocument("errors/4xx.html") + updateBucketRequest.SetWebsiteAccess(*website) + + quotas := garage.NewUpdateBucketRequestQuotas() + quotas.SetMaxSize(1000000000) + quotas.SetMaxObjects(999999999) + updateBucketRequest.SetQuotas(*quotas) + + updatedBucket, r, err := client.BucketApi.UpdateBucket(ctx).Id(*bucketInfo.Id).UpdateBucketRequest(updateBucketRequest).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `BucketApi.UpdateBucket`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + fmt.Printf("Bucket %v website activation: %v\n", *updatedBucket.Id, *updatedBucket.WebsiteAccess) + + // -- list + bucketList, r, err := client.BucketApi.ListBuckets(ctx).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `BucketApi.ListBuckets`\n") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + panic(err) + } + fmt.Printf("Bucket count: %v\n", len(bucketList)) } -- 2.45.2 From 6a07252d5618645f0aaa2160f7e90b44f65c92b9 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 Nov 2023 16:10:05 +0100 Subject: [PATCH 14/15] Add a short example --- README.md | 82 ++++++++++++++++++++++++++++++++------- example/golang/short.go | 85 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 example/golang/short.go diff --git a/README.md b/README.md index 276dbd6..cdc2981 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Install the SDK with: go get git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang ``` -A short example: +An example without error checking: ```go package main @@ -149,30 +149,84 @@ import ( "context" "fmt" "os" + "strings" garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang" ) func main() { - // Set Host and other parameters + // Initialization configuration := garage.NewConfiguration() configuration.Host = "127.0.0.1:3903" - - - // We can now generate a client client := garage.NewAPIClient(configuration) - - // Authentication is handled through the context pattern ctx := context.WithValue(context.Background(), garage.ContextAccessToken, "s3cr3t") - // Send a request - resp, r, err := client.NodesApi.GetNodes(ctx).Execute() - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `NodesApi.GetNodes``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + // Nodes + fmt.Println("--- nodes ---") + nodes, _, _ := client.NodesApi.GetNodes(ctx).Execute() + fmt.Fprintf(os.Stdout, "First hostname: %v\n", nodes.KnownNodes[0].Hostname) + capa := int64(1000000000) + change := []garage.NodeRoleChange{ + garage.NodeRoleChange{NodeRoleUpdate: &garage.NodeRoleUpdate { + Id: *nodes.KnownNodes[0].Id, + Zone: "dc1", + Capacity: *garage.NewNullableInt64(&capa), + Tags: []string{ "fast", "amd64" }, + }}, } + staged, _, _ := client.LayoutApi.AddLayout(ctx).NodeRoleChange(change).Execute() + msg, _, _ := client.LayoutApi.ApplyLayout(ctx).LayoutVersion(*garage.NewLayoutVersion(staged.Version + 1)).Execute() + fmt.Printf(strings.Join(msg.Message, "\n")) // Layout configured - // Process the response - fmt.Fprintf(os.Stdout, "Target hostname: %v\n", resp.KnownNodes[0].Hostname) + health, _, _ := client.NodesApi.GetHealth(ctx).Execute() + fmt.Printf("Status: %s, nodes: %v/%v, storage: %v/%v, partitions: %v/%v\n", health.Status, health.ConnectedNodes, health.KnownNodes, health.StorageNodesOk, health.StorageNodes, health.PartitionsAllOk, health.Partitions) + + // Key + fmt.Println("\n--- key ---") + key := "openapi-key" + keyInfo, _, _ := client.KeyApi.AddKey(ctx).AddKeyRequest(garage.AddKeyRequest{Name: *garage.NewNullableString(&key) }).Execute() + defer client.KeyApi.DeleteKey(ctx).Id(*keyInfo.AccessKeyId).Execute() + fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get()) + + id := *keyInfo.AccessKeyId + canCreateBucket := true + updateKeyRequest := *garage.NewUpdateKeyRequest() + updateKeyRequest.SetName("openapi-key-updated") + updateKeyRequest.SetAllow(garage.UpdateKeyRequestAllow { CreateBucket: &canCreateBucket }) + update, _, _ := client.KeyApi.UpdateKey(ctx).Id(id).UpdateKeyRequest(updateKeyRequest).Execute() + fmt.Printf("Updated %v with key name %v\n", *update.AccessKeyId, *update.Name) + + keyList, _, _ := client.KeyApi.ListKeys(ctx).Execute() + fmt.Printf("Keys count: %v\n", len(keyList)) + + // Bucket + fmt.Println("\n--- bucket ---") + global_name := "global-ns-openapi-bucket" + local_name := "local-ns-openapi-bucket" + bucketInfo, _, _ := client.BucketApi.CreateBucket(ctx).CreateBucketRequest(garage.CreateBucketRequest{ + GlobalAlias: &global_name, + LocalAlias: &garage.CreateBucketRequestLocalAlias { + AccessKeyId: keyInfo.AccessKeyId, + Alias: &local_name, + }, + }).Execute() + defer client.BucketApi.DeleteBucket(ctx).Id(*bucketInfo.Id).Execute() + fmt.Printf("Bucket id: %s\n", *bucketInfo.Id) + + updateBucketRequest := *garage.NewUpdateBucketRequest() + website := garage.NewUpdateBucketRequestWebsiteAccess() + website.SetEnabled(true) + website.SetIndexDocument("index.html") + website.SetErrorDocument("errors/4xx.html") + updateBucketRequest.SetWebsiteAccess(*website) + quotas := garage.NewUpdateBucketRequestQuotas() + quotas.SetMaxSize(1000000000) + quotas.SetMaxObjects(999999999) + updateBucketRequest.SetQuotas(*quotas) + updatedBucket, _, _ := client.BucketApi.UpdateBucket(ctx).Id(*bucketInfo.Id).UpdateBucketRequest(updateBucketRequest).Execute() + fmt.Printf("Bucket %v website activation: %v\n", *updatedBucket.Id, *updatedBucket.WebsiteAccess) + + bucketList, _, _ := client.BucketApi.ListBuckets(ctx).Execute() + fmt.Printf("Bucket count: %v\n", len(bucketList)) } ``` diff --git a/example/golang/short.go b/example/golang/short.go new file mode 100644 index 0000000..3b950a2 --- /dev/null +++ b/example/golang/short.go @@ -0,0 +1,85 @@ +package main + +import ( + "context" + "fmt" + "os" + "strings" + garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang" +) + +func main() { + // Initialization + configuration := garage.NewConfiguration() + configuration.Host = "127.0.0.1:3903" + client := garage.NewAPIClient(configuration) + ctx := context.WithValue(context.Background(), garage.ContextAccessToken, "s3cr3t") + + // Nodes + fmt.Println("--- nodes ---") + nodes, _, _ := client.NodesApi.GetNodes(ctx).Execute() + fmt.Fprintf(os.Stdout, "First hostname: %v\n", nodes.KnownNodes[0].Hostname) + capa := int64(1000000000) + change := []garage.NodeRoleChange{ + garage.NodeRoleChange{NodeRoleUpdate: &garage.NodeRoleUpdate { + Id: *nodes.KnownNodes[0].Id, + Zone: "dc1", + Capacity: *garage.NewNullableInt64(&capa), + Tags: []string{ "fast", "amd64" }, + }}, + } + staged, _, _ := client.LayoutApi.AddLayout(ctx).NodeRoleChange(change).Execute() + msg, _, _ := client.LayoutApi.ApplyLayout(ctx).LayoutVersion(*garage.NewLayoutVersion(staged.Version + 1)).Execute() + fmt.Printf(strings.Join(msg.Message, "\n")) // Layout configured + + health, _, _ := client.NodesApi.GetHealth(ctx).Execute() + fmt.Printf("Status: %s, nodes: %v/%v, storage: %v/%v, partitions: %v/%v\n", health.Status, health.ConnectedNodes, health.KnownNodes, health.StorageNodesOk, health.StorageNodes, health.PartitionsAllOk, health.Partitions) + + // Key + fmt.Println("\n--- key ---") + key := "openapi-key" + keyInfo, _, _ := client.KeyApi.AddKey(ctx).AddKeyRequest(garage.AddKeyRequest{Name: *garage.NewNullableString(&key) }).Execute() + defer client.KeyApi.DeleteKey(ctx).Id(*keyInfo.AccessKeyId).Execute() + fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get()) + + id := *keyInfo.AccessKeyId + canCreateBucket := true + updateKeyRequest := *garage.NewUpdateKeyRequest() + updateKeyRequest.SetName("openapi-key-updated") + updateKeyRequest.SetAllow(garage.UpdateKeyRequestAllow { CreateBucket: &canCreateBucket }) + update, _, _ := client.KeyApi.UpdateKey(ctx).Id(id).UpdateKeyRequest(updateKeyRequest).Execute() + fmt.Printf("Updated %v with key name %v\n", *update.AccessKeyId, *update.Name) + + keyList, _, _ := client.KeyApi.ListKeys(ctx).Execute() + fmt.Printf("Keys count: %v\n", len(keyList)) + + // Bucket + fmt.Println("\n--- bucket ---") + global_name := "global-ns-openapi-bucket" + local_name := "local-ns-openapi-bucket" + bucketInfo, _, _ := client.BucketApi.CreateBucket(ctx).CreateBucketRequest(garage.CreateBucketRequest{ + GlobalAlias: &global_name, + LocalAlias: &garage.CreateBucketRequestLocalAlias { + AccessKeyId: keyInfo.AccessKeyId, + Alias: &local_name, + }, + }).Execute() + defer client.BucketApi.DeleteBucket(ctx).Id(*bucketInfo.Id).Execute() + fmt.Printf("Bucket id: %s\n", *bucketInfo.Id) + + updateBucketRequest := *garage.NewUpdateBucketRequest() + website := garage.NewUpdateBucketRequestWebsiteAccess() + website.SetEnabled(true) + website.SetIndexDocument("index.html") + website.SetErrorDocument("errors/4xx.html") + updateBucketRequest.SetWebsiteAccess(*website) + quotas := garage.NewUpdateBucketRequestQuotas() + quotas.SetMaxSize(1000000000) + quotas.SetMaxObjects(999999999) + updateBucketRequest.SetQuotas(*quotas) + updatedBucket, _, _ := client.BucketApi.UpdateBucket(ctx).Id(*bucketInfo.Id).UpdateBucketRequest(updateBucketRequest).Execute() + fmt.Printf("Bucket %v website activation: %v\n", *updatedBucket.Id, *updatedBucket.WebsiteAccess) + + bucketList, _, _ := client.BucketApi.ListBuckets(ctx).Execute() + fmt.Printf("Bucket count: %v\n", len(bucketList)) +} -- 2.45.2 From 6204d1e29267a57343b9b0f37eee92e32a0689c3 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 28 Nov 2023 16:40:13 +0100 Subject: [PATCH 15/15] switch submodules to main --- garage-admin-sdk-golang | 2 +- garage-admin-sdk-js | 2 +- garage-admin-sdk-python | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/garage-admin-sdk-golang b/garage-admin-sdk-golang index 9dd59cf..8b81fae 160000 --- a/garage-admin-sdk-golang +++ b/garage-admin-sdk-golang @@ -1 +1 @@ -Subproject commit 9dd59cf12c08824bde465a30a1638579b0d1f041 +Subproject commit 8b81fae65e5e277b2b9e1659dd657f967a6122a9 diff --git a/garage-admin-sdk-js b/garage-admin-sdk-js index 2d012ad..271b951 160000 --- a/garage-admin-sdk-js +++ b/garage-admin-sdk-js @@ -1 +1 @@ -Subproject commit 2d012ad1b9e0f92980ea59a4fd4b7bf70932c83b +Subproject commit 271b95144902afdcdc7912c61936d955595bf48e diff --git a/garage-admin-sdk-python b/garage-admin-sdk-python index 972ab05..90e64fe 160000 --- a/garage-admin-sdk-python +++ b/garage-admin-sdk-python @@ -1 +1 @@ -Subproject commit 972ab05d71eaf8a75f326bce94f407e2dbe70fa3 +Subproject commit 90e64feb060692c0f19c283cace242e207f03190 -- 2.45.2