晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/opt/imunify360/venv/lib64/python3.11/site-packages/vendors_api/ |
| Current File : //opt/imunify360/venv/lib64/python3.11/site-packages/vendors_api/Readme.md |
# List of projects where vendor's API is used
- x-ray: @dkavchuk @skokhan
- userland: @oshyshatskyi @rprilipskii, @alutsiuk
PLEASE, ADD YOUR PROJECT AND CONTACT PERSON HERE SO WE CAN NOTIFY YOU ABOUT CHANGES
# Introduction
Vendor's api is a new proxy level between control panel data and CloudLinux utilities.
The complete integration guide for vendors is located
[here](https://docs.cloudlinux.com/control_panel_integration/#introduction)
and must be kept up-to date with api implementation on our side.
The original ControlPanel API (cpapi) is located at clcommon/cpapi was written years ago
and gave ability for CloudLinux developers to write proxy scripts that translate control panel data
in python objects. Unfortunately, cpapi is not easy to extend by third-party devs: they must know python well
and also update scripts when we change internal python version in cllib.
As a result of long discussion, Vendors API layer was added. Unlike cpapi,
it uses executable scripts as data source. E.g. vendor writes `db_info` executable and
we parse it's request to create python objects:
/scripts/db_info
{
"data": {
"mysql": {
"access": {
"login": "root",
"password": "Cphxo6z",
"host": "localhost",
"port": 3306
},
"mapping": { }
}
},
"metadata": {
"result": "ok"
}
}
The complete list of scripts is located
[here](https://docs.cloudlinux.com/control_panel_integration/#the-list-of-the-integration-scripts).
## Preparation
Unfortunately we don't have already working bundled scripts that you can install
in your testing environment, but we can well-detailed response examples in
[docs](https://docs.cloudlinux.com/control_panel_integration/#the-list-of-the-integration-scripts)
which you can copy-paste to simple bash script and use them to check your code locally.
We would really appeciate if someone will create testing package with some mocked integration scripts.
## Vendors API usage in CloudLinux code
Vendors API may be used directly using simple import*:
from vendors_api import PublicApi
api = PublicApi()
api.db_info() -> Databases object
\* in projects where original cpapi is used we added proxy layer that
transforms vendor's api objects into cpapi format (see cpapi/plugins/vendors.py).
That is temporary decision while we don't move our code completely to the new api.
ONLY THINGS DECLARED IN vendors_api.\_\_init__ ARE AVAILABLE FOR PUBLIC USAGE
## Before modifying vendors API
Before adding new data or fields, you must deside whether your changes will break backward compatibility.
It's always recommended to leave some fallbacks in our code in order not to force vendors to update their scripts.
In case if you add some major changes or even break compatibility, you MUST bump api version in spec file:
Provides: public_cp_vendors_api = 1.3
That gives ability for vendor's to conflict new version while their scripts are not ready.
## Adding new fields and scripts
Vendors api is highly covered with json schemas checks and python typing to make it
catch all possible vendor errors on the early stage.
Let's imagine that you are trying to add new possible field to `db_info` script.
In order to do that, you must modify python representation first. Go to the `parser.py` and check what
data type is returned. In our case it is `Databases` object:
def db_info(self):
# type: () -> Databases
Find the model in `models.py`, modify it's \_\_slots\_\_ to keep new field.
Next, modify `__init__` to process new fields and save them to model.
That's all for python part.
Next, you must modify script jsonschema that checks responses validity.
It's located in `schemas/db_info.yaml` for our case:
```text
---
type: object
properties:
mysql:
type:
- object
- "null"
properties:
...
```
Don't forget to cover your logic with unittests:
- test_vendors_api.py
- test_vendors_api_cpapi.py
- test_vendors_api_models.py
- test_vendors_api_validation.py
# Review and merging
Please ask @oshyshatskyi, @avolkov or @alutsik about reviewing and merging your change. |