Skip to content
Snippets Groups Projects

Добавлен базовый класс для сервиса расширений и модуль для установки зависимостей расширения

Merged Podosochnyy Maxim requested to merge feature/add-ext-service into master
All threads resolved!
1 file
+ 79
0
Compare changes
  • Side-by-side
  • Inline
+ 79
0
# perxis-python
# perxis-python
 
## Расширения
 
### Пример подключения расширения к Perxis
 
...
 
 
### Пример написания сервиса расширений
 
```python
 
from perxis.extensions.extension_service import ExtensionService
 
from perxis.roles import roles_pb2
 
from perxis.common import common_pb2
 
from perxis.clients import clients_pb2
 
 
from perxis.collections import collections_pb2
 
 
 
def make_collection_instances(schemes_mapping: dict[str, str]) -> list[collections_pb2.Collection]:
 
collections = []
 
 
for collection_id, collection_name in schemes_mapping.items():
 
with open(f"./schemes/{collection_id}.json", "r") as file:
 
collection_schema = file.read()
 
 
collection = collections_pb2.Collection(
 
id=collection_id,
 
name=collection_name,
 
schema=collection_schema
 
)
 
 
collections.append(collection)
 
 
return collections
 
 
...
 
 
schemes_mapping = {
 
"dealers_cities": "Дилеры/Города",
 
"dealers_contacts": "Дилеры/Контакты",
 
"dealers_countries": "Дилеры/Страны",
 
"dealers_dealers": "Дилеры/Дилеры",
 
"dealers_dealerships": "Дилеры/Дилерские центры",
 
"dealers_department_types": "Дилеры/Типы отделов",
 
"dealers_departments": "Дилеры/Отделы",
 
"dealers_events": "Дилеры/События",
 
"dealers_identifiers": "Дилеры/Идентификаторы",
 
"dealers_schedules": "Дилеры/Графики работы",
 
"dealers_services": "Дилеры/Услуги"
 
}
 
 
...
 
 
class Servicer(ExtensionService):
 
extension_id = "some_id"
 
collections = make_collection_instances(schemes_mapping)
 
roles = [
 
roles_pb2.Role(
 
id="my-role",
 
description="Описание к роли",
 
rules=[
 
common_pb2.Rule(
 
collection_id="dealers_cities",
 
actions=[common_pb2.CREATE, common_pb2.UPDATE, common_pb2.DELETE],
 
)
 
],
 
environments=["*"],
 
allow_management=False,
 
)
 
]
 
clients = [
 
clients_pb2.Client(
 
id="my-client",
 
name="Клиент, созданный расширением",
 
description="Описание созданного расширением клиента",
 
role_id="my-role",
 
api_key={
 
"rotate": True
 
}
 
)
 
]
 
```
 
## Аутентификация
## Аутентификация
gRPC Python предоставляет способ перехвата RPC и добавления метаданных,
gRPC Python предоставляет способ перехвата RPC и добавления метаданных,
Loading