Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,285 changes: 1,285 additions & 0 deletions API.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${java.version}</release>
<parameters>true</parameters>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
Expand Down
5 changes: 5 additions & 0 deletions python-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.egg-info/
__pycache__/
dist/
build/
.pytest_cache/
53 changes: 53 additions & 0 deletions python-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# karnak-api-client

Python client for the REST API exposed by this Karnak fork
([API.md](../API.md) documents every endpoint).

Two layers:

- `karnak_api_client.client` — `KarnakClient`: thin authenticated transport
mirroring the REST resources. Supports three auth modes:
- `basic` — HTTP Basic on every request (default in-memory IdP enables it);
- `form` — Spring form-login: POST `/login`, reuse the `JSESSIONID` cookie;
- `auto` (default) — try Basic, fall back to form-login transparently when
the server redirects to `/login` or returns 401.
- `karnak_api_client.apply` — `apply_config(client, config)`: idempotent
desired-state application (profile, project + HMAC secret, auth configs,
forward node, source nodes, destinations, external-ID import) from a JSON
config document.

## Install

```sh
pip install "karnak-api-client @ git+https://github.com/jbardet/karnak.git@client-v0.1.0#subdirectory=python-client"
```

## Usage

```python
from karnak_api_client import KarnakClient, KarnakClientConfig

client = KarnakClient(KarnakClientConfig(
base_url="http://localhost:8081", username="admin", password="karnak",
))
profiles = client.list_profiles()
```

Or configure from the environment (`KARNAK_API_BASE`, `KARNAK_USERNAME`,
`KARNAK_PASSWORD`, `KARNAK_AUTH_MODE`, `KARNAK_API_TIMEOUT_SEC`):

```python
client = KarnakClient() # KarnakClientConfig.from_env()
```

## Versioning

Tag scheme `client-v<semver>` on this repo. The Docker image of the fork uses
`<upstream-version>-api.<n>` tags; the two are released independently but the
client tracks the controllers in `src/main/java/org/karnak/backend/controller/`.

## Consumers

- MiCo-BID-pipeline (DAG step `00_apply_karnak_config.py`, `micobid` CLI)
- TMLCTP equivalence harness (`integration_tests/karnak_api/`)
- `setup_deid_gateway.py` in this repo
38 changes: 38 additions & 0 deletions python-client/karnak_api_client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Python client for the Karnak REST API (karnak-endpoints fork).

Transport client (``client``) plus idempotent desired-state apply
(``apply``). See API.md at the repository root for endpoint details.
"""

from .apply import (
KarnakConfigError,
apply_config,
load_apply_config,
profile_meta_from_yaml,
write_json_atomic,
)
from .client import (
ApiError,
AuthenticationError,
KarnakApiError,
KarnakClient,
KarnakClientConfig,
KarnakError,
)

__version__ = "0.1.0"

__all__ = [
"ApiError",
"AuthenticationError",
"KarnakApiError",
"KarnakClient",
"KarnakClientConfig",
"KarnakConfigError",
"KarnakError",
"apply_config",
"load_apply_config",
"profile_meta_from_yaml",
"write_json_atomic",
"__version__",
]
Loading