Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 904614f

Browse files
committedFeb 28, 2025
feat(vpc_flows): add token support (#2485)
1 parent 9fb8139 commit 904614f

File tree

11 files changed

+480
-1
lines changed

11 files changed

+480
-1
lines changed
 

‎.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1547
1+
configured_endpoints: 1548
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-cc9be7885f16989f56e5e015644178eb17b82304fc31f62ed14b7e9a93cab891.yml

‎api.md

+14
Original file line numberDiff line numberDiff line change
@@ -3951,6 +3951,20 @@ Methods:
39513951

39523952
# MagicNetworkMonitoring
39533953

3954+
## VpcFlows
3955+
3956+
### Tokens
3957+
3958+
Types:
3959+
3960+
```python
3961+
from cloudflare.types.magic_network_monitoring.vpc_flows import TokenCreateResponse
3962+
```
3963+
3964+
Methods:
3965+
3966+
- <code title="post /accounts/{account_id}/mnm/vpc-flows/token">client.magic_network_monitoring.vpc_flows.tokens.<a href="./src/cloudflare/resources/magic_network_monitoring/vpc_flows/tokens.py">create</a>(\*, account_id) -> <a href="./src/cloudflare/types/magic_network_monitoring/vpc_flows/token_create_response.py">str</a></code>
3967+
39543968
## Configs
39553969

39563970
Types:

‎src/cloudflare/resources/magic_network_monitoring/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
ConfigsResourceWithStreamingResponse,
1717
AsyncConfigsResourceWithStreamingResponse,
1818
)
19+
from .vpc_flows import (
20+
VpcFlowsResource,
21+
AsyncVpcFlowsResource,
22+
VpcFlowsResourceWithRawResponse,
23+
AsyncVpcFlowsResourceWithRawResponse,
24+
VpcFlowsResourceWithStreamingResponse,
25+
AsyncVpcFlowsResourceWithStreamingResponse,
26+
)
1927
from .magic_network_monitoring import (
2028
MagicNetworkMonitoringResource,
2129
AsyncMagicNetworkMonitoringResource,
@@ -26,6 +34,12 @@
2634
)
2735

2836
__all__ = [
37+
"VpcFlowsResource",
38+
"AsyncVpcFlowsResource",
39+
"VpcFlowsResourceWithRawResponse",
40+
"AsyncVpcFlowsResourceWithRawResponse",
41+
"VpcFlowsResourceWithStreamingResponse",
42+
"AsyncVpcFlowsResourceWithStreamingResponse",
2943
"ConfigsResource",
3044
"AsyncConfigsResource",
3145
"ConfigsResourceWithRawResponse",

‎src/cloudflare/resources/magic_network_monitoring/magic_network_monitoring.py

+32
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@
2020
ConfigsResourceWithStreamingResponse,
2121
AsyncConfigsResourceWithStreamingResponse,
2222
)
23+
from .vpc_flows.vpc_flows import (
24+
VpcFlowsResource,
25+
AsyncVpcFlowsResource,
26+
VpcFlowsResourceWithRawResponse,
27+
AsyncVpcFlowsResourceWithRawResponse,
28+
VpcFlowsResourceWithStreamingResponse,
29+
AsyncVpcFlowsResourceWithStreamingResponse,
30+
)
2331

2432
__all__ = ["MagicNetworkMonitoringResource", "AsyncMagicNetworkMonitoringResource"]
2533

2634

2735
class MagicNetworkMonitoringResource(SyncAPIResource):
36+
@cached_property
37+
def vpc_flows(self) -> VpcFlowsResource:
38+
return VpcFlowsResource(self._client)
39+
2840
@cached_property
2941
def configs(self) -> ConfigsResource:
3042
return ConfigsResource(self._client)
@@ -54,6 +66,10 @@ def with_streaming_response(self) -> MagicNetworkMonitoringResourceWithStreaming
5466

5567

5668
class AsyncMagicNetworkMonitoringResource(AsyncAPIResource):
69+
@cached_property
70+
def vpc_flows(self) -> AsyncVpcFlowsResource:
71+
return AsyncVpcFlowsResource(self._client)
72+
5773
@cached_property
5874
def configs(self) -> AsyncConfigsResource:
5975
return AsyncConfigsResource(self._client)
@@ -86,6 +102,10 @@ class MagicNetworkMonitoringResourceWithRawResponse:
86102
def __init__(self, magic_network_monitoring: MagicNetworkMonitoringResource) -> None:
87103
self._magic_network_monitoring = magic_network_monitoring
88104

105+
@cached_property
106+
def vpc_flows(self) -> VpcFlowsResourceWithRawResponse:
107+
return VpcFlowsResourceWithRawResponse(self._magic_network_monitoring.vpc_flows)
108+
89109
@cached_property
90110
def configs(self) -> ConfigsResourceWithRawResponse:
91111
return ConfigsResourceWithRawResponse(self._magic_network_monitoring.configs)
@@ -99,6 +119,10 @@ class AsyncMagicNetworkMonitoringResourceWithRawResponse:
99119
def __init__(self, magic_network_monitoring: AsyncMagicNetworkMonitoringResource) -> None:
100120
self._magic_network_monitoring = magic_network_monitoring
101121

122+
@cached_property
123+
def vpc_flows(self) -> AsyncVpcFlowsResourceWithRawResponse:
124+
return AsyncVpcFlowsResourceWithRawResponse(self._magic_network_monitoring.vpc_flows)
125+
102126
@cached_property
103127
def configs(self) -> AsyncConfigsResourceWithRawResponse:
104128
return AsyncConfigsResourceWithRawResponse(self._magic_network_monitoring.configs)
@@ -112,6 +136,10 @@ class MagicNetworkMonitoringResourceWithStreamingResponse:
112136
def __init__(self, magic_network_monitoring: MagicNetworkMonitoringResource) -> None:
113137
self._magic_network_monitoring = magic_network_monitoring
114138

139+
@cached_property
140+
def vpc_flows(self) -> VpcFlowsResourceWithStreamingResponse:
141+
return VpcFlowsResourceWithStreamingResponse(self._magic_network_monitoring.vpc_flows)
142+
115143
@cached_property
116144
def configs(self) -> ConfigsResourceWithStreamingResponse:
117145
return ConfigsResourceWithStreamingResponse(self._magic_network_monitoring.configs)
@@ -125,6 +153,10 @@ class AsyncMagicNetworkMonitoringResourceWithStreamingResponse:
125153
def __init__(self, magic_network_monitoring: AsyncMagicNetworkMonitoringResource) -> None:
126154
self._magic_network_monitoring = magic_network_monitoring
127155

156+
@cached_property
157+
def vpc_flows(self) -> AsyncVpcFlowsResourceWithStreamingResponse:
158+
return AsyncVpcFlowsResourceWithStreamingResponse(self._magic_network_monitoring.vpc_flows)
159+
128160
@cached_property
129161
def configs(self) -> AsyncConfigsResourceWithStreamingResponse:
130162
return AsyncConfigsResourceWithStreamingResponse(self._magic_network_monitoring.configs)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from .tokens import (
4+
TokensResource,
5+
AsyncTokensResource,
6+
TokensResourceWithRawResponse,
7+
AsyncTokensResourceWithRawResponse,
8+
TokensResourceWithStreamingResponse,
9+
AsyncTokensResourceWithStreamingResponse,
10+
)
11+
from .vpc_flows import (
12+
VpcFlowsResource,
13+
AsyncVpcFlowsResource,
14+
VpcFlowsResourceWithRawResponse,
15+
AsyncVpcFlowsResourceWithRawResponse,
16+
VpcFlowsResourceWithStreamingResponse,
17+
AsyncVpcFlowsResourceWithStreamingResponse,
18+
)
19+
20+
__all__ = [
21+
"TokensResource",
22+
"AsyncTokensResource",
23+
"TokensResourceWithRawResponse",
24+
"AsyncTokensResourceWithRawResponse",
25+
"TokensResourceWithStreamingResponse",
26+
"AsyncTokensResourceWithStreamingResponse",
27+
"VpcFlowsResource",
28+
"AsyncVpcFlowsResource",
29+
"VpcFlowsResourceWithRawResponse",
30+
"AsyncVpcFlowsResourceWithRawResponse",
31+
"VpcFlowsResourceWithStreamingResponse",
32+
"AsyncVpcFlowsResourceWithStreamingResponse",
33+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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 Type, cast
6+
7+
import httpx
8+
9+
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
10+
from ...._compat import cached_property
11+
from ...._resource import SyncAPIResource, AsyncAPIResource
12+
from ...._response import (
13+
to_raw_response_wrapper,
14+
to_streamed_response_wrapper,
15+
async_to_raw_response_wrapper,
16+
async_to_streamed_response_wrapper,
17+
)
18+
from ...._wrappers import ResultWrapper
19+
from ...._base_client import make_request_options
20+
from ....types.magic_network_monitoring.vpc_flows.token_create_response import TokenCreateResponse
21+
22+
__all__ = ["TokensResource", "AsyncTokensResource"]
23+
24+
25+
class TokensResource(SyncAPIResource):
26+
@cached_property
27+
def with_raw_response(self) -> TokensResourceWithRawResponse:
28+
"""
29+
This property can be used as a prefix for any HTTP method call to return
30+
the raw response object instead of the parsed content.
31+
32+
For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
33+
"""
34+
return TokensResourceWithRawResponse(self)
35+
36+
@cached_property
37+
def with_streaming_response(self) -> TokensResourceWithStreamingResponse:
38+
"""
39+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
40+
41+
For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response
42+
"""
43+
return TokensResourceWithStreamingResponse(self)
44+
45+
def create(
46+
self,
47+
*,
48+
account_id: str,
49+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
50+
# The extra values given here take precedence over values defined on the client or passed to this method.
51+
extra_headers: Headers | None = None,
52+
extra_query: Query | None = None,
53+
extra_body: Body | None = None,
54+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
55+
) -> str:
56+
"""
57+
Generate authentication token for VPC flow logs export.
58+
59+
Args:
60+
extra_headers: Send extra headers
61+
62+
extra_query: Add additional query parameters to the request
63+
64+
extra_body: Add additional JSON properties to the request
65+
66+
timeout: Override the client-level default timeout for this request, in seconds
67+
"""
68+
if not account_id:
69+
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
70+
return self._post(
71+
f"/accounts/{account_id}/mnm/vpc-flows/token",
72+
options=make_request_options(
73+
extra_headers=extra_headers,
74+
extra_query=extra_query,
75+
extra_body=extra_body,
76+
timeout=timeout,
77+
post_parser=ResultWrapper[TokenCreateResponse]._unwrapper,
78+
),
79+
cast_to=cast(Type[str], ResultWrapper[str]),
80+
)
81+
82+
83+
class AsyncTokensResource(AsyncAPIResource):
84+
@cached_property
85+
def with_raw_response(self) -> AsyncTokensResourceWithRawResponse:
86+
"""
87+
This property can be used as a prefix for any HTTP method call to return
88+
the raw response object instead of the parsed content.
89+
90+
For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
91+
"""
92+
return AsyncTokensResourceWithRawResponse(self)
93+
94+
@cached_property
95+
def with_streaming_response(self) -> AsyncTokensResourceWithStreamingResponse:
96+
"""
97+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
98+
99+
For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response
100+
"""
101+
return AsyncTokensResourceWithStreamingResponse(self)
102+
103+
async def create(
104+
self,
105+
*,
106+
account_id: str,
107+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
108+
# The extra values given here take precedence over values defined on the client or passed to this method.
109+
extra_headers: Headers | None = None,
110+
extra_query: Query | None = None,
111+
extra_body: Body | None = None,
112+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
113+
) -> str:
114+
"""
115+
Generate authentication token for VPC flow logs export.
116+
117+
Args:
118+
extra_headers: Send extra headers
119+
120+
extra_query: Add additional query parameters to the request
121+
122+
extra_body: Add additional JSON properties to the request
123+
124+
timeout: Override the client-level default timeout for this request, in seconds
125+
"""
126+
if not account_id:
127+
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
128+
return await self._post(
129+
f"/accounts/{account_id}/mnm/vpc-flows/token",
130+
options=make_request_options(
131+
extra_headers=extra_headers,
132+
extra_query=extra_query,
133+
extra_body=extra_body,
134+
timeout=timeout,
135+
post_parser=ResultWrapper[TokenCreateResponse]._unwrapper,
136+
),
137+
cast_to=cast(Type[str], ResultWrapper[str]),
138+
)
139+
140+
141+
class TokensResourceWithRawResponse:
142+
def __init__(self, tokens: TokensResource) -> None:
143+
self._tokens = tokens
144+
145+
self.create = to_raw_response_wrapper(
146+
tokens.create,
147+
)
148+
149+
150+
class AsyncTokensResourceWithRawResponse:
151+
def __init__(self, tokens: AsyncTokensResource) -> None:
152+
self._tokens = tokens
153+
154+
self.create = async_to_raw_response_wrapper(
155+
tokens.create,
156+
)
157+
158+
159+
class TokensResourceWithStreamingResponse:
160+
def __init__(self, tokens: TokensResource) -> None:
161+
self._tokens = tokens
162+
163+
self.create = to_streamed_response_wrapper(
164+
tokens.create,
165+
)
166+
167+
168+
class AsyncTokensResourceWithStreamingResponse:
169+
def __init__(self, tokens: AsyncTokensResource) -> None:
170+
self._tokens = tokens
171+
172+
self.create = async_to_streamed_response_wrapper(
173+
tokens.create,
174+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from .tokens import (
6+
TokensResource,
7+
AsyncTokensResource,
8+
TokensResourceWithRawResponse,
9+
AsyncTokensResourceWithRawResponse,
10+
TokensResourceWithStreamingResponse,
11+
AsyncTokensResourceWithStreamingResponse,
12+
)
13+
from ...._compat import cached_property
14+
from ...._resource import SyncAPIResource, AsyncAPIResource
15+
16+
__all__ = ["VpcFlowsResource", "AsyncVpcFlowsResource"]
17+
18+
19+
class VpcFlowsResource(SyncAPIResource):
20+
@cached_property
21+
def tokens(self) -> TokensResource:
22+
return TokensResource(self._client)
23+
24+
@cached_property
25+
def with_raw_response(self) -> VpcFlowsResourceWithRawResponse:
26+
"""
27+
This property can be used as a prefix for any HTTP method call to return
28+
the raw response object instead of the parsed content.
29+
30+
For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
31+
"""
32+
return VpcFlowsResourceWithRawResponse(self)
33+
34+
@cached_property
35+
def with_streaming_response(self) -> VpcFlowsResourceWithStreamingResponse:
36+
"""
37+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
38+
39+
For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response
40+
"""
41+
return VpcFlowsResourceWithStreamingResponse(self)
42+
43+
44+
class AsyncVpcFlowsResource(AsyncAPIResource):
45+
@cached_property
46+
def tokens(self) -> AsyncTokensResource:
47+
return AsyncTokensResource(self._client)
48+
49+
@cached_property
50+
def with_raw_response(self) -> AsyncVpcFlowsResourceWithRawResponse:
51+
"""
52+
This property can be used as a prefix for any HTTP method call to return
53+
the raw response object instead of the parsed content.
54+
55+
For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
56+
"""
57+
return AsyncVpcFlowsResourceWithRawResponse(self)
58+
59+
@cached_property
60+
def with_streaming_response(self) -> AsyncVpcFlowsResourceWithStreamingResponse:
61+
"""
62+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
63+
64+
For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response
65+
"""
66+
return AsyncVpcFlowsResourceWithStreamingResponse(self)
67+
68+
69+
class VpcFlowsResourceWithRawResponse:
70+
def __init__(self, vpc_flows: VpcFlowsResource) -> None:
71+
self._vpc_flows = vpc_flows
72+
73+
@cached_property
74+
def tokens(self) -> TokensResourceWithRawResponse:
75+
return TokensResourceWithRawResponse(self._vpc_flows.tokens)
76+
77+
78+
class AsyncVpcFlowsResourceWithRawResponse:
79+
def __init__(self, vpc_flows: AsyncVpcFlowsResource) -> None:
80+
self._vpc_flows = vpc_flows
81+
82+
@cached_property
83+
def tokens(self) -> AsyncTokensResourceWithRawResponse:
84+
return AsyncTokensResourceWithRawResponse(self._vpc_flows.tokens)
85+
86+
87+
class VpcFlowsResourceWithStreamingResponse:
88+
def __init__(self, vpc_flows: VpcFlowsResource) -> None:
89+
self._vpc_flows = vpc_flows
90+
91+
@cached_property
92+
def tokens(self) -> TokensResourceWithStreamingResponse:
93+
return TokensResourceWithStreamingResponse(self._vpc_flows.tokens)
94+
95+
96+
class AsyncVpcFlowsResourceWithStreamingResponse:
97+
def __init__(self, vpc_flows: AsyncVpcFlowsResource) -> None:
98+
self._vpc_flows = vpc_flows
99+
100+
@cached_property
101+
def tokens(self) -> AsyncTokensResourceWithStreamingResponse:
102+
return AsyncTokensResourceWithStreamingResponse(self._vpc_flows.tokens)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from .token_create_response import TokenCreateResponse as TokenCreateResponse
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing_extensions import TypeAlias
4+
5+
__all__ = ["TokenCreateResponse"]
6+
7+
TokenCreateResponse: TypeAlias = str
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
import os
6+
from typing import Any, cast
7+
8+
import pytest
9+
10+
from cloudflare import Cloudflare, AsyncCloudflare
11+
from tests.utils import assert_matches_type
12+
13+
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
14+
15+
16+
class TestTokens:
17+
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
18+
19+
@parametrize
20+
def test_method_create(self, client: Cloudflare) -> None:
21+
token = client.magic_network_monitoring.vpc_flows.tokens.create(
22+
account_id="6f91088a406011ed95aed352566e8d4c",
23+
)
24+
assert_matches_type(str, token, path=["response"])
25+
26+
@parametrize
27+
def test_raw_response_create(self, client: Cloudflare) -> None:
28+
response = client.magic_network_monitoring.vpc_flows.tokens.with_raw_response.create(
29+
account_id="6f91088a406011ed95aed352566e8d4c",
30+
)
31+
32+
assert response.is_closed is True
33+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
34+
token = response.parse()
35+
assert_matches_type(str, token, path=["response"])
36+
37+
@parametrize
38+
def test_streaming_response_create(self, client: Cloudflare) -> None:
39+
with client.magic_network_monitoring.vpc_flows.tokens.with_streaming_response.create(
40+
account_id="6f91088a406011ed95aed352566e8d4c",
41+
) as response:
42+
assert not response.is_closed
43+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
44+
45+
token = response.parse()
46+
assert_matches_type(str, token, path=["response"])
47+
48+
assert cast(Any, response.is_closed) is True
49+
50+
@parametrize
51+
def test_path_params_create(self, client: Cloudflare) -> None:
52+
with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_id` but received ''"):
53+
client.magic_network_monitoring.vpc_flows.tokens.with_raw_response.create(
54+
account_id="",
55+
)
56+
57+
58+
class TestAsyncTokens:
59+
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
60+
61+
@parametrize
62+
async def test_method_create(self, async_client: AsyncCloudflare) -> None:
63+
token = await async_client.magic_network_monitoring.vpc_flows.tokens.create(
64+
account_id="6f91088a406011ed95aed352566e8d4c",
65+
)
66+
assert_matches_type(str, token, path=["response"])
67+
68+
@parametrize
69+
async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None:
70+
response = await async_client.magic_network_monitoring.vpc_flows.tokens.with_raw_response.create(
71+
account_id="6f91088a406011ed95aed352566e8d4c",
72+
)
73+
74+
assert response.is_closed is True
75+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
76+
token = await response.parse()
77+
assert_matches_type(str, token, path=["response"])
78+
79+
@parametrize
80+
async def test_streaming_response_create(self, async_client: AsyncCloudflare) -> None:
81+
async with async_client.magic_network_monitoring.vpc_flows.tokens.with_streaming_response.create(
82+
account_id="6f91088a406011ed95aed352566e8d4c",
83+
) as response:
84+
assert not response.is_closed
85+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86+
87+
token = await response.parse()
88+
assert_matches_type(str, token, path=["response"])
89+
90+
assert cast(Any, response.is_closed) is True
91+
92+
@parametrize
93+
async def test_path_params_create(self, async_client: AsyncCloudflare) -> None:
94+
with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_id` but received ''"):
95+
await async_client.magic_network_monitoring.vpc_flows.tokens.with_raw_response.create(
96+
account_id="",
97+
)

0 commit comments

Comments
 (0)
Please sign in to comment.