diff --git a/README.md b/README.md index 058313719a501d26def5f55905e01d3af8a465a0..46d270160be0002d4ccc6c1903b69e05c836a278 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,84 @@ # 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 Рё добавления метаданных,