[PATCH] Add public API to capsul-flask #7

Open
opened 2021-09-18 07:35:05 +00:00 by j3s · 1 comment
Owner

These changes allow you to create a new Capsul‡ using a secure HTTP API. This makes it possible to integrate with other systems, e.g. a proposed abra-capsul script, which can be used standalone to create remote Capsuls from your own shell scripts, or with abra to create and set up a new Docker Swarm server and deploy Co-op Cloud apps to it.

(‡Other endpoints for details/list/delete Coming Soon™)

API tokens are revocable server-side, by users via the web console, and by administrators using manual SQL commands.

Goodies in these two commits, from the publicapi branch of my copy of capsul-flask:

cf42ac5e4d
b8d149e862

I also added some tests here: https://git.autonomic.zone/3wordchant/capsul-flask/commits/branch/publicapi-tests

(In a separate branch to make it easier to review the tests and the API separately, and on the Autonomic Gitea because of #81)

To try it out:

  1. Check out either the publicapi or publicapi-tests branches
  2. Go to the newly-renamed "SSH & API keys" page
  3. Generate an API token, save the value (the example below assumes you run export CAPSUL_API_TOKEN=...)
  4. Send a request to your local running server:
http POST :5000/api/capsul/create \
  Authorization:$CAPSUL_API_TOKEN \
  size=f1-xs os=openbsd68 ssh_key_0=keyname

(using HTTPie, you could also use cURL or Python Requests or urllib)

The request should succeed and return the new Capsul's ID. Beware that if you're running with SPOKE_MODEL=mock, the Capsul metadata won't be saved to the database, see #83

To run automated tests:

  1. Check out publicapi-tests
  2. Start a database server and create a capsulflask_test database, see #82
  3. Run python -m unittest capsulflask.tests.test_publicapi.PublicAPITests
These changes allow you to create a new Capsul‡ using a secure HTTP API. This makes it possible to integrate with other systems, e.g. [a proposed `abra-capsul` script](https://git.autonomic.zone/coop-cloud/abra-capsul/), which can be used standalone to create remote Capsuls from your own shell scripts, or with [`abra`](https://git.autonomic.zone/coop-cloud/abra) to create and set up a new Docker Swarm server and deploy [Co-op Cloud apps](https://dev.apps.coopcloud.tech/) to it. _(‡Other endpoints for details/list/delete Coming Soon™)_ API tokens are revocable server-side, by users via the web console, and by administrators using manual SQL commands. Goodies in these two commits, from the `publicapi` branch of [my copy of `capsul-flask`](https://giit.cyberia.club/~threewordchant/capsul-flask/): https://giit.cyberia.club/~threewordchant/capsul-flask/commit/cf42ac5e4d59f65c2f105d57e797bdb14a85140f https://giit.cyberia.club/~threewordchant/capsul-flask/commit/b8d149e8625b33fef4cee25748f63ba662833e7c I also added some tests here: https://git.autonomic.zone/3wordchant/capsul-flask/commits/branch/publicapi-tests (In a separate branch to make it easier to review the tests and the API separately, and on the Autonomic Gitea because of #81) To try it out: 1. Check out either the `publicapi` or `publicapi-tests` branches 2. Go to the newly-renamed "SSH & API keys" page 3. Generate an API token, save the value (the example below assumes you run `export CAPSUL_API_TOKEN=...`) 4. Send a request to your local running server: ``` http POST :5000/api/capsul/create \ Authorization:$CAPSUL_API_TOKEN \ size=f1-xs os=openbsd68 ssh_key_0=keyname ``` (using HTTPie, you could also use cURL or Python Requests or urllib) The request should succeed and return the new Capsul's ID. Beware that if you're running with `SPOKE_MODEL=mock`, the Capsul metadata won't be saved to the database, see #83 To run automated tests: 1. Check out `publicapi-tests` 2. Start a database server and create a `capsulflask_test` database, see #82 3. Run `python -m unittest capsulflask.tests.test_publicapi.PublicAPITests`
Author
Owner

~doubtsurgea month ago · edit
I've tested this and it works - it is running on https://yolo.servers.coop.

~doubtsurgea month ago · edit I've tested this and it works - it is running on https://yolo.servers.coop.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cyberia/capsul-flask#7
No description provided.