garage-admin-sdk-generator/README.md

107 lines
2.9 KiB
Markdown
Raw Normal View History

2022-09-13 14:00:03 +00:00
# Garage Admin SDK
2022-09-12 15:02:35 +00:00
2022-09-13 15:54:05 +00:00
## For SDK users
The SDK is currently only available for Python.
### Python
You need at least Python 3.6, pip, and setuptools.
Because the python package is in a subfolder, the command is a bit more complicated than usual:
```bash
2022-11-13 13:24:06 +00:00
pip3 install --user 'git+https://git.deuxfleurs.fr/quentin/garage-admin-sdk-python'
2022-09-13 15:54:05 +00:00
```
Now, let imagine you have a fresh Garage instance running on localhost, with the admin API configured on port 3903 with the bearer `s3cr3t`:
```python
import garage_admin_sdk
2022-11-12 21:48:50 +00:00
from garage_admin_sdk.apis import *
from garage_admin_sdk.models import *
2022-09-13 15:54:05 +00:00
configuration = garage_admin_sdk.Configuration(
host = "http://localhost:3903/v0",
access_token = "s3cr3t"
2022-09-13 15:54:05 +00:00
)
# Init APIs
api = garage_admin_sdk.ApiClient(configuration)
nodes, layout, keys, buckets = NodesApi(api), LayoutApi(api), KeyApi(api), BucketApi(api)
# Display some info on the node
status = nodes.get_nodes()
print(f"running garage {status.garage_version}, node_id {status.node}")
# Change layout of this node
current = layout.get_layout()
layout.add_layout({
2022-09-28 18:26:01 +00:00
status.node: NodeClusterInfo(
zone = "dc1",
capacity = 1,
tags = [ "dev" ],
)
})
layout.apply_layout(LayoutVersion(
version = current.version + 1
))
# Create key, allow it to create buckets
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
2022-11-12 22:16:11 +00:00
binfo = buckets.create_bucket(CreateBucketRequest(global_alias="documentation"))
binfo = buckets.allow_bucket_key(AllowBucketKeyRequest(
bucket_id=binfo.id,
access_key_id=kinfo.access_key_id,
permissions=AllowBucketKeyRequestPermissions(read=True, write=True, owner=True),
))
2022-11-12 22:16:11 +00:00
binfo = buckets.update_bucket(binfo.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}
2022-11-12 22:16:11 +00:00
bucket {binfo.global_aliases[0]} contains {binfo.objects}/{binfo.quotas.max_objects} objects
""")
2022-09-13 15:54:05 +00:00
```
*This example is named `short.py` in the example folder. Other python examples are also available.*
See also:
- [examples](./example)
- [generated doc](./python)
## For SDK developpers
PR are accepted for other languages as soon as meaningful, manually written, covering
a large range of the API are provided. Thanks in advance :-)
### Clone this repo
2022-09-12 15:02:35 +00:00
2022-09-13 14:00:03 +00:00
```bash
git clone ...
2022-09-14 13:45:21 +00:00
git submodule update --init
2022-09-12 15:02:35 +00:00
```
2022-09-13 14:00:03 +00:00
2022-09-13 15:54:05 +00:00
### (Re)generate libraries
2022-09-13 14:00:03 +00:00
```bash
# Check the OpenAPI spec file
gradle validate
# (re)build the python client
gradle buildPythonClient
2022-09-12 15:02:35 +00:00
```
2022-09-13 15:54:05 +00:00
## Support a new language
Read the doc: https://openapi-generator.tech/docs/installation
We use the Gradle plugins: https://openapi-generator.tech/docs/plugins
Many generators exist: https://openapi-generator.tech/docs/generators