Add a javascript example+doc
This commit is contained in:
parent
becd01784a
commit
16ee0d9924
3 changed files with 50 additions and 9 deletions
45
README.md
45
README.md
|
@ -1,8 +1,13 @@
|
|||
# Garage Admin SDK
|
||||
|
||||
Operate your Garage cluster programatically
|
||||
|
||||
## For SDK users
|
||||
|
||||
The SDK is currently only available for Python.
|
||||
The following languages are supported:
|
||||
- [Python](#python)
|
||||
- [Javascript](#javascript)
|
||||
- Golang
|
||||
|
||||
### Python
|
||||
|
||||
|
@ -74,8 +79,42 @@ bucket {binfo.global_aliases[0]} contains {binfo.objects}/{binfo.quotas.max_obje
|
|||
*This example is named `short.py` in the example folder. Other python examples are also available.*
|
||||
|
||||
See also:
|
||||
- [examples](./example)
|
||||
- [generated doc](./python)
|
||||
- [examples](./example/python)
|
||||
- [generated doc](./garage-admin-sdk-python)
|
||||
|
||||
### Javascript
|
||||
|
||||
Install the SDK with:
|
||||
|
||||
```bash
|
||||
npm install --save git+https://git.deuxfleurs.fr/quentin/garage-admin-sdk-js.git
|
||||
```
|
||||
|
||||
A short example:
|
||||
|
||||
```javascript
|
||||
const garage = require('garage_administration_api_v0garage_v0_8_0');
|
||||
|
||||
const api = new garage.ApiClient("http://127.0.0.1:3903/v0");
|
||||
api.authentications['bearerAuth'].accessToken = "s3cr3t";
|
||||
|
||||
const [node, layout, key, bucket] = [
|
||||
new garage.NodesApi(api),
|
||||
new garage.LayoutApi(api),
|
||||
new garage.KeyApi(api),
|
||||
new garage.BucketApi(api),
|
||||
];
|
||||
|
||||
node.getNodes().then((data) => {
|
||||
console.log(`nodes: ${Object.values(data.knownNodes).map(n => n.hostname)}`)
|
||||
}, (error) => {
|
||||
console.error(error);
|
||||
});
|
||||
```
|
||||
|
||||
See also:
|
||||
- [examples](./example/javascript)
|
||||
- [generated doc](./garage-admin-sdk-js)
|
||||
|
||||
## For SDK developpers
|
||||
|
||||
|
|
4
example/javascript/package-lock.json
generated
4
example/javascript/package-lock.json
generated
|
@ -738,7 +738,7 @@
|
|||
},
|
||||
"node_modules/garage_administration_api_v0garage_v0_8_0": {
|
||||
"version": "v0.8.0",
|
||||
"resolved": "git+https://git.deuxfleurs.fr/quentin/garage-admin-sdk-js.git#10360d3b3c5596abc668ff95d6924f1dd6485509",
|
||||
"resolved": "git+https://git.deuxfleurs.fr/quentin/garage-admin-sdk-js.git#97a1ec97120d1376cbf93e8213bfdb4f2be9c522",
|
||||
"license": "Unlicense",
|
||||
"dependencies": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
|
@ -1814,7 +1814,7 @@
|
|||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
||||
},
|
||||
"garage_administration_api_v0garage_v0_8_0": {
|
||||
"version": "git+https://git.deuxfleurs.fr/quentin/garage-admin-sdk-js.git#10360d3b3c5596abc668ff95d6924f1dd6485509",
|
||||
"version": "git+https://git.deuxfleurs.fr/quentin/garage-admin-sdk-js.git#97a1ec97120d1376cbf93e8213bfdb4f2be9c522",
|
||||
"from": "garage_administration_api_v0garage_v0_8_0@git+https://git.deuxfleurs.fr/quentin/garage-admin-sdk-js.git",
|
||||
"requires": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const garage = require('garage_administration_api_v0garage_v0_8_0');
|
||||
|
||||
const api = new garage.ApiClient("http://localhost:3903/v0");
|
||||
const api = new garage.ApiClient("http://127.0.0.1:3903/v0");
|
||||
api.authentications['bearerAuth'].accessToken = "s3cr3t";
|
||||
|
||||
const [node, layout, key, bucket] = [
|
||||
|
@ -10,6 +10,8 @@ const [node, layout, key, bucket] = [
|
|||
new garage.BucketApi(api),
|
||||
];
|
||||
|
||||
node.
|
||||
|
||||
console.log(node);
|
||||
node.getNodes().then((data) => {
|
||||
console.log(`nodes: ${Object.values(data.knownNodes).map(n => n.hostname)}`)
|
||||
}, (error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue