From 20e8558ceb95ce04c5947a597a81f7ddb7e07742 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 28 Feb 2024 18:33:04 +0700 Subject: [PATCH] planfix client --- .env.template | 4 + chain_service/dependencies/planfix_client.py | 16 ++++ chain_service/settings.py | 3 + poetry.lock | 78 +++++++++++++++++++- pyproject.toml | 1 + 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 chain_service/dependencies/planfix_client.py diff --git a/.env.template b/.env.template index 0c8e1d0..3bd970c 100644 --- a/.env.template +++ b/.env.template @@ -3,6 +3,10 @@ DATABASE_URL=REQUIRED. Example: DATABASE_URL=mongodb://chain-service:password@127.0.0.1:27017 DATABASE_NAME=OPTOINAL. Default: chain-db +# Planfix Rest API +PLANFIX_HOSTNAME=REQUIRED. Example: crm.planfix.com +PLANFIX_TOKEN=REQUIRED + # Poetry (Gitlab Auth Token for PyPi) POETRY_USERNAME=REQUIRED POETRY_PASSWORD=REQUIRED diff --git a/chain_service/dependencies/planfix_client.py b/chain_service/dependencies/planfix_client.py new file mode 100644 index 0000000..211c940 --- /dev/null +++ b/chain_service/dependencies/planfix_client.py @@ -0,0 +1,16 @@ +from planfix_client import PlanfixClient +from chain_service.settings import Settings + +from fastapi import Depends +from typing import Annotated + + +def get_planfix_client() -> PlanfixClient: + settings = Settings() + + return PlanfixClient( + planfix_hostname=settings.planfix_hostname, planfix_token=settings.planfix_token + ) + + +PlanfixClientDependency = Annotated[PlanfixClient, Depends(get_planfix_client)] diff --git a/chain_service/settings.py b/chain_service/settings.py index dbc749b..33bb017 100644 --- a/chain_service/settings.py +++ b/chain_service/settings.py @@ -5,4 +5,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): database_url: str database_name: Optional[str] = "chain-db" + planfix_hostname: str + planfix_token: str + model_config = SettingsConfigDict(env_file=".env") diff --git a/poetry.lock b/poetry.lock index fe73572..1f5bbdd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -31,6 +31,17 @@ doc = ["Sphinx (>=7)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphin test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "uvloop (>=0.17)"] trio = ["trio (>=0.23)"] +[[package]] +name = "certifi" +version = "2024.2.2" +description = "Python package for providing Mozilla's CA Bundle." +optional = false +python-versions = ">=3.6" +files = [ + {file = "certifi-2024.2.2-py3-none-any.whl", hash = "sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1"}, + {file = "certifi-2024.2.2.tar.gz", hash = "sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f"}, +] + [[package]] name = "click" version = "8.1.7" @@ -138,6 +149,51 @@ files = [ {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, ] +[[package]] +name = "httpcore" +version = "1.0.4" +description = "A minimal low-level HTTP client." +optional = false +python-versions = ">=3.8" +files = [ + {file = "httpcore-1.0.4-py3-none-any.whl", hash = "sha256:ac418c1db41bade2ad53ae2f3834a3a0f5ae76b56cf5aa497d2d033384fc7d73"}, + {file = "httpcore-1.0.4.tar.gz", hash = "sha256:cb2839ccfcba0d2d3c1131d3c3e26dfc327326fbe7a5dc0dbfe9f6c9151bb022"}, +] + +[package.dependencies] +certifi = "*" +h11 = ">=0.13,<0.15" + +[package.extras] +asyncio = ["anyio (>=4.0,<5.0)"] +http2 = ["h2 (>=3,<5)"] +socks = ["socksio (==1.*)"] +trio = ["trio (>=0.22.0,<0.25.0)"] + +[[package]] +name = "httpx" +version = "0.27.0" +description = "The next generation HTTP client." +optional = false +python-versions = ">=3.8" +files = [ + {file = "httpx-0.27.0-py3-none-any.whl", hash = "sha256:71d5465162c13681bff01ad59b2cc68dd838ea1f10e51574bac27103f00c91a5"}, + {file = "httpx-0.27.0.tar.gz", hash = "sha256:a0cb88a46f32dc874e04ee956e4c2764aba2aa228f650b06788ba6bda2962ab5"}, +] + +[package.dependencies] +anyio = "*" +certifi = "*" +httpcore = "==1.*" +idna = "*" +sniffio = "*" + +[package.extras] +brotli = ["brotli", "brotlicffi"] +cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"] +http2 = ["h2 (>=3,<5)"] +socks = ["socksio (==1.*)"] + [[package]] name = "idna" version = "3.6" @@ -202,6 +258,26 @@ srv = ["pymongo[srv] (>=4.5,<5)"] test = ["aiohttp (<3.8.6)", "mockupdb", "motor[encryption]", "pytest (>=7)", "tornado (>=5)"] zstd = ["pymongo[zstd] (>=4.5,<5)"] +[[package]] +name = "planfix-client" +version = "0.1.3" +description = "" +optional = false +python-versions = ">=3.12,<4.0" +files = [ + {file = "planfix_client-0.1.3-py3-none-any.whl", hash = "sha256:e701adc263c89602dadfbb7a95624714b37302f8cab753a5d32de514a54d593f"}, + {file = "planfix_client-0.1.3.tar.gz", hash = "sha256:e3e793ab5b0132e8035b7c75bcae91780a6a888dc20d0ef8b174b707f438acae"}, +] + +[package.dependencies] +httpx = ">=0.27.0,<0.28.0" +loguru = ">=0.7.2,<0.8.0" + +[package.source] +type = "legacy" +url = "https://gitlab.com/api/v4/groups/82963914/-/packages/pypi/simple" +reference = "gitlab" + [[package]] name = "pycodestyle" version = "2.11.1" @@ -544,4 +620,4 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "28773ead745eb18500da153a3309d6fc967461497b9c5ceb18bcfaea1a8f1647" +content-hash = "5fa2301a3493a9a6a28c5b253c5af679e2c757478858fa58f6e382c804f13182" diff --git a/pyproject.toml b/pyproject.toml index 367343e..97bb8a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ uvicorn = "^0.27.1" motor = "^3.3.2" pydantic-settings = "^2.2.1" loguru = "^0.7.2" +planfix-client = "^0.1.3" [build-system] requires = ["poetry-core"]