cl4hana-agent-service-library 0.2.1
Common helper functions and classes used across Cluster lion services
License: MIT
Requires Python: >=3.11.4,<4.0.0

# agent services library for the CL4SAP project

Technology: Python

## Description

The **cl4hana-agent-service-library** serves on hand as the base image for (almost) all other CL4SAP docker services
and on the other hand as the main collection of functions/helpers that are needed across all CL4SAP services.

The library istelf uses python:3.8.12-alpine as its base image.

> :exclamation: :warning: An upgrade to a newer python version isn't currently possible, to be able to update to a newer
> version some services have to be
> rewritten from the ground up (ssh-service, vcenter-service, etc.). <br>
> The reason for this is a bug on python versions >= 3.9, that occurs when using multiprocessing in multiple docker
> containers.
> ([See here for more information](https://github.com/SeldonIO/seldon-core/issues/3720)) :warning: :exclamation:

<hr>

## Setting up

### Dependencies instalation

1. Install poetry `pip install poetry`
2. Install the header spoofer plugin `poetry self add poetry-request-spoofing-plugin@latest`
   > Note: This step may be optional in case poetry managed to fix it themselves. The plugin only makes sure we get
   stuff from the nexus without triggering "bot protection".
3. Install the necessary dependencies with `poetry install`

<hr>

## Usage

### Usage as a python package

1. Set up the pacakge source (ProLion nexus) in your `pyproject.toml`.

```toml
[[tool.poetry.source]]
name = "prolion"
url = "https://dev-nexus.prolion.com/repository/pypi-group/simple/"
priority = "explicit"
```

2. Add the necessary credentials to your poetry instance by running `poetry config http-basic.prolion <username>` hit
   enter and enter your password.
3. Add the package dependency to your project.

```toml
[tool.poetry.dependencies]
python = "^3.9"
# ...
cl4hana-agent-service-library = { version = "*", source = "prolion" }
```

### ~~Usage as base image~~ [DEPRECATED]

~~To use the **cl4hana-agent-service-library** as your base image for new docker services you will have to add the
following your Dockerfile.~~

(BASE_IMAGETAG can be develop, master, staging and release tags (e.g. v3.2.1))

```dockerfile
    # base image
    FROM registry.gitlab.com/cl4hana/cl4hana-agent-service-library:${BASE_IMAGETAG}
```

Containers created using the base image can use the library in their python code by default.

```python
    from cl4hana_agent_service_library.mqtt import MQTTClass
```

## Library components

The cl4hana-agent-service-library provides the following components.

### Config component

The config component provides functions to handle everything related to the config files.
For more infomation about the exported functions, please check the "config.py" file.

To use the component add the following line to your python code:

```python
    from cl4hana_agent_service_library.config import

...
```

Currently these configs files are supported:

- agent.config
- appsrv.config
- cluster.config
- hana.config
- infrastructure.config
- location.config
- mqtt.config

### SSH component

The ssh component provides functions to handle everything related to establishing a ssh connection and sending ssh
commands.
For more infomation about the exported functions, please check the "ssh.py" file.

To use the component add the following line to your python code:

```python
    from cl4hana_agent_service_library.ssh import

...
```

### Crypt component

The crypt component provides functions to encrypt/decrypt for sending/receiving clusterlion messages.
For more infomation about the exported functions, please check the "crypt.py" file.

To use the component add the following line to your python code:

```python
    from cl4hana_agent_service_library.crypt import

...
```

### Helpers component

The helpers component provides common functions to help you do things like write proper logs or check file access etc..
For more infomation about the exported functions, please check the "helpers.py" file.

To use the component add the following line to your python code:

```python
    from cl4hana_agent_service_library.helpers import

...
```

### Mqtt component

The mqtt component provides functions to handle everything related to establishing a mqtt connection and
sending/receiving mqtt messages.
For more infomation about the exported functions, please check the "mqtt.py" file.

To use the component add the following line to your python code:

```python
    from cl4hana_agent_service_library.mqtt import

...
```

### Soap_parser component

The soap_parser component provides functions to help you properly parse soap messages. (Soap messages are returned by
remote executing sapcontrol)
For more infomation about the exported functions, please check the "soap_parser.py" file.

To use the component add the following line to your python code:

```python
    from cl4hana_agent_service_library.soap_parser import

...
```