Skip to content

Commit

Permalink
feat: use the nethsm-sdk-py lib
Browse files Browse the repository at this point in the history
  • Loading branch information
nponsard committed Sep 29, 2023
1 parent 307da31 commit a62f347
Show file tree
Hide file tree
Showing 1,095 changed files with 22 additions and 40,503 deletions.
18 changes: 1 addition & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PYTHON3=python3
PYTHON3_VENV=venv/bin/python3

# whitelist of directories for flake8
FLAKE8_DIRS=pynitrokey/nethsm pynitrokey/cli/nk3 pynitrokey/nk3
FLAKE8_DIRS=pynitrokey/cli/nk3 pynitrokey/nk3

all: init

Expand Down Expand Up @@ -132,22 +132,6 @@ build-CI-test:
CI-test:
sudo docker run -it --rm -v $(PWD):/app nitro-python-ci make CI VENV=venv-ci

OPENAPI_OUTPUT_DIR=${PWD}/tmp/openapi-client

nethsm-api.yaml:
curl "https://nethsmdemo.nitrokey.com/api_docs/nethsm-api.yaml" --output nethsm-api.yaml

# Generates the OpenAPI client for the NetHSM REST API
.PHONY: nethsm-client
nethsm-client: nethsm-api.yaml
mkdir -p "${OPENAPI_OUTPUT_DIR}"
python tools/transform_nethsm_api_spec.py nethsm-api.yaml "${OPENAPI_OUTPUT_DIR}/nethsm-api.json"
docker run --rm -ti -v "${OPENAPI_OUTPUT_DIR}:/out" \
openapijsonschematools/openapi-json-schema-generator-cli:3.0.0 generate \
-i=/out/nethsm-api.json \
-g=python -o=/out/python --package-name=pynitrokey.nethsm.client
cp -r "${OPENAPI_OUTPUT_DIR}/python/src/pynitrokey/nethsm/client" pynitrokey/nethsm

.PHONY: secrets-test-all secrets-test secrets-test-report
LOG=info
TESTADD=
Expand Down
27 changes: 1 addition & 26 deletions docs/developer-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,4 @@ Commands that require a password should first try to read the password from an e
Updating the NetHSM client
--------------------------

To update the NetHSM HTTP client, you need to download the updated ``nethsm-api.yml`` OpenAPI specification. The easiest is to download it from the NetHSM demo server (``curl`` required):

.. code:: bash
make nethsm-api.yaml --always-make
Then, run the generation script, docker is required:

.. code:: bash
make nethsm-client
Be sure to run the linter, tests and check that everything is working as expected after the update.

Custom functions
~~~~~~~~~~~~~~~~

The generator doesn't support upload of binary files and custom ``Content-Type`` headers (fails to serialize).
To work around this, some functions are written manually, using ``NetHSM.request()`` to send the request.

The current list of such functions is:

- ``NetHSM.restore()`` : ``/system/restore``
- ``NetHSM.set_key_certificate()`` : ``/keys/{KeyID}/cert``
- ``NetHSM.set_certificate()`` : ``/config/tls/cert.pem``
- ``NetHSM.update()`` : ``/system/update``
The NetHSM client is now managed in a `separate repo <https://github.com/Nitrokey/nethsm-sdk-py>`__
Loading

0 comments on commit a62f347

Please sign in to comment.