From 5a50ef8faa99fe6111816053fcbb1e774262ef3e Mon Sep 17 00:00:00 2001 From: Maxim Podosochnyy <podosochnyy@perx.ru> Date: Wed, 28 Jun 2023 13:40:25 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B8=D1=81=D0=B0=20=D1=80=D0=B0=D1=81=D1=88=D0=B8?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B8=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=B7=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B5=D0=B9=20=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/README.md b/README.md index 0583137..46d2701 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 Рё добавления метаданных, -- GitLab