Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scaleway-async/scaleway_async/vpcgw/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
from .types import Gateway
from .types import PatRule
from .types import SetPatRulesRequestRule
from .types import AddBastionAllowedIPsRequest
from .types import AddBastionAllowedIPsResponse
from .types import CreateGatewayNetworkRequest
from .types import CreateGatewayRequest
from .types import CreateIPRequest
from .types import CreatePatRuleRequest
from .types import DeleteBastionAllowedIPsRequest
from .types import DeleteGatewayNetworkRequest
from .types import DeleteGatewayRequest
from .types import DeleteIPRequest
Expand All @@ -38,6 +41,8 @@
from .types import ListPatRulesRequest
from .types import ListPatRulesResponse
from .types import RefreshSSHKeysRequest
from .types import SetBastionAllowedIPsRequest
from .types import SetBastionAllowedIPsResponse
from .types import SetPatRulesRequest
from .types import SetPatRulesResponse
from .types import UpdateGatewayNetworkRequest
Expand All @@ -63,10 +68,13 @@
"Gateway",
"PatRule",
"SetPatRulesRequestRule",
"AddBastionAllowedIPsRequest",
"AddBastionAllowedIPsResponse",
"CreateGatewayNetworkRequest",
"CreateGatewayRequest",
"CreateIPRequest",
"CreatePatRuleRequest",
"DeleteBastionAllowedIPsRequest",
"DeleteGatewayNetworkRequest",
"DeleteGatewayRequest",
"DeleteIPRequest",
Expand All @@ -86,6 +94,8 @@
"ListPatRulesRequest",
"ListPatRulesResponse",
"RefreshSSHKeysRequest",
"SetBastionAllowedIPsRequest",
"SetBastionAllowedIPsResponse",
"SetPatRulesRequest",
"SetPatRulesResponse",
"UpdateGatewayNetworkRequest",
Expand Down
127 changes: 127 additions & 0 deletions scaleway-async/scaleway_async/vpcgw/v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
ListIPsRequestOrderBy,
ListPatRulesRequestOrderBy,
PatRuleProtocol,
AddBastionAllowedIPsRequest,
AddBastionAllowedIPsResponse,
CreateGatewayNetworkRequest,
CreateGatewayRequest,
CreateIPRequest,
Expand All @@ -35,6 +37,8 @@
ListIPsResponse,
ListPatRulesResponse,
PatRule,
SetBastionAllowedIPsRequest,
SetBastionAllowedIPsResponse,
SetPatRulesRequest,
SetPatRulesRequestRule,
SetPatRulesResponse,
Expand All @@ -53,16 +57,20 @@
unmarshal_IP,
unmarshal_Gateway,
unmarshal_PatRule,
unmarshal_AddBastionAllowedIPsResponse,
unmarshal_ListGatewayNetworksResponse,
unmarshal_ListGatewayTypesResponse,
unmarshal_ListGatewaysResponse,
unmarshal_ListIPsResponse,
unmarshal_ListPatRulesResponse,
unmarshal_SetBastionAllowedIPsResponse,
unmarshal_SetPatRulesResponse,
marshal_AddBastionAllowedIPsRequest,
marshal_CreateGatewayNetworkRequest,
marshal_CreateGatewayRequest,
marshal_CreateIPRequest,
marshal_CreatePatRuleRequest,
marshal_SetBastionAllowedIPsRequest,
marshal_SetPatRulesRequest,
marshal_UpdateGatewayNetworkRequest,
marshal_UpdateGatewayRequest,
Expand Down Expand Up @@ -1383,3 +1391,122 @@ async def refresh_ssh_keys(

self._throw_on_error(res)
return unmarshal_Gateway(res.json())

async def add_bastion_allowed_i_ps(
self,
*,
gateway_id: str,
ip_range: str,
zone: Optional[Zone] = None,
) -> AddBastionAllowedIPsResponse:
"""
Add allowed IP range to SSH bastion.
Add an IP range (in CIDR notation) to be allowed to connect to the SSH bastion.
:param gateway_id: ID of the gateway to add the allowed IP range to.
:param ip_range: IP range allowed to connect to the SSH bastion.
:param zone: Zone to target. If none is passed will use default zone from the config.
:return: :class:`AddBastionAllowedIPsResponse <AddBastionAllowedIPsResponse>`

Usage:
::

result = await api.add_bastion_allowed_i_ps(
gateway_id="example",
ip_range="example",
)
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_gateway_id = validate_path_param("gateway_id", gateway_id)

res = self._request(
"POST",
f"/vpc-gw/v2/zones/{param_zone}/gateways/{param_gateway_id}/bastion-allowed-ips",
body=marshal_AddBastionAllowedIPsRequest(
AddBastionAllowedIPsRequest(
gateway_id=gateway_id,
ip_range=ip_range,
zone=zone,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_AddBastionAllowedIPsResponse(res.json())

async def set_bastion_allowed_i_ps(
self,
*,
gateway_id: str,
zone: Optional[Zone] = None,
ip_ranges: Optional[List[str]] = None,
) -> SetBastionAllowedIPsResponse:
"""
Set all IP ranges allowed for SSH bastion.
Set a definitive list of IP ranges (in CIDR notation) allowed to connect to the SSH bastion.
:param gateway_id: ID of the gateway on which to set the allowed IP range.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param ip_ranges: New list of IP ranges (each range in CIDR notation) allowed to connect to the SSH bastion.
:return: :class:`SetBastionAllowedIPsResponse <SetBastionAllowedIPsResponse>`

Usage:
::

result = await api.set_bastion_allowed_i_ps(
gateway_id="example",
)
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_gateway_id = validate_path_param("gateway_id", gateway_id)

res = self._request(
"PUT",
f"/vpc-gw/v2/zones/{param_zone}/gateways/{param_gateway_id}/bastion-allowed-ips",
body=marshal_SetBastionAllowedIPsRequest(
SetBastionAllowedIPsRequest(
gateway_id=gateway_id,
zone=zone,
ip_ranges=ip_ranges,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_SetBastionAllowedIPsResponse(res.json())

async def delete_bastion_allowed_i_ps(
self,
*,
gateway_id: str,
ip_range: str,
zone: Optional[Zone] = None,
) -> None:
"""
Delete allowed IP range from SSH bastion.
Delete an IP range (defined in CIDR notation) from SSH bastion, so that it is no longer allowed to connect.
:param gateway_id: ID of the gateway on which to delete the allowed IP range.
:param ip_range: IP range to delete from SSH bastion's list of allowed IPs.
:param zone: Zone to target. If none is passed will use default zone from the config.

Usage:
::

result = await api.delete_bastion_allowed_i_ps(
gateway_id="example",
ip_range="example",
)
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_gateway_id = validate_path_param("gateway_id", gateway_id)
param_ip_range = validate_path_param("ip_range", ip_range)

res = self._request(
"DELETE",
f"/vpc-gw/v2/zones/{param_zone}/gateways/{param_gateway_id}/bastion-allowed-ips/{param_ip_range}",
)

self._throw_on_error(res)
102 changes: 82 additions & 20 deletions scaleway-async/scaleway_async/vpcgw/v2/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
IP,
Gateway,
PatRule,
AddBastionAllowedIPsResponse,
ListGatewayNetworksResponse,
GatewayType,
ListGatewayTypesResponse,
ListGatewaysResponse,
ListIPsResponse,
ListPatRulesResponse,
SetBastionAllowedIPsResponse,
SetPatRulesResponse,
AddBastionAllowedIPsRequest,
CreateGatewayNetworkRequest,
CreateGatewayRequest,
CreateIPRequest,
CreatePatRuleRequest,
SetBastionAllowedIPsRequest,
SetPatRulesRequestRule,
SetPatRulesRequest,
UpdateGatewayNetworkRequest,
Expand Down Expand Up @@ -183,6 +187,10 @@ def unmarshal_Gateway(data: Any) -> Gateway:
if field is not None:
args["status"] = field

field = data.get("name", None)
if field is not None:
args["name"] = field

field = data.get("created_at", None)
if field is not None:
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
Expand All @@ -195,10 +203,6 @@ def unmarshal_Gateway(data: Any) -> Gateway:
else:
args["updated_at"] = None

field = data.get("name", None)
if field is not None:
args["name"] = field

field = data.get("tags", None)
if field is not None:
args["tags"] = field
Expand All @@ -213,22 +217,6 @@ def unmarshal_Gateway(data: Any) -> Gateway:
if field is not None:
args["bastion_enabled"] = field

field = data.get("bastion_port", None)
if field is not None:
args["bastion_port"] = field

field = data.get("smtp_enabled", None)
if field is not None:
args["smtp_enabled"] = field

field = data.get("is_legacy", None)
if field is not None:
args["is_legacy"] = field

field = data.get("zone", None)
if field is not None:
args["zone"] = field

field = data.get("ipv4", None)
if field is not None:
args["ipv4"] = unmarshal_IP(field)
Expand All @@ -247,6 +235,26 @@ def unmarshal_Gateway(data: Any) -> Gateway:
else:
args["can_upgrade_to"] = None

field = data.get("bastion_port", None)
if field is not None:
args["bastion_port"] = field

field = data.get("smtp_enabled", None)
if field is not None:
args["smtp_enabled"] = field

field = data.get("is_legacy", None)
if field is not None:
args["is_legacy"] = field

field = data.get("bastion_allowed_ips", None)
if field is not None:
args["bastion_allowed_ips"] = field

field = data.get("zone", None)
if field is not None:
args["zone"] = field

return Gateway(**args)


Expand Down Expand Up @@ -301,6 +309,21 @@ def unmarshal_PatRule(data: Any) -> PatRule:
return PatRule(**args)


def unmarshal_AddBastionAllowedIPsResponse(data: Any) -> AddBastionAllowedIPsResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'AddBastionAllowedIPsResponse' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("ip_ranges", None)
if field is not None:
args["ip_ranges"] = field

return AddBastionAllowedIPsResponse(**args)


def unmarshal_ListGatewayNetworksResponse(data: Any) -> ListGatewayNetworksResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down Expand Up @@ -423,6 +446,21 @@ def unmarshal_ListPatRulesResponse(data: Any) -> ListPatRulesResponse:
return ListPatRulesResponse(**args)


def unmarshal_SetBastionAllowedIPsResponse(data: Any) -> SetBastionAllowedIPsResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'SetBastionAllowedIPsResponse' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("ip_ranges", None)
if field is not None:
args["ip_ranges"] = field

return SetBastionAllowedIPsResponse(**args)


def unmarshal_SetPatRulesResponse(data: Any) -> SetPatRulesResponse:
if not isinstance(data, dict):
raise TypeError(
Expand All @@ -440,6 +478,18 @@ def unmarshal_SetPatRulesResponse(data: Any) -> SetPatRulesResponse:
return SetPatRulesResponse(**args)


def marshal_AddBastionAllowedIPsRequest(
request: AddBastionAllowedIPsRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.ip_range is not None:
output["ip_range"] = request.ip_range

return output


def marshal_CreateGatewayNetworkRequest(
request: CreateGatewayNetworkRequest,
defaults: ProfileDefaults,
Expand Down Expand Up @@ -536,6 +586,18 @@ def marshal_CreatePatRuleRequest(
return output


def marshal_SetBastionAllowedIPsRequest(
request: SetBastionAllowedIPsRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.ip_ranges is not None:
output["ip_ranges"] = request.ip_ranges

return output


def marshal_SetPatRulesRequestRule(
request: SetPatRulesRequestRule,
defaults: ProfileDefaults,
Expand Down
Loading
Loading