diff --git a/README.md b/README.md index cb66e20..1419987 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,88 @@ # Garage Admin SDK -## Clone this repo +## 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 +pip3 install --user 'git+https://git.deuxfleurs.fr/quentin/garage-admin-sdk#egg=garage-admin-sdk&subdirectory=python' +``` + +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 +from garage_admin_sdk.api import nodes_api, layout_api, key_api +from garage_admin_sdk.model.node_cluster_info import NodeClusterInfo +from garage_admin_sdk.model.layout_version import LayoutVersion +from garage_admin_sdk.model.add_key_request import AddKeyRequest +from garage_admin_sdk.model.update_key_request import UpdateKeyRequest +from garage_admin_sdk.model.update_key_request_allow import UpdateKeyRequestAllow + +configuration = garage_admin_sdk.Configuration( + host = "http://localhost:3903/v0", + access_token = "s3cr3t" +) + +with garage_admin_sdk.ApiClient(configuration) as api: + # Init APIs + nodes = nodes_api.NodesApi(api) + layout = layout_api.LayoutApi(api) + keys = key_api.KeyApi(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(request_body={ + f"{status.node}": NodeClusterInfo( + zone = "dc1", + capacity = 1, + tags = [ "dev" ], + ) + }) + layout.apply_layout(layout_version=LayoutVersion( + version = current.version + 1 + )) + + # Create key, allow it to create buckets + kreq = AddKeyRequest(name="openapi") + kinfo = keys.add_key(add_key_request=kreq) + + allow_create = UpdateKeyRequestAllow(create_bucket=True) + kreq = UpdateKeyRequest(allow=allow_create) + keys.update_key(kinfo.access_key_id, update_key_request=kreq) + + # Display key + print(f"your cluster is ready, your key id: {kinfo.access_key_id}, your secret key: {kinfo.secret_access_key}") +``` + +*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 ```bash git clone ... git submodule init ``` -## (Re)generate libraries +### (Re)generate libraries ```bash # Check the OpenAPI spec file @@ -16,3 +91,9 @@ gradle validate # (re)build the python client gradle buildPythonClient ``` + +## 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 diff --git a/example/short.py b/example/short.py new file mode 100644 index 0000000..287221c --- /dev/null +++ b/example/short.py @@ -0,0 +1,46 @@ +import garage_admin_sdk +from garage_admin_sdk.api import nodes_api, layout_api, key_api +from garage_admin_sdk.model.node_cluster_info import NodeClusterInfo +from garage_admin_sdk.model.layout_version import LayoutVersion +from garage_admin_sdk.model.add_key_request import AddKeyRequest +from garage_admin_sdk.model.update_key_request import UpdateKeyRequest +from garage_admin_sdk.model.update_key_request_allow import UpdateKeyRequestAllow + +configuration = garage_admin_sdk.Configuration( + host = "http://localhost:3903/v0", + access_token = "s3cr3t" +) + +with garage_admin_sdk.ApiClient(configuration) as api: + # Init APIs + nodes = nodes_api.NodesApi(api) + layout = layout_api.LayoutApi(api) + keys = key_api.KeyApi(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(request_body={ + f"{status.node}": NodeClusterInfo( + zone = "dc1", + capacity = 1, + tags = [ "dev" ], + ) + }) + layout.apply_layout(layout_version=LayoutVersion( + version = current.version + 1 + )) + + # Create key, allow it to create buckets + kreq = AddKeyRequest(name="openapi") + kinfo = keys.add_key(add_key_request=kreq) + + allow_create = UpdateKeyRequestAllow(create_bucket=True) + kreq = UpdateKeyRequest(allow=allow_create) + keys.update_key(kinfo.access_key_id, update_key_request=kreq) + + # Display key + print(f"your cluster is ready, your key id: {kinfo.access_key_id}, your secret key: {kinfo.secret_access_key}")