From 9686b380039e3f20e0a3be16edc22f0021d8cdab Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sat, 12 Nov 2022 23:12:52 +0100 Subject: [PATCH] Add bucket calls in the short.py example --- README.md | 16 ++++++++++++---- example/short.py | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9b51f5f..f87d4cb 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,7 @@ configuration = garage_admin_sdk.Configuration( # Init APIs api = garage_admin_sdk.ApiClient(configuration) -nodes = NodesApi(api) -layout = LayoutApi(api) -keys = KeyApi(api) +nodes, layout, keys, buckets = NodesApi(api), LayoutApi(api), KeyApi(api), BucketApi(api) # Display some info on the node status = nodes.get_nodes() @@ -54,12 +52,22 @@ kinfo = keys.add_key(AddKeyRequest(name="openapi")) allow_create = UpdateKeyRequestAllow(create_bucket=True) keys.update_key(kinfo.access_key_id, UpdateKeyRequest(allow=allow_create)) +# Create a bucket, allow key, set quotas +doc = buckets.create_bucket(CreateBucketRequest(global_alias="documentation")) +doc = buckets.allow_bucket_key(AllowBucketKeyRequest( + bucket_id=doc.id, + access_key_id=kinfo.access_key_id, + permissions=AllowBucketKeyRequestPermissions(read=True, write=True, owner=True), +)) +doc = buckets.update_bucket(doc.id, UpdateBucketRequest( + quotas=UpdateBucketRequestQuotas(max_size=19029801,max_objects=1500))) + # Display key print(f""" cluster ready key id is {kinfo.access_key_id} secret key is {kinfo.secret_access_key} -""") +bucket {doc.global_aliases[0]} contains {doc.objects}/{doc.quotas.max_objects} objects ``` *This example is named `short.py` in the example folder. Other python examples are also available.* diff --git a/example/short.py b/example/short.py index 480246d..a5298a6 100644 --- a/example/short.py +++ b/example/short.py @@ -9,9 +9,7 @@ configuration = garage_admin_sdk.Configuration( # Init APIs api = garage_admin_sdk.ApiClient(configuration) -nodes = NodesApi(api) -layout = LayoutApi(api) -keys = KeyApi(api) +nodes, layout, keys, buckets = NodesApi(api), LayoutApi(api), KeyApi(api), BucketApi(api) # Display some info on the node status = nodes.get_nodes() @@ -36,9 +34,20 @@ kinfo = keys.add_key(AddKeyRequest(name="openapi")) allow_create = UpdateKeyRequestAllow(create_bucket=True) keys.update_key(kinfo.access_key_id, UpdateKeyRequest(allow=allow_create)) +# Create a bucket, allow key, set quotas +doc = buckets.create_bucket(CreateBucketRequest(global_alias="documentation")) +doc = buckets.allow_bucket_key(AllowBucketKeyRequest( + bucket_id=doc.id, + access_key_id=kinfo.access_key_id, + permissions=AllowBucketKeyRequestPermissions(read=True, write=True, owner=True), +)) +doc = buckets.update_bucket(doc.id, UpdateBucketRequest( + quotas=UpdateBucketRequestQuotas(max_size=19029801,max_objects=1500))) + # Display key print(f""" cluster ready key id is {kinfo.access_key_id} secret key is {kinfo.secret_access_key} +bucket {doc.global_aliases[0]} contains {doc.objects}/{doc.quotas.max_objects} objects """)