Skip to content

Commit aa5b8b1

Browse files
committed
python: Add Environment resource
1 parent c4709aa commit aa5b8b1

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

codegen.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ output_dir = "svix-cli/src/cmds/api"
6161
[python]
6262
template_dir = "python/templates"
6363
extra_shell_commands = [
64-
"rm python/svix/api/{environment,health,ingest}.py",
64+
"rm python/svix/api/{health,ingest}.py",
6565
]
6666
[[python.task]]
6767
template = "python/templates/api_resource.py.jinja"

python/svix/api/environment.py

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# This file is @generated
2+
import typing as t
3+
from dataclasses import dataclass
4+
5+
from ..models import EnvironmentIn, EnvironmentOut
6+
from .common import ApiBase, BaseOptions, serialize_params
7+
8+
9+
@dataclass
10+
class EnvironmentExportOptions(BaseOptions):
11+
idempotency_key: t.Optional[str] = None
12+
13+
def _header_params(self) -> t.Dict[str, str]:
14+
return serialize_params(
15+
{
16+
"idempotency-key": self.idempotency_key,
17+
}
18+
)
19+
20+
21+
@dataclass
22+
class EnvironmentImportOptions(BaseOptions):
23+
idempotency_key: t.Optional[str] = None
24+
25+
def _header_params(self) -> t.Dict[str, str]:
26+
return serialize_params(
27+
{
28+
"idempotency-key": self.idempotency_key,
29+
}
30+
)
31+
32+
33+
class EnvironmentAsync(ApiBase):
34+
async def export(
35+
self, options: EnvironmentExportOptions = EnvironmentExportOptions()
36+
) -> EnvironmentOut:
37+
"""Download a JSON file containing all org-settings and event types."""
38+
response = await self._request_asyncio(
39+
method="post",
40+
path="/api/v1/environment/export",
41+
path_params={},
42+
query_params=options._query_params(),
43+
header_params=options._header_params(),
44+
)
45+
return EnvironmentOut.model_validate(response.json())
46+
47+
async def import_(
48+
self,
49+
environment_in: EnvironmentIn,
50+
options: EnvironmentImportOptions = EnvironmentImportOptions(),
51+
) -> None:
52+
"""Import a configuration into the active organization.
53+
54+
It doesn't delete anything, only adds / updates what was passed to it."""
55+
await self._request_asyncio(
56+
method="post",
57+
path="/api/v1/environment/import",
58+
path_params={},
59+
query_params=options._query_params(),
60+
header_params=options._header_params(),
61+
json_body=environment_in.model_dump_json(exclude_unset=True, by_alias=True),
62+
)
63+
64+
65+
class Environment(ApiBase):
66+
def export(
67+
self, options: EnvironmentExportOptions = EnvironmentExportOptions()
68+
) -> EnvironmentOut:
69+
"""Download a JSON file containing all org-settings and event types."""
70+
response = self._request_sync(
71+
method="post",
72+
path="/api/v1/environment/export",
73+
path_params={},
74+
query_params=options._query_params(),
75+
header_params=options._header_params(),
76+
)
77+
return EnvironmentOut.model_validate(response.json())
78+
79+
def import_(
80+
self,
81+
environment_in: EnvironmentIn,
82+
options: EnvironmentImportOptions = EnvironmentImportOptions(),
83+
) -> None:
84+
"""Import a configuration into the active organization.
85+
86+
It doesn't delete anything, only adds / updates what was passed to it."""
87+
self._request_sync(
88+
method="post",
89+
path="/api/v1/environment/import",
90+
path_params={},
91+
query_params=options._query_params(),
92+
header_params=options._header_params(),
93+
json_body=environment_in.model_dump_json(exclude_unset=True, by_alias=True),
94+
)

python/svix/api/svix.py

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .application import Application, ApplicationAsync
55
from .authentication import Authentication, AuthenticationAsync
66
from .endpoint import Endpoint, EndpointAsync
7+
from .environment import Environment, EnvironmentAsync
78
from .event_type import EventType, EventTypeAsync
89
from .integration import Integration, IntegrationAsync
910
from .message import Message, MessageAsync
@@ -88,6 +89,10 @@ def application(self) -> ApplicationAsync:
8889
def endpoint(self) -> EndpointAsync:
8990
return EndpointAsync(self._client)
9091

92+
@property
93+
def environment(self) -> EnvironmentAsync:
94+
return EnvironmentAsync(self._client)
95+
9196
@property
9297
def event_type(self) -> EventTypeAsync:
9398
return EventTypeAsync(self._client)
@@ -130,6 +135,10 @@ def application(self) -> Application:
130135
def endpoint(self) -> Endpoint:
131136
return Endpoint(self._client)
132137

138+
@property
139+
def environment(self) -> Environment:
140+
return Environment(self._client)
141+
133142
@property
134143
def event_type(self) -> EventType:
135144
return EventType(self._client)

0 commit comments

Comments
 (0)