# ubai-client
Universal Binary Archiver Service

This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: 1.0.0
- Package version: 1.0.0
- Build package: org.openapitools.codegen.languages.PythonClientCodegen

## Requirements.

Python >= 3.6

## Installation & Usage
### pip install

If the python package is hosted on a repository, you can install directly using:

```sh
pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
```
(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git`)

Then import the package:
```python
import ubai_client
```

### Setuptools

Install via [Setuptools](http://pypi.python.org/pypi/setuptools).

```sh
python setup.py install --user
```
(or `sudo python setup.py install` to install the package for all users)

Then import the package:
```python
import ubai_client
```

## Getting Started

Please follow the [installation procedure](#installation--usage) and then run the following:

```python
from ubai_client.apis import ArtifactApi, SearchApi
from ubai_client.models import ArtifactInput, ArtifactStorage
from ubai_client.exceptions import NotFoundException
import random
import base64
import requests
import urllib3


def main():
    # disable warnings due to insecure connection to Nexus
    urllib3.disable_warnings()

    b = bytearray(1000)
    for i in range(0, len(b)):
        b[i] = random.randint(0, 255)

    artifact_api = ArtifactApi()

    artifact_input = ArtifactInput(
        name="test_binary_2",
        extension=".bin",
        base64_content=base64.b64encode(b).decode("utf-8"),
        validate_metadata=False,
        metadata=dict(my_property="something"),
    )
    artifact = artifact_api.upload_artifact(payload=artifact_input)
    print(artifact)

    # retrieve by id
    retrieved_artifact = artifact_api.get_artifact(artifact.id)
    assert retrieved_artifact.hash == artifact.hash

    # retrieve by search
    search_api = SearchApi()
    search_spec = ArtifactStorage(
        extension=artifact.extension,
        name=artifact.name,
        metadata=dict(my_property="something"),
    )
    search_results = search_api.find_all_artifacts(search_spec)
    assert len([result for result in search_results if result.id == artifact.id]) == 1

    # retrieve from Nexus
    r = requests.get(artifact.url, verify=False)
    assert r.status_code == 200
    content = r.content
    assert content == b

    # after deleting the artifact, getting it should throw a NotFoundException
    artifact_api.delete_artifact(artifact.id)
    try:
        artifact_api.get_artifact(artifact.id)
        raise RuntimeError("Should have raised NotFoundException")
    except NotFoundException:
        pass

    # retrieving it via Nexus URL should return 404
    r = requests.get(artifact.url, verify=False)
    assert r.status_code == 404


if __name__ == "__main__":
    main()

```

## Documentation for API Endpoints

All URIs are relative to *https://ateaus002d.silabs.com/ubai*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*ArtifactApi* | [**delete_artifact**](docs/ArtifactApi.md#delete_artifact) | **DELETE** /api/v1/artifacts/{artifact_id} | 
*ArtifactApi* | [**get_artifact**](docs/ArtifactApi.md#get_artifact) | **GET** /api/v1/artifacts/{artifact_id} | 
*ArtifactApi* | [**upload_artifact**](docs/ArtifactApi.md#upload_artifact) | **POST** /api/v1/artifacts | 
*SearchApi* | [**find_all_artifacts**](docs/SearchApi.md#find_all_artifacts) | **POST** /api/v1/findAll | 
*SearchApi* | [**find_first_artifact**](docs/SearchApi.md#find_first_artifact) | **POST** /api/v1/findFirst | 


## Documentation For Models

 - [ArtifactInput](docs/ArtifactInput.md)
 - [ArtifactMetadata](docs/ArtifactMetadata.md)
 - [ArtifactStorage](docs/ArtifactStorage.md)


## Documentation For Authorization

 All endpoints do not require authorization.

## Author




## Notes for Large OpenAPI documents
If the OpenAPI document is large, imports in ubai_client.apis and ubai_client.models may fail with a
RecursionError indicating the maximum recursion limit has been exceeded. In that case, there are a couple of solutions:

Solution 1:
Use specific imports for apis and models like:
- `from ubai_client.api.default_api import DefaultApi`
- `from ubai_client.model.pet import Pet`

Solution 2:
Before importing the package, adjust the maximum recursion limit as shown below:
```
import sys
sys.setrecursionlimit(1500)
import ubai_client
from ubai_client.apis import *
from ubai_client.models import *
```

