galon 1.0.0__py3-none-any.whl
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.
- galon/__init__.py +91 -0
- galon/_errors.py +110 -0
- galon/_generated_models.py +1893 -0
- galon/_generated_resources.py +440 -0
- galon/_generated_routes.py +689 -0
- galon/_generated_services.py +262 -0
- galon/_http.py +146 -0
- galon/_serialize.py +50 -0
- galon/cli.py +345 -0
- galon/cli_complete.py +1055 -0
- galon/galon_catalogue.py +2276 -0
- galon/galon_commandes.py +1019 -0
- galon/galon_connexion.py +295 -0
- galon/mcp_server.py +303 -0
- galon/py.typed +0 -0
- galon/resources.py +53 -0
- galon/terminal.py +122 -0
- galon/webhooks.py +81 -0
- galon-1.0.0.dist-info/METADATA +138 -0
- galon-1.0.0.dist-info/RECORD +23 -0
- galon-1.0.0.dist-info/WHEEL +5 -0
- galon-1.0.0.dist-info/entry_points.txt +3 -0
- galon-1.0.0.dist-info/top_level.txt +1 -0
galon/__init__.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Galon Cloud SDK for Python (standard library only): Mail, AI, Geo, Search, Storage, Backend, Compute, Deploy,
|
|
2
|
+
Domains and Functions.
|
|
3
|
+
|
|
4
|
+
from galon import Galon
|
|
5
|
+
galon = Galon() # reads GALON_API_KEY
|
|
6
|
+
galon.emails.send({"from": "you@your-domain.com", "to": "ana@example.com",
|
|
7
|
+
"subject": "Hi", "html": "<p>Hi</p>"})
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import Any, Optional
|
|
12
|
+
|
|
13
|
+
from ._errors import (GalonAuthenticationError, GalonConflictError, GalonConnectionError, GalonError,
|
|
14
|
+
GalonNotFoundError, GalonPermissionError, GalonRateLimitError, GalonServerError,
|
|
15
|
+
GalonValidationError, GalonWebhookVerificationError)
|
|
16
|
+
from ._http import DEFAULT_BASE_URL, VERSION, HttpClient, backoff, parse_retry_after
|
|
17
|
+
from ._generated_models import * # noqa: F403 — surface publique générée depuis l'OpenAPI
|
|
18
|
+
from ._generated_models import __all__ as _MODEL_NAMES
|
|
19
|
+
from ._serialize import serialize_email
|
|
20
|
+
from .resources import (BETA, RESOURCES, ApiKeys, Artifacts, Batch, Builds, Contacts, Costs,
|
|
21
|
+
DomainActions, Domains, Emails, Estimates, Jobs, Limits, Metering,
|
|
22
|
+
Preparations, Segments, Templates, Tools, Topics, Webhooks,
|
|
23
|
+
Suppressions, ReceivedEmails, ReceivingDomains, Ai, Buckets, Uploads, Objects,
|
|
24
|
+
Storage, Deployments, Deploy, Production, Search)
|
|
25
|
+
from ._generated_services import SERVICE_RESOURCES # lot geo-c : namespaces par service, générés
|
|
26
|
+
from ._generated_services import Backend, Compute, DomainNames, Functions, Geo, Previews, SearchIndexes, StorageExtra
|
|
27
|
+
from .webhooks import (EVENT_ID_HEADER, SIGNATURE_HEADER, compute_signature, parse_signature_header,
|
|
28
|
+
verify_webhook)
|
|
29
|
+
|
|
30
|
+
__version__ = VERSION
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Galon:
|
|
34
|
+
"""Client. Keyword options: base_url, project_id, max_retries, timeout, transport, sleep, idempotency_key."""
|
|
35
|
+
|
|
36
|
+
emails: Emails
|
|
37
|
+
batch: Batch
|
|
38
|
+
jobs: Jobs
|
|
39
|
+
domain_actions: DomainActions
|
|
40
|
+
tools: Tools
|
|
41
|
+
costs: Costs
|
|
42
|
+
metering: Metering
|
|
43
|
+
limits: Limits
|
|
44
|
+
estimates: Estimates
|
|
45
|
+
preparations: Preparations
|
|
46
|
+
builds: Builds
|
|
47
|
+
artifacts: Artifacts
|
|
48
|
+
domains: Domains
|
|
49
|
+
api_keys: ApiKeys
|
|
50
|
+
webhooks: Webhooks
|
|
51
|
+
contacts: Contacts
|
|
52
|
+
segments: Segments
|
|
53
|
+
topics: Topics
|
|
54
|
+
templates: Templates
|
|
55
|
+
suppressions: Suppressions
|
|
56
|
+
received_emails: ReceivedEmails
|
|
57
|
+
receiving_domains: ReceivingDomains
|
|
58
|
+
ai: Ai
|
|
59
|
+
buckets: Buckets
|
|
60
|
+
uploads: Uploads
|
|
61
|
+
objects: Objects
|
|
62
|
+
storage: Storage
|
|
63
|
+
deployments: Deployments
|
|
64
|
+
deploy: Deploy
|
|
65
|
+
production: Production
|
|
66
|
+
search: Search
|
|
67
|
+
search_indexes: SearchIndexes
|
|
68
|
+
storage_extra: StorageExtra
|
|
69
|
+
previews: Previews
|
|
70
|
+
geo: Geo
|
|
71
|
+
compute: Compute
|
|
72
|
+
backend: Backend
|
|
73
|
+
functions: Functions
|
|
74
|
+
domain_names: DomainNames
|
|
75
|
+
|
|
76
|
+
def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
|
|
77
|
+
self.http = HttpClient(api_key, **options)
|
|
78
|
+
for name, cls in {**RESOURCES, **SERVICE_RESOURCES}.items():
|
|
79
|
+
setattr(self, name, cls(self.http))
|
|
80
|
+
|
|
81
|
+
def __repr__(self) -> str:
|
|
82
|
+
return "Galon(%r)" % self.http
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
__all__ = [
|
|
86
|
+
"Galon", "HttpClient", "VERSION", "DEFAULT_BASE_URL", "BETA", "serialize_email", "verify_webhook",
|
|
87
|
+
"compute_signature", "parse_signature_header", "SIGNATURE_HEADER", "EVENT_ID_HEADER", "backoff",
|
|
88
|
+
"parse_retry_after", "GalonError", "GalonValidationError", "GalonAuthenticationError",
|
|
89
|
+
"GalonPermissionError", "GalonNotFoundError", "GalonConflictError", "GalonRateLimitError",
|
|
90
|
+
"GalonServerError", "GalonConnectionError", "GalonWebhookVerificationError",
|
|
91
|
+
] + _MODEL_NAMES
|
galon/_errors.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Typed errors. Every API failure is a ``GalonError``; the subclass tells what to do next."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GalonError(Exception):
|
|
8
|
+
def __init__(self, message: str, *, status: Optional[int] = None, code: str = "galon_error",
|
|
9
|
+
body: Any = None, headers: Optional[Dict[str, str]] = None,
|
|
10
|
+
retry_after: Optional[float] = None,
|
|
11
|
+
next_action: Optional[Dict[str, Any]] = None) -> None:
|
|
12
|
+
super().__init__(message)
|
|
13
|
+
self.message = message
|
|
14
|
+
self.status = status
|
|
15
|
+
self.code = code
|
|
16
|
+
self.body = body
|
|
17
|
+
self.headers = headers or {}
|
|
18
|
+
self.retry_after = retry_after
|
|
19
|
+
#: What to do next, from the API: ``{"code", "hint", "docs_url", "console_url"?}`` (None if absent).
|
|
20
|
+
self.next_action = next_action
|
|
21
|
+
|
|
22
|
+
def __repr__(self) -> str:
|
|
23
|
+
return "%s(status=%r, code=%r, message=%r)" % (type(self).__name__, self.status, self.code, self.message)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class GalonValidationError(GalonError):
|
|
27
|
+
"""400, 413, 422: repair the request before sending it again."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class GalonAuthenticationError(GalonError):
|
|
31
|
+
"""401: missing, invalid, revoked or expired key."""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class GalonPermissionError(GalonError):
|
|
35
|
+
"""403: valid key without the scope (for example ``mail:send``)."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class GalonNotFoundError(GalonError):
|
|
39
|
+
"""404: not visible from this key's tenant, project and environment."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class GalonConflictError(GalonError):
|
|
43
|
+
"""409: idempotency or state conflict. Do not change the intent under the same key."""
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def is_idempotency_conflict(self) -> bool:
|
|
47
|
+
return self.code == "idempotency_conflict"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class GalonRateLimitError(GalonError):
|
|
51
|
+
"""429: quota or rate limit. ``retry_after`` (seconds) carries the server delay when present."""
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class GalonServerError(GalonError):
|
|
55
|
+
"""5xx: temporary failure on Galon's side, after the automatic retries."""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class GalonConnectionError(GalonError):
|
|
59
|
+
"""The request never got an HTTP answer (network, DNS, timeout)."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class GalonWebhookVerificationError(GalonError):
|
|
63
|
+
"""A webhook payload whose signature, timestamp or format does not verify."""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _detail(body: Any):
|
|
67
|
+
if isinstance(body, dict):
|
|
68
|
+
inner = body.get("detail", body.get("error", body))
|
|
69
|
+
if isinstance(inner, dict):
|
|
70
|
+
code = inner.get("code") if isinstance(inner.get("code"), str) else None
|
|
71
|
+
message = inner.get("message") if isinstance(inner.get("message"), str) else None
|
|
72
|
+
return code, message
|
|
73
|
+
if isinstance(inner, str):
|
|
74
|
+
return None, inner
|
|
75
|
+
return None, None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _next_action(body: Any) -> Optional[Dict[str, Any]]:
|
|
79
|
+
"""``detail.next_action``, else a top-level ``next_action`` (when ``detail`` is not an object)."""
|
|
80
|
+
if not isinstance(body, dict):
|
|
81
|
+
return None
|
|
82
|
+
detail = body.get("detail")
|
|
83
|
+
for candidate in ((detail.get("next_action") if isinstance(detail, dict) else None), body.get("next_action")):
|
|
84
|
+
if isinstance(candidate, dict) and isinstance(candidate.get("code"), str) \
|
|
85
|
+
and isinstance(candidate.get("hint"), str):
|
|
86
|
+
return dict(candidate)
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def error_from_response(status: int, body: Any, headers: Dict[str, str],
|
|
91
|
+
retry_after: Optional[float] = None) -> GalonError:
|
|
92
|
+
code, message = _detail(body)
|
|
93
|
+
kw = dict(status=status, code=code or "http_%d" % status, body=body, headers=headers,
|
|
94
|
+
retry_after=retry_after, next_action=_next_action(body))
|
|
95
|
+
message = message or "Galon API answered HTTP %d" % status
|
|
96
|
+
if status == 401:
|
|
97
|
+
return GalonAuthenticationError(message, **kw)
|
|
98
|
+
if status == 403:
|
|
99
|
+
return GalonPermissionError(message, **kw)
|
|
100
|
+
if status == 404:
|
|
101
|
+
return GalonNotFoundError(message, **kw)
|
|
102
|
+
if status == 409:
|
|
103
|
+
return GalonConflictError(message, **kw)
|
|
104
|
+
if status == 429:
|
|
105
|
+
return GalonRateLimitError(message, **kw)
|
|
106
|
+
if status >= 500:
|
|
107
|
+
return GalonServerError(message, **kw)
|
|
108
|
+
if status in (400, 413, 422):
|
|
109
|
+
return GalonValidationError(message, **kw)
|
|
110
|
+
return GalonError(message, **kw)
|