|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Any, cast |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ......_types import NOT_GIVEN, Body, Query, Headers, NotGiven |
| 10 | +from ......_utils import ( |
| 11 | + maybe_transform, |
| 12 | + async_maybe_transform, |
| 13 | +) |
| 14 | +from ......_compat import cached_property |
| 15 | +from ......_resource import SyncAPIResource, AsyncAPIResource |
| 16 | +from ......_response import ( |
| 17 | + to_raw_response_wrapper, |
| 18 | + to_streamed_response_wrapper, |
| 19 | + async_to_raw_response_wrapper, |
| 20 | + async_to_streamed_response_wrapper, |
| 21 | +) |
| 22 | +from ......_wrappers import ResultWrapper |
| 23 | +from ......_base_client import make_request_options |
| 24 | +from ......types.zero_trust.devices.policies.default import certificate_edit_params |
| 25 | +from ......types.zero_trust.devices.policies.default.certificate_get_response import CertificateGetResponse |
| 26 | +from ......types.zero_trust.devices.policies.default.certificate_edit_response import CertificateEditResponse |
| 27 | + |
| 28 | +__all__ = ["CertificatesResource", "AsyncCertificatesResource"] |
| 29 | + |
| 30 | + |
| 31 | +class CertificatesResource(SyncAPIResource): |
| 32 | + @cached_property |
| 33 | + def with_raw_response(self) -> CertificatesResourceWithRawResponse: |
| 34 | + """ |
| 35 | + This property can be used as a prefix for any HTTP method call to return the |
| 36 | + the raw response object instead of the parsed content. |
| 37 | +
|
| 38 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 39 | + """ |
| 40 | + return CertificatesResourceWithRawResponse(self) |
| 41 | + |
| 42 | + @cached_property |
| 43 | + def with_streaming_response(self) -> CertificatesResourceWithStreamingResponse: |
| 44 | + """ |
| 45 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 46 | +
|
| 47 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 48 | + """ |
| 49 | + return CertificatesResourceWithStreamingResponse(self) |
| 50 | + |
| 51 | + def edit( |
| 52 | + self, |
| 53 | + *, |
| 54 | + zone_id: str, |
| 55 | + enabled: bool, |
| 56 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 57 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 58 | + extra_headers: Headers | None = None, |
| 59 | + extra_query: Query | None = None, |
| 60 | + extra_body: Body | None = None, |
| 61 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 62 | + ) -> CertificateEditResponse: |
| 63 | + """ |
| 64 | + Enable Zero Trust Clients to provision a certificate, containing a x509 subject, |
| 65 | + and referenced by Access device posture policies when the client visits MTLS |
| 66 | + protected domains. This facilitates device posture without a WARP session. |
| 67 | +
|
| 68 | + Args: |
| 69 | + enabled: The current status of the device policy certificate provisioning feature for |
| 70 | + WARP clients. |
| 71 | +
|
| 72 | + extra_headers: Send extra headers |
| 73 | +
|
| 74 | + extra_query: Add additional query parameters to the request |
| 75 | +
|
| 76 | + extra_body: Add additional JSON properties to the request |
| 77 | +
|
| 78 | + timeout: Override the client-level default timeout for this request, in seconds |
| 79 | + """ |
| 80 | + if not zone_id: |
| 81 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 82 | + return cast( |
| 83 | + CertificateEditResponse, |
| 84 | + self._patch( |
| 85 | + f"/zones/{zone_id}/devices/policy/certificates", |
| 86 | + body=maybe_transform({"enabled": enabled}, certificate_edit_params.CertificateEditParams), |
| 87 | + options=make_request_options( |
| 88 | + extra_headers=extra_headers, |
| 89 | + extra_query=extra_query, |
| 90 | + extra_body=extra_body, |
| 91 | + timeout=timeout, |
| 92 | + post_parser=ResultWrapper[CertificateEditResponse]._unwrapper, |
| 93 | + ), |
| 94 | + cast_to=cast( |
| 95 | + Any, ResultWrapper[CertificateEditResponse] |
| 96 | + ), # Union types cannot be passed in as arguments in the type system |
| 97 | + ), |
| 98 | + ) |
| 99 | + |
| 100 | + def get( |
| 101 | + self, |
| 102 | + *, |
| 103 | + zone_id: str, |
| 104 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 105 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 106 | + extra_headers: Headers | None = None, |
| 107 | + extra_query: Query | None = None, |
| 108 | + extra_body: Body | None = None, |
| 109 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 110 | + ) -> CertificateGetResponse: |
| 111 | + """ |
| 112 | + Fetches device certificate provisioning |
| 113 | +
|
| 114 | + Args: |
| 115 | + extra_headers: Send extra headers |
| 116 | +
|
| 117 | + extra_query: Add additional query parameters to the request |
| 118 | +
|
| 119 | + extra_body: Add additional JSON properties to the request |
| 120 | +
|
| 121 | + timeout: Override the client-level default timeout for this request, in seconds |
| 122 | + """ |
| 123 | + if not zone_id: |
| 124 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 125 | + return cast( |
| 126 | + CertificateGetResponse, |
| 127 | + self._get( |
| 128 | + f"/zones/{zone_id}/devices/policy/certificates", |
| 129 | + options=make_request_options( |
| 130 | + extra_headers=extra_headers, |
| 131 | + extra_query=extra_query, |
| 132 | + extra_body=extra_body, |
| 133 | + timeout=timeout, |
| 134 | + post_parser=ResultWrapper[CertificateGetResponse]._unwrapper, |
| 135 | + ), |
| 136 | + cast_to=cast( |
| 137 | + Any, ResultWrapper[CertificateGetResponse] |
| 138 | + ), # Union types cannot be passed in as arguments in the type system |
| 139 | + ), |
| 140 | + ) |
| 141 | + |
| 142 | + |
| 143 | +class AsyncCertificatesResource(AsyncAPIResource): |
| 144 | + @cached_property |
| 145 | + def with_raw_response(self) -> AsyncCertificatesResourceWithRawResponse: |
| 146 | + """ |
| 147 | + This property can be used as a prefix for any HTTP method call to return the |
| 148 | + the raw response object instead of the parsed content. |
| 149 | +
|
| 150 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 151 | + """ |
| 152 | + return AsyncCertificatesResourceWithRawResponse(self) |
| 153 | + |
| 154 | + @cached_property |
| 155 | + def with_streaming_response(self) -> AsyncCertificatesResourceWithStreamingResponse: |
| 156 | + """ |
| 157 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 158 | +
|
| 159 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 160 | + """ |
| 161 | + return AsyncCertificatesResourceWithStreamingResponse(self) |
| 162 | + |
| 163 | + async def edit( |
| 164 | + self, |
| 165 | + *, |
| 166 | + zone_id: str, |
| 167 | + enabled: bool, |
| 168 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 169 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 170 | + extra_headers: Headers | None = None, |
| 171 | + extra_query: Query | None = None, |
| 172 | + extra_body: Body | None = None, |
| 173 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 174 | + ) -> CertificateEditResponse: |
| 175 | + """ |
| 176 | + Enable Zero Trust Clients to provision a certificate, containing a x509 subject, |
| 177 | + and referenced by Access device posture policies when the client visits MTLS |
| 178 | + protected domains. This facilitates device posture without a WARP session. |
| 179 | +
|
| 180 | + Args: |
| 181 | + enabled: The current status of the device policy certificate provisioning feature for |
| 182 | + WARP clients. |
| 183 | +
|
| 184 | + extra_headers: Send extra headers |
| 185 | +
|
| 186 | + extra_query: Add additional query parameters to the request |
| 187 | +
|
| 188 | + extra_body: Add additional JSON properties to the request |
| 189 | +
|
| 190 | + timeout: Override the client-level default timeout for this request, in seconds |
| 191 | + """ |
| 192 | + if not zone_id: |
| 193 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 194 | + return cast( |
| 195 | + CertificateEditResponse, |
| 196 | + await self._patch( |
| 197 | + f"/zones/{zone_id}/devices/policy/certificates", |
| 198 | + body=await async_maybe_transform({"enabled": enabled}, certificate_edit_params.CertificateEditParams), |
| 199 | + options=make_request_options( |
| 200 | + extra_headers=extra_headers, |
| 201 | + extra_query=extra_query, |
| 202 | + extra_body=extra_body, |
| 203 | + timeout=timeout, |
| 204 | + post_parser=ResultWrapper[CertificateEditResponse]._unwrapper, |
| 205 | + ), |
| 206 | + cast_to=cast( |
| 207 | + Any, ResultWrapper[CertificateEditResponse] |
| 208 | + ), # Union types cannot be passed in as arguments in the type system |
| 209 | + ), |
| 210 | + ) |
| 211 | + |
| 212 | + async def get( |
| 213 | + self, |
| 214 | + *, |
| 215 | + zone_id: str, |
| 216 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 217 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 218 | + extra_headers: Headers | None = None, |
| 219 | + extra_query: Query | None = None, |
| 220 | + extra_body: Body | None = None, |
| 221 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 222 | + ) -> CertificateGetResponse: |
| 223 | + """ |
| 224 | + Fetches device certificate provisioning |
| 225 | +
|
| 226 | + Args: |
| 227 | + extra_headers: Send extra headers |
| 228 | +
|
| 229 | + extra_query: Add additional query parameters to the request |
| 230 | +
|
| 231 | + extra_body: Add additional JSON properties to the request |
| 232 | +
|
| 233 | + timeout: Override the client-level default timeout for this request, in seconds |
| 234 | + """ |
| 235 | + if not zone_id: |
| 236 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 237 | + return cast( |
| 238 | + CertificateGetResponse, |
| 239 | + await self._get( |
| 240 | + f"/zones/{zone_id}/devices/policy/certificates", |
| 241 | + options=make_request_options( |
| 242 | + extra_headers=extra_headers, |
| 243 | + extra_query=extra_query, |
| 244 | + extra_body=extra_body, |
| 245 | + timeout=timeout, |
| 246 | + post_parser=ResultWrapper[CertificateGetResponse]._unwrapper, |
| 247 | + ), |
| 248 | + cast_to=cast( |
| 249 | + Any, ResultWrapper[CertificateGetResponse] |
| 250 | + ), # Union types cannot be passed in as arguments in the type system |
| 251 | + ), |
| 252 | + ) |
| 253 | + |
| 254 | + |
| 255 | +class CertificatesResourceWithRawResponse: |
| 256 | + def __init__(self, certificates: CertificatesResource) -> None: |
| 257 | + self._certificates = certificates |
| 258 | + |
| 259 | + self.edit = to_raw_response_wrapper( |
| 260 | + certificates.edit, |
| 261 | + ) |
| 262 | + self.get = to_raw_response_wrapper( |
| 263 | + certificates.get, |
| 264 | + ) |
| 265 | + |
| 266 | + |
| 267 | +class AsyncCertificatesResourceWithRawResponse: |
| 268 | + def __init__(self, certificates: AsyncCertificatesResource) -> None: |
| 269 | + self._certificates = certificates |
| 270 | + |
| 271 | + self.edit = async_to_raw_response_wrapper( |
| 272 | + certificates.edit, |
| 273 | + ) |
| 274 | + self.get = async_to_raw_response_wrapper( |
| 275 | + certificates.get, |
| 276 | + ) |
| 277 | + |
| 278 | + |
| 279 | +class CertificatesResourceWithStreamingResponse: |
| 280 | + def __init__(self, certificates: CertificatesResource) -> None: |
| 281 | + self._certificates = certificates |
| 282 | + |
| 283 | + self.edit = to_streamed_response_wrapper( |
| 284 | + certificates.edit, |
| 285 | + ) |
| 286 | + self.get = to_streamed_response_wrapper( |
| 287 | + certificates.get, |
| 288 | + ) |
| 289 | + |
| 290 | + |
| 291 | +class AsyncCertificatesResourceWithStreamingResponse: |
| 292 | + def __init__(self, certificates: AsyncCertificatesResource) -> None: |
| 293 | + self._certificates = certificates |
| 294 | + |
| 295 | + self.edit = async_to_streamed_response_wrapper( |
| 296 | + certificates.edit, |
| 297 | + ) |
| 298 | + self.get = async_to_streamed_response_wrapper( |
| 299 | + certificates.get, |
| 300 | + ) |
0 commit comments