dock-thor-client 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.
- dock_thor_client-0.1.0/LICENSE +21 -0
- dock_thor_client-0.1.0/PKG-INFO +10 -0
- dock_thor_client-0.1.0/README.md +0 -0
- dock_thor_client-0.1.0/dock_thor/__init__.py +3 -0
- dock_thor_client-0.1.0/dock_thor/client.py +28 -0
- dock_thor_client-0.1.0/dock_thor/models.py +82 -0
- dock_thor_client-0.1.0/dock_thor/serializer.py +19 -0
- dock_thor_client-0.1.0/dock_thor/transport.py +25 -0
- dock_thor_client-0.1.0/dock_thor_client.egg-info/PKG-INFO +10 -0
- dock_thor_client-0.1.0/dock_thor_client.egg-info/SOURCES.txt +13 -0
- dock_thor_client-0.1.0/dock_thor_client.egg-info/dependency_links.txt +1 -0
- dock_thor_client-0.1.0/dock_thor_client.egg-info/requires.txt +1 -0
- dock_thor_client-0.1.0/dock_thor_client.egg-info/top_level.txt +1 -0
- dock_thor_client-0.1.0/pyproject.toml +12 -0
- dock_thor_client-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jacek Labudda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dock-thor-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for Dock THOR error reporting
|
|
5
|
+
Author: Jacek Labudda
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: httpx>=0.27.0
|
|
10
|
+
Dynamic: license-file
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from .models import AuthData, Event
|
|
3
|
+
from .transport import HttpTransport
|
|
4
|
+
|
|
5
|
+
class DockThorClient:
|
|
6
|
+
def __init__(self, token: str, private_key: str, environment: str = "production"):
|
|
7
|
+
self.auth = AuthData(token=token, private_key=private_key)
|
|
8
|
+
self.transport = HttpTransport(self.auth)
|
|
9
|
+
self.environment = environment
|
|
10
|
+
|
|
11
|
+
async def capture_event(self, event: Event):
|
|
12
|
+
await self.transport.send(event)
|
|
13
|
+
|
|
14
|
+
async def capture_exception(self, exc: Exception):
|
|
15
|
+
event = Event.from_exception(exc, environment=self.environment)
|
|
16
|
+
await self.capture_event(event)
|
|
17
|
+
|
|
18
|
+
async def capture_message(self, message: str, level="info"):
|
|
19
|
+
event = Event.from_message(message, level=level, environment=self.environment)
|
|
20
|
+
await self.capture_event(event)
|
|
21
|
+
|
|
22
|
+
async def close(self):
|
|
23
|
+
await self.transport.close()
|
|
24
|
+
|
|
25
|
+
# Sync helper
|
|
26
|
+
def capture_message(token: str, private_key: str, message: str, level="info"):
|
|
27
|
+
client = DockThorClient(token, private_key)
|
|
28
|
+
asyncio.run(client.capture_message(message, level))
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
import platform
|
|
4
|
+
import socket
|
|
5
|
+
import os
|
|
6
|
+
import traceback
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class AuthData:
|
|
11
|
+
token: str
|
|
12
|
+
private_key: str
|
|
13
|
+
scheme: str = "https"
|
|
14
|
+
host: str = "pab.creativa.studio"
|
|
15
|
+
path: str = "/api/v1"
|
|
16
|
+
|
|
17
|
+
def base_url(self):
|
|
18
|
+
return f"{self.scheme}://{self.host}{self.path}/{self.token}"
|
|
19
|
+
|
|
20
|
+
def project_url(self):
|
|
21
|
+
return f"{self.base_url()}/project/"
|
|
22
|
+
|
|
23
|
+
def transaction_url(self):
|
|
24
|
+
return f"{self.base_url()}/transaction/"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class Event:
|
|
29
|
+
event_id: str
|
|
30
|
+
timestamp: str
|
|
31
|
+
level: str
|
|
32
|
+
message: str
|
|
33
|
+
platform: str
|
|
34
|
+
server_name: str
|
|
35
|
+
environment: str
|
|
36
|
+
extra: dict
|
|
37
|
+
tags: dict
|
|
38
|
+
exception: dict | None = None
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def from_exception(cls, exc: Exception, level="error", environment="production"):
|
|
42
|
+
return cls(
|
|
43
|
+
event_id=os.urandom(8).hex(),
|
|
44
|
+
timestamp=datetime.utcnow().isoformat() + "Z",
|
|
45
|
+
level=level,
|
|
46
|
+
message=str(exc),
|
|
47
|
+
platform="python",
|
|
48
|
+
server_name=socket.gethostname(),
|
|
49
|
+
environment=environment,
|
|
50
|
+
extra={
|
|
51
|
+
"python_version": sys.version,
|
|
52
|
+
"cwd": os.getcwd(),
|
|
53
|
+
},
|
|
54
|
+
tags={
|
|
55
|
+
"os": platform.system(),
|
|
56
|
+
"release": platform.release(),
|
|
57
|
+
},
|
|
58
|
+
exception={
|
|
59
|
+
"type": exc.__class__.__name__,
|
|
60
|
+
"traceback": traceback.format_exc(),
|
|
61
|
+
},
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def from_message(cls, message: str, level="info", environment="production"):
|
|
66
|
+
return cls(
|
|
67
|
+
event_id=os.urandom(8).hex(),
|
|
68
|
+
timestamp=datetime.utcnow().isoformat() + "Z",
|
|
69
|
+
level=level,
|
|
70
|
+
message=message,
|
|
71
|
+
platform="python",
|
|
72
|
+
server_name=socket.gethostname(),
|
|
73
|
+
environment=environment,
|
|
74
|
+
extra={
|
|
75
|
+
"python_version": sys.version,
|
|
76
|
+
"cwd": os.getcwd(),
|
|
77
|
+
},
|
|
78
|
+
tags={
|
|
79
|
+
"os": platform.system(),
|
|
80
|
+
"release": platform.release(),
|
|
81
|
+
},
|
|
82
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from .models import Event
|
|
3
|
+
|
|
4
|
+
class PayloadSerializer:
|
|
5
|
+
@staticmethod
|
|
6
|
+
def serialize(event: Event) -> str:
|
|
7
|
+
"""Zamienia Event w JSON zgodny z API."""
|
|
8
|
+
return json.dumps({
|
|
9
|
+
"event_id": event.event_id,
|
|
10
|
+
"timestamp": event.timestamp,
|
|
11
|
+
"level": event.level,
|
|
12
|
+
"platform": event.platform,
|
|
13
|
+
"server_name": event.server_name,
|
|
14
|
+
"environment": event.environment,
|
|
15
|
+
"message": event.message,
|
|
16
|
+
"extra": event.extra,
|
|
17
|
+
"tags": event.tags,
|
|
18
|
+
"exception": event.exception,
|
|
19
|
+
}, ensure_ascii=False)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from .models import AuthData
|
|
3
|
+
from .serializer import PayloadSerializer
|
|
4
|
+
|
|
5
|
+
class HttpTransport:
|
|
6
|
+
def __init__(self, auth: AuthData):
|
|
7
|
+
self.auth = auth
|
|
8
|
+
self.client = httpx.AsyncClient(timeout=10)
|
|
9
|
+
|
|
10
|
+
async def send(self, event, transaction=False):
|
|
11
|
+
serializer = PayloadSerializer()
|
|
12
|
+
content = serializer.serialize(event)
|
|
13
|
+
url = self.auth.transaction_url() if transaction else self.auth.project_url()
|
|
14
|
+
|
|
15
|
+
headers = {
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
"Authorization": f"Bearer {self.auth.private_key}",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
response = await self.client.post(url, headers=headers, content=content)
|
|
21
|
+
response.raise_for_status()
|
|
22
|
+
return response
|
|
23
|
+
|
|
24
|
+
async def close(self):
|
|
25
|
+
await self.client.aclose()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dock-thor-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for Dock THOR error reporting
|
|
5
|
+
Author: Jacek Labudda
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: httpx>=0.27.0
|
|
10
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
dock_thor/__init__.py
|
|
5
|
+
dock_thor/client.py
|
|
6
|
+
dock_thor/models.py
|
|
7
|
+
dock_thor/serializer.py
|
|
8
|
+
dock_thor/transport.py
|
|
9
|
+
dock_thor_client.egg-info/PKG-INFO
|
|
10
|
+
dock_thor_client.egg-info/SOURCES.txt
|
|
11
|
+
dock_thor_client.egg-info/dependency_links.txt
|
|
12
|
+
dock_thor_client.egg-info/requires.txt
|
|
13
|
+
dock_thor_client.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
httpx>=0.27.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dock_thor
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "dock-thor-client"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python client for Dock THOR error reporting"
|
|
5
|
+
authors = [{ name = "Jacek Labudda" }]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.9"
|
|
8
|
+
dependencies = ["httpx>=0.27.0"]
|
|
9
|
+
|
|
10
|
+
[build-system]
|
|
11
|
+
requires = ["setuptools>=61.0"]
|
|
12
|
+
build-backend = "setuptools.build_meta"
|