-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathasync_network_policy.py
More file actions
109 lines (93 loc) · 3.46 KB
/
Copy pathasync_network_policy.py
File metadata and controls
109 lines (93 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""NetworkPolicy resource class for asynchronous operations."""
from __future__ import annotations
from typing import Optional
from typing_extensions import Unpack, override
from ._types import BaseRequestOptions, LongRequestOptions
from .._types import SequenceNotStr
from .._client import AsyncRunloop
from ..types.network_policy_view import NetworkPolicyView
class AsyncNetworkPolicy:
"""Asynchronous wrapper around a network policy resource."""
def __init__(
self,
client: AsyncRunloop,
network_policy_id: str,
) -> None:
"""Initialize the wrapper.
:param client: Generated AsyncRunloop client
:type client: AsyncRunloop
:param network_policy_id: NetworkPolicy ID returned by the API
:type network_policy_id: str
"""
self._client = client
self._id = network_policy_id
@override
def __repr__(self) -> str:
return f"<AsyncNetworkPolicy id={self._id!r}>"
@property
def id(self) -> str:
"""Return the network policy ID.
:return: Unique network policy ID
:rtype: str
"""
return self._id
async def get_info(
self,
**options: Unpack[BaseRequestOptions],
) -> NetworkPolicyView:
"""Retrieve the latest network policy details.
:param options: Optional request configuration
:return: API response describing the network policy
:rtype: NetworkPolicyView
"""
return await self._client.network_policies.retrieve(
self._id,
**options,
)
async def update(
self,
*,
allow_all: Optional[bool] = None,
allow_devbox_to_devbox: Optional[bool] = None,
allowed_hostnames: Optional[SequenceNotStr[str]] = None,
description: Optional[str] = None,
name: Optional[str] = None,
**options: Unpack[LongRequestOptions],
) -> NetworkPolicyView:
"""Update the network policy.
:param allow_all: If true, all egress traffic is allowed (ALLOW_ALL policy)
:type allow_all: Optional[bool]
:param allow_devbox_to_devbox: If true, allows traffic between devboxes via tunnels
:type allow_devbox_to_devbox: Optional[bool]
:param allowed_hostnames: DNS-based allow list with wildcard support
:type allowed_hostnames: Optional[SequenceNotStr[str]]
:param description: Updated description for the NetworkPolicy
:type description: Optional[str]
:param name: Updated human-readable name for the NetworkPolicy
:type name: Optional[str]
:param options: Optional long-running request configuration
:return: Updated network policy view
:rtype: NetworkPolicyView
"""
return await self._client.network_policies.update(
self._id,
allow_all=allow_all,
allow_devbox_to_devbox=allow_devbox_to_devbox,
allowed_hostnames=allowed_hostnames,
description=description,
name=name,
**options,
)
async def delete(
self,
**options: Unpack[LongRequestOptions],
) -> NetworkPolicyView:
"""Delete the network policy.
:param options: Optional long-running request configuration
:return: API response acknowledging deletion
:rtype: NetworkPolicyView
"""
return await self._client.network_policies.delete(
self._id,
**options,
)