cloudflare-python/src/cloudflare/resources/magic_transit/ipsec_tunnels.py
stainless-app[bot] ef37bfc0eb
Some checks are pending
CI / lint (push) Waiting to run
CI / build (push) Waiting to run
CI / test (push) Waiting to run
CI / examples (push) Waiting to run
chore(api): update composite API spec
2025-12-09 23:38:46 +00:00

1161 lines
48 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Type, cast
import httpx
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ..._utils import is_given, maybe_transform, strip_not_given, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
to_raw_response_wrapper,
to_streamed_response_wrapper,
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from ..._wrappers import ResultWrapper
from ..._base_client import make_request_options
from ...types.magic_transit import (
ipsec_tunnel_create_params,
ipsec_tunnel_update_params,
ipsec_tunnel_bulk_update_params,
ipsec_tunnel_psk_generate_params,
)
from ...types.magic_transit.ipsec_tunnel_get_response import IPSECTunnelGetResponse
from ...types.magic_transit.ipsec_tunnel_list_response import IPSECTunnelListResponse
from ...types.magic_transit.ipsec_tunnel_create_response import IPSECTunnelCreateResponse
from ...types.magic_transit.ipsec_tunnel_delete_response import IPSECTunnelDeleteResponse
from ...types.magic_transit.ipsec_tunnel_update_response import IPSECTunnelUpdateResponse
from ...types.magic_transit.ipsec_tunnel_bulk_update_response import IPSECTunnelBulkUpdateResponse
from ...types.magic_transit.ipsec_tunnel_psk_generate_response import IPSECTunnelPSKGenerateResponse
__all__ = ["IPSECTunnelsResource", "AsyncIPSECTunnelsResource"]
class IPSECTunnelsResource(SyncAPIResource):
@cached_property
def with_raw_response(self) -> IPSECTunnelsResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
"""
return IPSECTunnelsResourceWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> IPSECTunnelsResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response
"""
return IPSECTunnelsResourceWithStreamingResponse(self)
def create(
self,
*,
account_id: str,
cloudflare_endpoint: str,
interface_address: str,
name: str,
automatic_return_routing: bool | Omit = omit,
bgp: ipsec_tunnel_create_params.BGP | Omit = omit,
custom_remote_identities: ipsec_tunnel_create_params.CustomRemoteIdentities | Omit = omit,
customer_endpoint: str | Omit = omit,
description: str | Omit = omit,
health_check: ipsec_tunnel_create_params.HealthCheck | Omit = omit,
interface_address6: str | Omit = omit,
psk: str | Omit = omit,
replay_protection: bool | Omit = omit,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelCreateResponse:
"""Creates a new IPsec tunnel associated with an account.
Use `?validate_only=true`
as an optional query parameter to only run validation without persisting
changes.
Args:
account_id: Identifier
cloudflare_endpoint: The IP address assigned to the Cloudflare side of the IPsec tunnel.
interface_address: A 31-bit prefix (/31 in CIDR notation) supporting two hosts, one for each side
of the tunnel. Select the subnet from the following private IP space:
10.0.0.010.255.255.255, 172.16.0.0172.31.255.255, 192.168.0.0192.168.255.255.
name: The name of the IPsec tunnel. The name cannot share a name with other tunnels.
automatic_return_routing: True if automatic stateful return routing should be enabled for a tunnel, false
otherwise.
customer_endpoint: The IP address assigned to the customer side of the IPsec tunnel. Not required,
but must be set for proactive traceroutes to work.
description: An optional description forthe IPsec tunnel.
interface_address6: A 127 bit IPV6 prefix from within the virtual_subnet6 prefix space with the
address being the first IP of the subnet and not same as the address of
virtual_subnet6. Eg if virtual_subnet6 is 2606:54c1:7:0:a9fe:12d2::/127 ,
interface_address6 could be 2606:54c1:7:0:a9fe:12d2:1:200/127
psk: A randomly generated or provided string for use in the IPsec tunnel.
replay_protection: If `true`, then IPsec replay protection will be supported in the
Cloudflare-to-customer direction.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return self._post(
f"/accounts/{account_id}/magic/ipsec_tunnels",
body=maybe_transform(
{
"cloudflare_endpoint": cloudflare_endpoint,
"interface_address": interface_address,
"name": name,
"automatic_return_routing": automatic_return_routing,
"bgp": bgp,
"custom_remote_identities": custom_remote_identities,
"customer_endpoint": customer_endpoint,
"description": description,
"health_check": health_check,
"interface_address6": interface_address6,
"psk": psk,
"replay_protection": replay_protection,
},
ipsec_tunnel_create_params.IPSECTunnelCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelCreateResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelCreateResponse], ResultWrapper[IPSECTunnelCreateResponse]),
)
def update(
self,
ipsec_tunnel_id: str,
*,
account_id: str,
cloudflare_endpoint: str,
interface_address: str,
name: str,
automatic_return_routing: bool | Omit = omit,
bgp: ipsec_tunnel_update_params.BGP | Omit = omit,
custom_remote_identities: ipsec_tunnel_update_params.CustomRemoteIdentities | Omit = omit,
customer_endpoint: str | Omit = omit,
description: str | Omit = omit,
health_check: ipsec_tunnel_update_params.HealthCheck | Omit = omit,
interface_address6: str | Omit = omit,
psk: str | Omit = omit,
replay_protection: bool | Omit = omit,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelUpdateResponse:
"""Updates a specific IPsec tunnel associated with an account.
Use
`?validate_only=true` as an optional query parameter to only run validation
without persisting changes.
Args:
account_id: Identifier
ipsec_tunnel_id: Identifier
cloudflare_endpoint: The IP address assigned to the Cloudflare side of the IPsec tunnel.
interface_address: A 31-bit prefix (/31 in CIDR notation) supporting two hosts, one for each side
of the tunnel. Select the subnet from the following private IP space:
10.0.0.010.255.255.255, 172.16.0.0172.31.255.255, 192.168.0.0192.168.255.255.
name: The name of the IPsec tunnel. The name cannot share a name with other tunnels.
automatic_return_routing: True if automatic stateful return routing should be enabled for a tunnel, false
otherwise.
customer_endpoint: The IP address assigned to the customer side of the IPsec tunnel. Not required,
but must be set for proactive traceroutes to work.
description: An optional description forthe IPsec tunnel.
interface_address6: A 127 bit IPV6 prefix from within the virtual_subnet6 prefix space with the
address being the first IP of the subnet and not same as the address of
virtual_subnet6. Eg if virtual_subnet6 is 2606:54c1:7:0:a9fe:12d2::/127 ,
interface_address6 could be 2606:54c1:7:0:a9fe:12d2:1:200/127
psk: A randomly generated or provided string for use in the IPsec tunnel.
replay_protection: If `true`, then IPsec replay protection will be supported in the
Cloudflare-to-customer direction.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not ipsec_tunnel_id:
raise ValueError(f"Expected a non-empty value for `ipsec_tunnel_id` but received {ipsec_tunnel_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return self._put(
f"/accounts/{account_id}/magic/ipsec_tunnels/{ipsec_tunnel_id}",
body=maybe_transform(
{
"cloudflare_endpoint": cloudflare_endpoint,
"interface_address": interface_address,
"name": name,
"automatic_return_routing": automatic_return_routing,
"bgp": bgp,
"custom_remote_identities": custom_remote_identities,
"customer_endpoint": customer_endpoint,
"description": description,
"health_check": health_check,
"interface_address6": interface_address6,
"psk": psk,
"replay_protection": replay_protection,
},
ipsec_tunnel_update_params.IPSECTunnelUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelUpdateResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelUpdateResponse], ResultWrapper[IPSECTunnelUpdateResponse]),
)
def list(
self,
*,
account_id: str,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelListResponse:
"""
Lists IPsec tunnels associated with an account.
Args:
account_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return self._get(
f"/accounts/{account_id}/magic/ipsec_tunnels",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelListResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelListResponse], ResultWrapper[IPSECTunnelListResponse]),
)
def delete(
self,
ipsec_tunnel_id: str,
*,
account_id: str,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelDeleteResponse:
"""
Disables and removes a specific static IPsec Tunnel associated with an account.
Use `?validate_only=true` as an optional query parameter to only run validation
without persisting changes.
Args:
account_id: Identifier
ipsec_tunnel_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not ipsec_tunnel_id:
raise ValueError(f"Expected a non-empty value for `ipsec_tunnel_id` but received {ipsec_tunnel_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return self._delete(
f"/accounts/{account_id}/magic/ipsec_tunnels/{ipsec_tunnel_id}",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelDeleteResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelDeleteResponse], ResultWrapper[IPSECTunnelDeleteResponse]),
)
def bulk_update(
self,
*,
account_id: str,
body: object,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelBulkUpdateResponse:
"""Update multiple IPsec tunnels associated with an account.
Use
`?validate_only=true` as an optional query parameter to only run validation
without persisting changes.
Args:
account_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return self._put(
f"/accounts/{account_id}/magic/ipsec_tunnels",
body=maybe_transform(body, ipsec_tunnel_bulk_update_params.IPSECTunnelBulkUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelBulkUpdateResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelBulkUpdateResponse], ResultWrapper[IPSECTunnelBulkUpdateResponse]),
)
def get(
self,
ipsec_tunnel_id: str,
*,
account_id: str,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelGetResponse:
"""
Lists details for a specific IPsec tunnel.
Args:
account_id: Identifier
ipsec_tunnel_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not ipsec_tunnel_id:
raise ValueError(f"Expected a non-empty value for `ipsec_tunnel_id` but received {ipsec_tunnel_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return self._get(
f"/accounts/{account_id}/magic/ipsec_tunnels/{ipsec_tunnel_id}",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelGetResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelGetResponse], ResultWrapper[IPSECTunnelGetResponse]),
)
def psk_generate(
self,
ipsec_tunnel_id: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelPSKGenerateResponse:
"""
Generates a Pre Shared Key for a specific IPsec tunnel used in the IKE session.
Use `?validate_only=true` as an optional query parameter to only run validation
without persisting changes. After a PSK is generated, the PSK is immediately
persisted to Cloudflare's edge and cannot be retrieved later. Note the PSK in a
safe place.
Args:
account_id: Identifier
ipsec_tunnel_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not ipsec_tunnel_id:
raise ValueError(f"Expected a non-empty value for `ipsec_tunnel_id` but received {ipsec_tunnel_id!r}")
return self._post(
f"/accounts/{account_id}/magic/ipsec_tunnels/{ipsec_tunnel_id}/psk_generate",
body=maybe_transform(body, ipsec_tunnel_psk_generate_params.IPSECTunnelPSKGenerateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelPSKGenerateResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelPSKGenerateResponse], ResultWrapper[IPSECTunnelPSKGenerateResponse]),
)
class AsyncIPSECTunnelsResource(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncIPSECTunnelsResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
"""
return AsyncIPSECTunnelsResourceWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncIPSECTunnelsResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response
"""
return AsyncIPSECTunnelsResourceWithStreamingResponse(self)
async def create(
self,
*,
account_id: str,
cloudflare_endpoint: str,
interface_address: str,
name: str,
automatic_return_routing: bool | Omit = omit,
bgp: ipsec_tunnel_create_params.BGP | Omit = omit,
custom_remote_identities: ipsec_tunnel_create_params.CustomRemoteIdentities | Omit = omit,
customer_endpoint: str | Omit = omit,
description: str | Omit = omit,
health_check: ipsec_tunnel_create_params.HealthCheck | Omit = omit,
interface_address6: str | Omit = omit,
psk: str | Omit = omit,
replay_protection: bool | Omit = omit,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelCreateResponse:
"""Creates a new IPsec tunnel associated with an account.
Use `?validate_only=true`
as an optional query parameter to only run validation without persisting
changes.
Args:
account_id: Identifier
cloudflare_endpoint: The IP address assigned to the Cloudflare side of the IPsec tunnel.
interface_address: A 31-bit prefix (/31 in CIDR notation) supporting two hosts, one for each side
of the tunnel. Select the subnet from the following private IP space:
10.0.0.010.255.255.255, 172.16.0.0172.31.255.255, 192.168.0.0192.168.255.255.
name: The name of the IPsec tunnel. The name cannot share a name with other tunnels.
automatic_return_routing: True if automatic stateful return routing should be enabled for a tunnel, false
otherwise.
customer_endpoint: The IP address assigned to the customer side of the IPsec tunnel. Not required,
but must be set for proactive traceroutes to work.
description: An optional description forthe IPsec tunnel.
interface_address6: A 127 bit IPV6 prefix from within the virtual_subnet6 prefix space with the
address being the first IP of the subnet and not same as the address of
virtual_subnet6. Eg if virtual_subnet6 is 2606:54c1:7:0:a9fe:12d2::/127 ,
interface_address6 could be 2606:54c1:7:0:a9fe:12d2:1:200/127
psk: A randomly generated or provided string for use in the IPsec tunnel.
replay_protection: If `true`, then IPsec replay protection will be supported in the
Cloudflare-to-customer direction.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return await self._post(
f"/accounts/{account_id}/magic/ipsec_tunnels",
body=await async_maybe_transform(
{
"cloudflare_endpoint": cloudflare_endpoint,
"interface_address": interface_address,
"name": name,
"automatic_return_routing": automatic_return_routing,
"bgp": bgp,
"custom_remote_identities": custom_remote_identities,
"customer_endpoint": customer_endpoint,
"description": description,
"health_check": health_check,
"interface_address6": interface_address6,
"psk": psk,
"replay_protection": replay_protection,
},
ipsec_tunnel_create_params.IPSECTunnelCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelCreateResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelCreateResponse], ResultWrapper[IPSECTunnelCreateResponse]),
)
async def update(
self,
ipsec_tunnel_id: str,
*,
account_id: str,
cloudflare_endpoint: str,
interface_address: str,
name: str,
automatic_return_routing: bool | Omit = omit,
bgp: ipsec_tunnel_update_params.BGP | Omit = omit,
custom_remote_identities: ipsec_tunnel_update_params.CustomRemoteIdentities | Omit = omit,
customer_endpoint: str | Omit = omit,
description: str | Omit = omit,
health_check: ipsec_tunnel_update_params.HealthCheck | Omit = omit,
interface_address6: str | Omit = omit,
psk: str | Omit = omit,
replay_protection: bool | Omit = omit,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelUpdateResponse:
"""Updates a specific IPsec tunnel associated with an account.
Use
`?validate_only=true` as an optional query parameter to only run validation
without persisting changes.
Args:
account_id: Identifier
ipsec_tunnel_id: Identifier
cloudflare_endpoint: The IP address assigned to the Cloudflare side of the IPsec tunnel.
interface_address: A 31-bit prefix (/31 in CIDR notation) supporting two hosts, one for each side
of the tunnel. Select the subnet from the following private IP space:
10.0.0.010.255.255.255, 172.16.0.0172.31.255.255, 192.168.0.0192.168.255.255.
name: The name of the IPsec tunnel. The name cannot share a name with other tunnels.
automatic_return_routing: True if automatic stateful return routing should be enabled for a tunnel, false
otherwise.
customer_endpoint: The IP address assigned to the customer side of the IPsec tunnel. Not required,
but must be set for proactive traceroutes to work.
description: An optional description forthe IPsec tunnel.
interface_address6: A 127 bit IPV6 prefix from within the virtual_subnet6 prefix space with the
address being the first IP of the subnet and not same as the address of
virtual_subnet6. Eg if virtual_subnet6 is 2606:54c1:7:0:a9fe:12d2::/127 ,
interface_address6 could be 2606:54c1:7:0:a9fe:12d2:1:200/127
psk: A randomly generated or provided string for use in the IPsec tunnel.
replay_protection: If `true`, then IPsec replay protection will be supported in the
Cloudflare-to-customer direction.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not ipsec_tunnel_id:
raise ValueError(f"Expected a non-empty value for `ipsec_tunnel_id` but received {ipsec_tunnel_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return await self._put(
f"/accounts/{account_id}/magic/ipsec_tunnels/{ipsec_tunnel_id}",
body=await async_maybe_transform(
{
"cloudflare_endpoint": cloudflare_endpoint,
"interface_address": interface_address,
"name": name,
"automatic_return_routing": automatic_return_routing,
"bgp": bgp,
"custom_remote_identities": custom_remote_identities,
"customer_endpoint": customer_endpoint,
"description": description,
"health_check": health_check,
"interface_address6": interface_address6,
"psk": psk,
"replay_protection": replay_protection,
},
ipsec_tunnel_update_params.IPSECTunnelUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelUpdateResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelUpdateResponse], ResultWrapper[IPSECTunnelUpdateResponse]),
)
async def list(
self,
*,
account_id: str,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelListResponse:
"""
Lists IPsec tunnels associated with an account.
Args:
account_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return await self._get(
f"/accounts/{account_id}/magic/ipsec_tunnels",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelListResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelListResponse], ResultWrapper[IPSECTunnelListResponse]),
)
async def delete(
self,
ipsec_tunnel_id: str,
*,
account_id: str,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelDeleteResponse:
"""
Disables and removes a specific static IPsec Tunnel associated with an account.
Use `?validate_only=true` as an optional query parameter to only run validation
without persisting changes.
Args:
account_id: Identifier
ipsec_tunnel_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not ipsec_tunnel_id:
raise ValueError(f"Expected a non-empty value for `ipsec_tunnel_id` but received {ipsec_tunnel_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return await self._delete(
f"/accounts/{account_id}/magic/ipsec_tunnels/{ipsec_tunnel_id}",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelDeleteResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelDeleteResponse], ResultWrapper[IPSECTunnelDeleteResponse]),
)
async def bulk_update(
self,
*,
account_id: str,
body: object,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelBulkUpdateResponse:
"""Update multiple IPsec tunnels associated with an account.
Use
`?validate_only=true` as an optional query parameter to only run validation
without persisting changes.
Args:
account_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return await self._put(
f"/accounts/{account_id}/magic/ipsec_tunnels",
body=await async_maybe_transform(body, ipsec_tunnel_bulk_update_params.IPSECTunnelBulkUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelBulkUpdateResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelBulkUpdateResponse], ResultWrapper[IPSECTunnelBulkUpdateResponse]),
)
async def get(
self,
ipsec_tunnel_id: str,
*,
account_id: str,
x_magic_new_hc_target: bool | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelGetResponse:
"""
Lists details for a specific IPsec tunnel.
Args:
account_id: Identifier
ipsec_tunnel_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not ipsec_tunnel_id:
raise ValueError(f"Expected a non-empty value for `ipsec_tunnel_id` but received {ipsec_tunnel_id!r}")
extra_headers = {
**strip_not_given(
{
"x-magic-new-hc-target": ("true" if x_magic_new_hc_target else "false")
if is_given(x_magic_new_hc_target)
else not_given
}
),
**(extra_headers or {}),
}
return await self._get(
f"/accounts/{account_id}/magic/ipsec_tunnels/{ipsec_tunnel_id}",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelGetResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelGetResponse], ResultWrapper[IPSECTunnelGetResponse]),
)
async def psk_generate(
self,
ipsec_tunnel_id: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> IPSECTunnelPSKGenerateResponse:
"""
Generates a Pre Shared Key for a specific IPsec tunnel used in the IKE session.
Use `?validate_only=true` as an optional query parameter to only run validation
without persisting changes. After a PSK is generated, the PSK is immediately
persisted to Cloudflare's edge and cannot be retrieved later. Note the PSK in a
safe place.
Args:
account_id: Identifier
ipsec_tunnel_id: Identifier
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not ipsec_tunnel_id:
raise ValueError(f"Expected a non-empty value for `ipsec_tunnel_id` but received {ipsec_tunnel_id!r}")
return await self._post(
f"/accounts/{account_id}/magic/ipsec_tunnels/{ipsec_tunnel_id}/psk_generate",
body=await async_maybe_transform(body, ipsec_tunnel_psk_generate_params.IPSECTunnelPSKGenerateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
post_parser=ResultWrapper[IPSECTunnelPSKGenerateResponse]._unwrapper,
),
cast_to=cast(Type[IPSECTunnelPSKGenerateResponse], ResultWrapper[IPSECTunnelPSKGenerateResponse]),
)
class IPSECTunnelsResourceWithRawResponse:
def __init__(self, ipsec_tunnels: IPSECTunnelsResource) -> None:
self._ipsec_tunnels = ipsec_tunnels
self.create = to_raw_response_wrapper(
ipsec_tunnels.create,
)
self.update = to_raw_response_wrapper(
ipsec_tunnels.update,
)
self.list = to_raw_response_wrapper(
ipsec_tunnels.list,
)
self.delete = to_raw_response_wrapper(
ipsec_tunnels.delete,
)
self.bulk_update = to_raw_response_wrapper(
ipsec_tunnels.bulk_update,
)
self.get = to_raw_response_wrapper(
ipsec_tunnels.get,
)
self.psk_generate = to_raw_response_wrapper(
ipsec_tunnels.psk_generate,
)
class AsyncIPSECTunnelsResourceWithRawResponse:
def __init__(self, ipsec_tunnels: AsyncIPSECTunnelsResource) -> None:
self._ipsec_tunnels = ipsec_tunnels
self.create = async_to_raw_response_wrapper(
ipsec_tunnels.create,
)
self.update = async_to_raw_response_wrapper(
ipsec_tunnels.update,
)
self.list = async_to_raw_response_wrapper(
ipsec_tunnels.list,
)
self.delete = async_to_raw_response_wrapper(
ipsec_tunnels.delete,
)
self.bulk_update = async_to_raw_response_wrapper(
ipsec_tunnels.bulk_update,
)
self.get = async_to_raw_response_wrapper(
ipsec_tunnels.get,
)
self.psk_generate = async_to_raw_response_wrapper(
ipsec_tunnels.psk_generate,
)
class IPSECTunnelsResourceWithStreamingResponse:
def __init__(self, ipsec_tunnels: IPSECTunnelsResource) -> None:
self._ipsec_tunnels = ipsec_tunnels
self.create = to_streamed_response_wrapper(
ipsec_tunnels.create,
)
self.update = to_streamed_response_wrapper(
ipsec_tunnels.update,
)
self.list = to_streamed_response_wrapper(
ipsec_tunnels.list,
)
self.delete = to_streamed_response_wrapper(
ipsec_tunnels.delete,
)
self.bulk_update = to_streamed_response_wrapper(
ipsec_tunnels.bulk_update,
)
self.get = to_streamed_response_wrapper(
ipsec_tunnels.get,
)
self.psk_generate = to_streamed_response_wrapper(
ipsec_tunnels.psk_generate,
)
class AsyncIPSECTunnelsResourceWithStreamingResponse:
def __init__(self, ipsec_tunnels: AsyncIPSECTunnelsResource) -> None:
self._ipsec_tunnels = ipsec_tunnels
self.create = async_to_streamed_response_wrapper(
ipsec_tunnels.create,
)
self.update = async_to_streamed_response_wrapper(
ipsec_tunnels.update,
)
self.list = async_to_streamed_response_wrapper(
ipsec_tunnels.list,
)
self.delete = async_to_streamed_response_wrapper(
ipsec_tunnels.delete,
)
self.bulk_update = async_to_streamed_response_wrapper(
ipsec_tunnels.bulk_update,
)
self.get = async_to_streamed_response_wrapper(
ipsec_tunnels.get,
)
self.psk_generate = async_to_streamed_response_wrapper(
ipsec_tunnels.psk_generate,
)