Metadata-Version: 2.3
Name: koap
Version: 0.4.0
Summary: 
Author: Sergej Suskov
Author-email: git@spilikin.dev
Requires-Python: >=3.10,<3.13
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: jwcrypto (>=1.5.0,<2.0.0)
Requires-Dist: pydantic (>=1.10.2,<2.0.0)
Requires-Dist: pyopenssl (>=23.2.0,<24.0.0)
Requires-Dist: requests (>=2.28.1,<3.0.0)
Requires-Dist: requests-pkcs12 (>=1.18,<2.0)
Requires-Dist: rich (>=12.5.1,<13.0.0)
Requires-Dist: xmltodict (>=0.13.0,<0.14.0)
Requires-Dist: zeep (>=4.1.0,<5.0.0)
Description-Content-Type: text/markdown

# KOAP: Lightweight Konnektor Client Library

## Messages Logs
Sample Message Logs can be found here: [https://spilikin.dev/koap-python/](https://spilikin.dev/koap-python/)

## Configuration using environment variables

| Environment variable | Comment |
| --- | --- |
| `KONNEKTOR_BASE_URL` | Base URL for Konnektor. The `connector.sds` must be available at `{KONNEKTOR_BASE_URL}/connector.sds`|
| `KONNEKTOR_MANDANT_ID` | Context Mandant ID (Tenant)|
| `KONNEKTOR_CLIENT_SYSTEM_ID` | Context Client System ID|
| `KONNEKTOR_WORKPLACE_ID` | Context Workplace ID|
| `KONNEKTOR_USER_ID` | Context UserID (optional)|
| *Basic Auth* |
| `KONNEKTOR_AUTH_METHOD` | `basic`|
| `KONNEKTOR_AUTH_BASIC_USERNAME` | Username for Basic authentication| 
| `KONNEKTOR_AUTH_BASIC_PASSWORD`| Password for Basic authentication| 
| *Mutual TLS Auth* |
| `KONNEKTOR_AUTH_METHOD` | `cert`|
| `KONNEKTOR_AUTH_CERT_P12_FILENAME` | Path to the PKCS#12 file with client credentials| 
| `KONNEKTOR_AUTH_CERT_P12_PASSWORD`| Password for PKCS#12 file | 

```bash
export KONNEKTOR_BASE_URL=https://.../
export KONNEKTOR_MANDANT_ID=m1
export KONNEKTOR_CLIENT_SYSTEM_ID=c1
export KONNEKTOR_WORKPLACE_ID=w1
export KONNEKTOR_USER_ID=user1
export KONNEKTOR_AUTH_BASIC_USERNAME=user1
export KONNEKTOR_AUTH_BASIC_PASSWORD='use strong passwords in production'
```

Once the environmant variables are set, the `koap.config.ConnectorConfig`can be instantiated without parameters. We make use of [Pydantic Model Config](https://docs.pydantic.dev/latest/usage/model_config/).

```python
from koap.config import ConnectorConfig
from koap.client import ConnectorClient

config = ConnectorConfig()

client = ConnectorClient(config)

event_service = client.create_service_client('EventService', '7.2.0')

cards = event_service.GetCards(client.context())

print(cards)

```

## Configuration in code

```python
from koap.config import ConnectorConfig
from koap.client import ConnectorClient

config = ConnectorConfig(
    base_url='https://.../',
    mandant_id='m1',
    client_system_id='c1',
    workplace_id='w1',
    user_id='user1',
    # Basic Auth
    auth_method='cert',
    auth_cert_p12_filename='client.p12',
    auth_cert_p12_password='password for p12 file',
)

client = ConnectorClient(config)

event_service = client.create_service_client('EventService', '7.2.0')

cards = event_service.GetCards(client.context())

print(cards)
```

## VSDM Facade


```python
from koap.facade.vsdm.vsdm_facade import VSDMFacade
from koap.facade.model import CardTypeEnum
from koap.client import ConnectorClient, ConnectorConfig

config = ConnectorConfig()
client = ConnectorClient(config)

vsdm = VSDMFacade(client)

egks = vsdm.get_cards([CardTypeEnum.EGK])
egk_1 = egks[0]

print(egk_1)

smcbs = vsdm.get_cards([CardTypeEnum.SMC_B])
smcb_1 = smcbs[0]

print(smcb_1)

vsd = vsdm.read_vsd(
    EhcHandle=egk_1.CardHandle,
    HpcHandle=smcb_1.CardHandle,
    PerformOnlineCheck=False,
    ReadOnlineReceipt=False,
)

print(vsd)

```

## Development

```bash
git submodule init
git submodule update
poetry install
```


