Metadata-Version: 2.4
Name: realerikrani-projectclient
Version: 1.1.0
Summary: API client & CLI for https://github.com/realerikrani/project
License: Apache-2.0
Project-URL: Repository, https://github.com/realerikrani/projectclient
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE-Apache-2.0
License-File: LICENSE-MIT-pyjwt
License-File: NOTICE
Requires-Dist: realerikrani-baseclient==1.*
Requires-Dist: pyjwt[crypto]==2.*
Requires-Dist: requests==2.*
Dynamic: license-file

# projectclient

API client and CLI for <https://github.com/realerikrani/project>.

## CLI

Pip-install projectclient.

Set `export PROJECT_CLI_CONFIG_PATH=/path/to/config.ini`

which contains the URL of your project API

```
[DEFAULT]
url = http://localhost:5000
```

Then can call the

```bash
cli_project -h
usage: cli_project [-h] {create,read,delete,key-create,keys-read,key-delete} ...

CLI for managing projects and keys.

positional arguments:
  {create,read,delete,key-create,keys-read,key-delete}
    create              Create a project with a key.
    read                Read a project.
    delete              Delete a project.
    key-create          Create a new key for a project.
    keys-read           Read public keys of a project.
    key-delete          Delete a key.

options:
  -h, --help            show this help message and exit
```

After creating a project, the ini-file shall be updated by the code.
For example, it could be similar to

```
[DEFAULT]
url = http://localhost:5000
current_key_id = 01744bc7-45e5-4a49-837b-3677e6cc65f7
current_project_id = 3c6955c4-2ag9-4f31-ba75-9e96afca5ee4

[01744bc7-45e5-4a49-837b-3677e6cc65f7@3c6955c4-2ag9-4f31-ba75-9e96afca5ee4]
public = /Users/john/Documents/demo/pubkey.pem
private = /Users/john/Documents/demo/key.pem.enc
```

## API Client

```py
from realerikrani.projectclient import JWTAuth, ProjectClient
from realerikrani.baseclient import BaseAdapter, BaseClient


def create_project_client() -> ProjectClient:
    adapter = BaseAdapter()
    with requests.Session() as session:
        jwt_auth = None
        with suppress(KeyError):
            jwt_auth = JWTAuth(
                YOUR_CONF[YOUR_PROJECT_ID], 
                YOUR_CONF[YOUR_KEY_ID], 
                YOUR_CONF[YOUR_PRIVATE_KEY_ENCRYPTED_PEM_STRING], 
                YOUR_CONF[YOUR_PRIVATE_KEY_ENCRYPTED_PEM_PASSPHRASE]
            )
            # If you don't have encrypted key, then don't provide the passphrase
            # jwt_auth = JWTAuth(YOUR_CONF[YOUR_PROJECT_ID], YOUR_CONF[YOUR_KEY_ID], YOUR_CONF[YOUR_PRIVATE_KEY_PEM_STR])
        baseclient = BaseClient(
            session=session, adapter=adapter, url=read_url(config), auth=jwt_auth
        )
        return ProjectClient(baseclient)
```

## Direct Dependencies:

- requests - licensed under the Apache License 2.0
- realerikrani-baseclient - licensed under the Apache License 2.0
- pyjwt[crypto] - licensed under the MIT License
