multiservice-tools 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- multiservice_tools-0.1.0/LICENSE +0 -0
- multiservice_tools-0.1.0/MANIFEST.in +15 -0
- multiservice_tools-0.1.0/PKG-INFO +16 -0
- multiservice_tools-0.1.0/README.md +0 -0
- multiservice_tools-0.1.0/multiservice-tools/__init__.py +4 -0
- multiservice_tools-0.1.0/multiservice-tools/auth.py +37 -0
- multiservice_tools-0.1.0/multiservice-tools/client.py +25 -0
- multiservice_tools-0.1.0/multiservice-tools/exceptions.py +0 -0
- multiservice_tools-0.1.0/multiservice-tools/models.py +0 -0
- multiservice_tools-0.1.0/multiservice_tools.egg-info/PKG-INFO +16 -0
- multiservice_tools-0.1.0/multiservice_tools.egg-info/SOURCES.txt +15 -0
- multiservice_tools-0.1.0/multiservice_tools.egg-info/dependency_links.txt +1 -0
- multiservice_tools-0.1.0/multiservice_tools.egg-info/requires.txt +7 -0
- multiservice_tools-0.1.0/multiservice_tools.egg-info/top_level.txt +1 -0
- multiservice_tools-0.1.0/pyproject.toml +18 -0
- multiservice_tools-0.1.0/setup.cfg +4 -0
- multiservice_tools-0.1.0/setup.py +14 -0
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
include setup.py
|
|
5
|
+
|
|
6
|
+
recursive-include multiservice_tools *.py
|
|
7
|
+
recursive-include multiservice_tools *.md
|
|
8
|
+
|
|
9
|
+
# Wykluczamy niepotrzebne rzeczy
|
|
10
|
+
global-exclude *.pyc
|
|
11
|
+
global-exclude *.pyo
|
|
12
|
+
global-exclude __pycache__/*
|
|
13
|
+
global-exclude .git/*
|
|
14
|
+
global-exclude .gitignore
|
|
15
|
+
global-exclude .env
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: multiservice-tools
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Wspólne narzędzia do komunikacji z serwisami (Auth + Media + inne)
|
|
5
|
+
Author: Marcin Kallas
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: httpx>=0.27.0
|
|
10
|
+
Requires-Dist: pydantic>=2.0
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: black; extra == "dev"
|
|
13
|
+
Requires-Dist: isort; extra == "dev"
|
|
14
|
+
Requires-Dist: mypy; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
Dynamic: requires-python
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import hashlib
|
|
3
|
+
import hmac
|
|
4
|
+
from typing import Optional, Dict
|
|
5
|
+
|
|
6
|
+
class AuthManager:
|
|
7
|
+
"""Zarządzanie autoryzacją"""
|
|
8
|
+
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
jwt_token: Optional[str] = None,
|
|
12
|
+
api_key: Optional[str] = None,
|
|
13
|
+
secret_key: Optional[str] = None
|
|
14
|
+
):
|
|
15
|
+
self.jwt_token = jwt_token
|
|
16
|
+
self.api_key = api_key
|
|
17
|
+
self.secret_key = secret_key
|
|
18
|
+
|
|
19
|
+
async def get_headers(self) -> Dict:
|
|
20
|
+
headers = {}
|
|
21
|
+
|
|
22
|
+
if self.jwt_token:
|
|
23
|
+
headers["Authorization"] = f"Bearer {self.jwt_token}"
|
|
24
|
+
elif self.api_key and self.secret_key:
|
|
25
|
+
timestamp = str(int(time.time()))
|
|
26
|
+
headers["X-API-Key"] = self.api_key
|
|
27
|
+
headers["X-Timestamp"] = timestamp
|
|
28
|
+
headers["X-Signature"] = self._calculate_signature(timestamp)
|
|
29
|
+
|
|
30
|
+
return headers
|
|
31
|
+
|
|
32
|
+
def _calculate_signature(self, timestamp: str, method: str = "GET", path: str = "") -> str:
|
|
33
|
+
"""Oblicza sygnaturę HMAC-SHA256"""
|
|
34
|
+
if not self.api_key or not self.secret_key:
|
|
35
|
+
raise ValueError("API key and secret key must be provided for signature calculation.")
|
|
36
|
+
message = f"{self.api_key[-8:]}{method}\n{path}\n{timestamp}".encode()
|
|
37
|
+
return hmac.new(self.secret_key.encode(), message, hashlib.sha256).hexdigest()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from typing import Optional, Dict, Any
|
|
3
|
+
from .auth import AuthManager
|
|
4
|
+
|
|
5
|
+
class MultiServiceClient:
|
|
6
|
+
"""Uniwersalny klient do serwisów"""
|
|
7
|
+
|
|
8
|
+
def __init__(self, base_url: str, auth_manager: AuthManager):
|
|
9
|
+
self.base_url = base_url.rstrip("/")
|
|
10
|
+
self.client = httpx.AsyncClient(timeout=15.0)
|
|
11
|
+
self.auth = auth_manager
|
|
12
|
+
|
|
13
|
+
async def get(self, endpoint: str, params: Optional[Dict] = None):
|
|
14
|
+
headers = await self.auth.get_headers()
|
|
15
|
+
response = await self.client.get(f"{self.base_url}{endpoint}", params=params, headers=headers)
|
|
16
|
+
response.raise_for_status()
|
|
17
|
+
return response.json()
|
|
18
|
+
|
|
19
|
+
async def post(self, endpoint: str, json: Optional[Dict] = None):
|
|
20
|
+
headers = await self.auth.get_headers()
|
|
21
|
+
response = await self.client.post(f"{self.base_url}{endpoint}", json=json, headers=headers)
|
|
22
|
+
response.raise_for_status()
|
|
23
|
+
return response.json()
|
|
24
|
+
|
|
25
|
+
# put, delete, patch...
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: multiservice-tools
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Wspólne narzędzia do komunikacji z serwisami (Auth + Media + inne)
|
|
5
|
+
Author: Marcin Kallas
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: httpx>=0.27.0
|
|
10
|
+
Requires-Dist: pydantic>=2.0
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: black; extra == "dev"
|
|
13
|
+
Requires-Dist: isort; extra == "dev"
|
|
14
|
+
Requires-Dist: mypy; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
Dynamic: requires-python
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.py
|
|
6
|
+
multiservice-tools/__init__.py
|
|
7
|
+
multiservice-tools/auth.py
|
|
8
|
+
multiservice-tools/client.py
|
|
9
|
+
multiservice-tools/exceptions.py
|
|
10
|
+
multiservice-tools/models.py
|
|
11
|
+
multiservice_tools.egg-info/PKG-INFO
|
|
12
|
+
multiservice_tools.egg-info/SOURCES.txt
|
|
13
|
+
multiservice_tools.egg-info/dependency_links.txt
|
|
14
|
+
multiservice_tools.egg-info/requires.txt
|
|
15
|
+
multiservice_tools.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "multiservice-tools"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Wspólne narzędzia do komunikacji z serwisami (Auth + Media + inne)"
|
|
5
|
+
authors = [{ name = "Marcin Kallas" }]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"httpx>=0.27.0",
|
|
10
|
+
"pydantic>=2.0",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[project.optional-dependencies]
|
|
14
|
+
dev = ["black", "isort", "mypy"]
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
where = ["."]
|
|
18
|
+
include = ["multiservice_tools*"]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="multiservice-tools",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
install_requires=[
|
|
8
|
+
"httpx>=0.27.0",
|
|
9
|
+
"pydantic>=2.0",
|
|
10
|
+
],
|
|
11
|
+
author="Your Name",
|
|
12
|
+
description="Wspólne narzędzia do komunikacji z serwisami",
|
|
13
|
+
python_requires=">=3.10",
|
|
14
|
+
)
|