Debian Codegraph @

src/anthropic/resources/beta/organization/federation/rules/workspaces.py

raw
1 from __future__ import annotations
2
3 from typing import List, Optional
4
5 import httpx2
6
7 from ......_types import Body, Omit, Query, Headers, NotGiven, omit, not_given
8 from ......_utils import is_given, path_template, strip_not_given
9 from ......_compat import cached_property
10 from ......_resource import SyncAPIResource, AsyncAPIResource
11 from ......_response import (
12 to_raw_response_wrapper,
13 to_streamed_response_wrapper,
14 async_to_raw_response_wrapper,
15 async_to_streamed_response_wrapper,
16 )
17 from ......pagination import SyncPageCursor, AsyncPageCursor
18 from ......_base_client import AsyncPaginator, make_request_options
19 from ......types.anthropic_beta_param import AnthropicBetaParam
20 from ......types.beta.organization.federation.beta_federation_rule_workspace import BetaFederationRuleWorkspace
21 from ......types.beta.organization.federation.rules.workspace_remove_response import WorkspaceRemoveResponse
22
23 __all__ = ["Workspaces", "AsyncWorkspaces"]
24
25
26 class Workspaces(SyncAPIResource):
27 @cached_property
28 def with_raw_response(self) -> WorkspacesWithRawResponse:
29 """
30 This property can be used as a prefix for any HTTP method call to return
31 the raw response object instead of the parsed content.
32
33 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
34 """
35 return WorkspacesWithRawResponse(self)
36
37 @cached_property
38 def with_streaming_response(self) -> WorkspacesWithStreamingResponse:
39 """
40 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
41
42 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
43 """
44 return WorkspacesWithStreamingResponse(self)
45
46 def list(
47 self,
48 federation_rule_id: str,
49 *,
50 limit: int | Omit = omit,
51 page: Optional[str] | Omit = omit,
52 betas: List[AnthropicBetaParam] | Omit = omit,
53 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
54 # The extra values given here take precedence over values defined on the client or passed to this method.
55 extra_headers: Headers | None = None,
56 extra_query: Query | None = None,
57 extra_body: Body | None = None,
58 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
59 ) -> SyncPageCursor[BetaFederationRuleWorkspace]:
60 """
61 **Requires an OAuth access token with the `org:admin` scope**, from
62 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
63 API keys are not accepted. See
64 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
65
66 List workspaces where this federation rule is enabled.
67
68 Returns all workspace enablements in a single response; the `limit` and `page`
69 parameters are accepted but have no effect, and `next_page` is always `null`.
70 Returns explicit per-workspace enablements only; for rules with
71 `applies_to_all_workspaces` or a legacy single `workspace_id`, check those
72 fields on the rule itself.
73
74 Args:
75 federation_rule_id: ID of the federation rule.
76
77 limit: Number of results per page.
78
79 page: Opaque cursor from a previous response's `next_page`.
80
81 betas: Optional header to specify the beta version(s) you want to use.
82
83 extra_headers: Send extra headers
84
85 extra_query: Add additional query parameters to the request
86
87 extra_body: Add additional JSON properties to the request
88
89 timeout: Override the client-level default timeout for this request, in seconds
90 """
91 if not federation_rule_id:
92 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
93 extra_headers = {
94 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
95 **(extra_headers or {}),
96 }
97 return self._get_api_list(
98 path_template(
99 "/v1/organizations/federation_rules/{federation_rule_id}/workspaces?beta=true",
100 federation_rule_id=federation_rule_id,
101 ),
102 page=SyncPageCursor[BetaFederationRuleWorkspace],
103 options=make_request_options(
104 extra_headers=extra_headers,
105 extra_query=extra_query,
106 extra_body=extra_body,
107 timeout=timeout,
108 query={
109 "limit": limit,
110 "page": page,
111 },
112 ),
113 model=BetaFederationRuleWorkspace,
114 )
115
116 def add(
117 self,
118 federation_rule_id: str,
119 *,
120 workspace_id: str,
121 betas: List[AnthropicBetaParam] | Omit = omit,
122 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
123 # The extra values given here take precedence over values defined on the client or passed to this method.
124 extra_headers: Headers | None = None,
125 extra_query: Query | None = None,
126 extra_body: Body | None = None,
127 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
128 ) -> BetaFederationRuleWorkspace:
129 """
130 **Requires an OAuth access token with the `org:admin` scope**, from
131 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
132 API keys are not accepted. See
133 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
134
135 Enable a federation rule for a workspace.
136
137 Idempotent; re-enabling returns the existing enablement. The rule and workspace
138 must both belong to your organization. Membership of the rule's target service
139 account in this workspace is not checked at enablement: token exchange into this
140 workspace is rejected unless the target is a member (it is implicitly a member
141 of the default workspace). Archived rules are rejected with 400. OAuth callers
142 may only manage rules whose `oauth_scope` is `workspace:developer` or
143 `workspace:inference`; other scopes require a Console session.
144
145 Args:
146 federation_rule_id: ID of the federation rule.
147
148 workspace_id: Tagged ID of the workspace to enable this rule for.
149
150 betas: Optional header to specify the beta version(s) you want to use.
151
152 extra_headers: Send extra headers
153
154 extra_query: Add additional query parameters to the request
155
156 extra_body: Add additional JSON properties to the request
157
158 timeout: Override the client-level default timeout for this request, in seconds
159 """
160 if not federation_rule_id:
161 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
162 extra_headers = {
163 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
164 **(extra_headers or {}),
165 }
166 return self._post(
167 path_template(
168 "/v1/organizations/federation_rules/{federation_rule_id}/workspaces?beta=true",
169 federation_rule_id=federation_rule_id,
170 ),
171 body={"workspace_id": workspace_id},
172 options=make_request_options(
173 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
174 ),
175 cast_to=BetaFederationRuleWorkspace,
176 )
177
178 def remove(
179 self,
180 workspace_id: str,
181 *,
182 federation_rule_id: str,
183 betas: List[AnthropicBetaParam] | Omit = omit,
184 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
185 # The extra values given here take precedence over values defined on the client or passed to this method.
186 extra_headers: Headers | None = None,
187 extra_query: Query | None = None,
188 extra_body: Body | None = None,
189 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
190 ) -> WorkspaceRemoveResponse:
191 """
192 **Requires an OAuth access token with the `org:admin` scope**, from
193 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
194 API keys are not accepted. See
195 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
196
197 Disable a federation rule for a workspace.
198
199 Idempotent; succeeds even if the enablement was already removed. OAuth callers
200 may only manage rules whose `oauth_scope` is `workspace:developer` or
201 `workspace:inference`; other scopes require a Console session.
202
203 Args:
204 federation_rule_id: ID of the federation rule.
205
206 workspace_id: ID of the workspace to disable for.
207
208 betas: Optional header to specify the beta version(s) you want to use.
209
210 extra_headers: Send extra headers
211
212 extra_query: Add additional query parameters to the request
213
214 extra_body: Add additional JSON properties to the request
215
216 timeout: Override the client-level default timeout for this request, in seconds
217 """
218 if not federation_rule_id:
219 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
220 if not workspace_id:
221 raise ValueError(f"Expected a non-empty value for `workspace_id` but received {workspace_id!r}")
222 extra_headers = {
223 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
224 **(extra_headers or {}),
225 }
226 return self._delete(
227 path_template(
228 "/v1/organizations/federation_rules/{federation_rule_id}/workspaces/{workspace_id}?beta=true",
229 federation_rule_id=federation_rule_id,
230 workspace_id=workspace_id,
231 ),
232 options=make_request_options(
233 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
234 ),
235 cast_to=WorkspaceRemoveResponse,
236 )
237
238
239 class AsyncWorkspaces(AsyncAPIResource):
240 @cached_property
241 def with_raw_response(self) -> AsyncWorkspacesWithRawResponse:
242 """
243 This property can be used as a prefix for any HTTP method call to return
244 the raw response object instead of the parsed content.
245
246 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
247 """
248 return AsyncWorkspacesWithRawResponse(self)
249
250 @cached_property
251 def with_streaming_response(self) -> AsyncWorkspacesWithStreamingResponse:
252 """
253 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
254
255 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
256 """
257 return AsyncWorkspacesWithStreamingResponse(self)
258
259 def list(
260 self,
261 federation_rule_id: str,
262 *,
263 limit: int | Omit = omit,
264 page: Optional[str] | Omit = omit,
265 betas: List[AnthropicBetaParam] | Omit = omit,
266 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
267 # The extra values given here take precedence over values defined on the client or passed to this method.
268 extra_headers: Headers | None = None,
269 extra_query: Query | None = None,
270 extra_body: Body | None = None,
271 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
272 ) -> AsyncPaginator[BetaFederationRuleWorkspace, AsyncPageCursor[BetaFederationRuleWorkspace]]:
273 """
274 **Requires an OAuth access token with the `org:admin` scope**, from
275 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
276 API keys are not accepted. See
277 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
278
279 List workspaces where this federation rule is enabled.
280
281 Returns all workspace enablements in a single response; the `limit` and `page`
282 parameters are accepted but have no effect, and `next_page` is always `null`.
283 Returns explicit per-workspace enablements only; for rules with
284 `applies_to_all_workspaces` or a legacy single `workspace_id`, check those
285 fields on the rule itself.
286
287 Args:
288 federation_rule_id: ID of the federation rule.
289
290 limit: Number of results per page.
291
292 page: Opaque cursor from a previous response's `next_page`.
293
294 betas: Optional header to specify the beta version(s) you want to use.
295
296 extra_headers: Send extra headers
297
298 extra_query: Add additional query parameters to the request
299
300 extra_body: Add additional JSON properties to the request
301
302 timeout: Override the client-level default timeout for this request, in seconds
303 """
304 if not federation_rule_id:
305 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
306 extra_headers = {
307 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
308 **(extra_headers or {}),
309 }
310 return self._get_api_list(
311 path_template(
312 "/v1/organizations/federation_rules/{federation_rule_id}/workspaces?beta=true",
313 federation_rule_id=federation_rule_id,
314 ),
315 page=AsyncPageCursor[BetaFederationRuleWorkspace],
316 options=make_request_options(
317 extra_headers=extra_headers,
318 extra_query=extra_query,
319 extra_body=extra_body,
320 timeout=timeout,
321 query={
322 "limit": limit,
323 "page": page,
324 },
325 ),
326 model=BetaFederationRuleWorkspace,
327 )
328
329 async def add(
330 self,
331 federation_rule_id: str,
332 *,
333 workspace_id: str,
334 betas: List[AnthropicBetaParam] | Omit = omit,
335 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
336 # The extra values given here take precedence over values defined on the client or passed to this method.
337 extra_headers: Headers | None = None,
338 extra_query: Query | None = None,
339 extra_body: Body | None = None,
340 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
341 ) -> BetaFederationRuleWorkspace:
342 """
343 **Requires an OAuth access token with the `org:admin` scope**, from
344 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
345 API keys are not accepted. See
346 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
347
348 Enable a federation rule for a workspace.
349
350 Idempotent; re-enabling returns the existing enablement. The rule and workspace
351 must both belong to your organization. Membership of the rule's target service
352 account in this workspace is not checked at enablement: token exchange into this
353 workspace is rejected unless the target is a member (it is implicitly a member
354 of the default workspace). Archived rules are rejected with 400. OAuth callers
355 may only manage rules whose `oauth_scope` is `workspace:developer` or
356 `workspace:inference`; other scopes require a Console session.
357
358 Args:
359 federation_rule_id: ID of the federation rule.
360
361 workspace_id: Tagged ID of the workspace to enable this rule for.
362
363 betas: Optional header to specify the beta version(s) you want to use.
364
365 extra_headers: Send extra headers
366
367 extra_query: Add additional query parameters to the request
368
369 extra_body: Add additional JSON properties to the request
370
371 timeout: Override the client-level default timeout for this request, in seconds
372 """
373 if not federation_rule_id:
374 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
375 extra_headers = {
376 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
377 **(extra_headers or {}),
378 }
379 return await self._post(
380 path_template(
381 "/v1/organizations/federation_rules/{federation_rule_id}/workspaces?beta=true",
382 federation_rule_id=federation_rule_id,
383 ),
384 body={"workspace_id": workspace_id},
385 options=make_request_options(
386 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
387 ),
388 cast_to=BetaFederationRuleWorkspace,
389 )
390
391 async def remove(
392 self,
393 workspace_id: str,
394 *,
395 federation_rule_id: str,
396 betas: List[AnthropicBetaParam] | Omit = omit,
397 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
398 # The extra values given here take precedence over values defined on the client or passed to this method.
399 extra_headers: Headers | None = None,
400 extra_query: Query | None = None,
401 extra_body: Body | None = None,
402 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
403 ) -> WorkspaceRemoveResponse:
404 """
405 **Requires an OAuth access token with the `org:admin` scope**, from
406 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
407 API keys are not accepted. See
408 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
409
410 Disable a federation rule for a workspace.
411
412 Idempotent; succeeds even if the enablement was already removed. OAuth callers
413 may only manage rules whose `oauth_scope` is `workspace:developer` or
414 `workspace:inference`; other scopes require a Console session.
415
416 Args:
417 federation_rule_id: ID of the federation rule.
418
419 workspace_id: ID of the workspace to disable for.
420
421 betas: Optional header to specify the beta version(s) you want to use.
422
423 extra_headers: Send extra headers
424
425 extra_query: Add additional query parameters to the request
426
427 extra_body: Add additional JSON properties to the request
428
429 timeout: Override the client-level default timeout for this request, in seconds
430 """
431 if not federation_rule_id:
432 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
433 if not workspace_id:
434 raise ValueError(f"Expected a non-empty value for `workspace_id` but received {workspace_id!r}")
435 extra_headers = {
436 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
437 **(extra_headers or {}),
438 }
439 return await self._delete(
440 path_template(
441 "/v1/organizations/federation_rules/{federation_rule_id}/workspaces/{workspace_id}?beta=true",
442 federation_rule_id=federation_rule_id,
443 workspace_id=workspace_id,
444 ),
445 options=make_request_options(
446 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
447 ),
448 cast_to=WorkspaceRemoveResponse,
449 )
450
451
452 class WorkspacesWithRawResponse:
453 def __init__(self, workspaces: Workspaces) -> None:
454 self._workspaces = workspaces
455
456 self.list = to_raw_response_wrapper(
457 workspaces.list,
458 )
459 self.add = to_raw_response_wrapper(
460 workspaces.add,
461 )
462 self.remove = to_raw_response_wrapper(
463 workspaces.remove,
464 )
465
466
467 class AsyncWorkspacesWithRawResponse:
468 def __init__(self, workspaces: AsyncWorkspaces) -> None:
469 self._workspaces = workspaces
470
471 self.list = async_to_raw_response_wrapper(
472 workspaces.list,
473 )
474 self.add = async_to_raw_response_wrapper(
475 workspaces.add,
476 )
477 self.remove = async_to_raw_response_wrapper(
478 workspaces.remove,
479 )
480
481
482 class WorkspacesWithStreamingResponse:
483 def __init__(self, workspaces: Workspaces) -> None:
484 self._workspaces = workspaces
485
486 self.list = to_streamed_response_wrapper(
487 workspaces.list,
488 )
489 self.add = to_streamed_response_wrapper(
490 workspaces.add,
491 )
492 self.remove = to_streamed_response_wrapper(
493 workspaces.remove,
494 )
495
496
497 class AsyncWorkspacesWithStreamingResponse:
498 def __init__(self, workspaces: AsyncWorkspaces) -> None:
499 self._workspaces = workspaces
500
501 self.list = async_to_streamed_response_wrapper(
502 workspaces.list,
503 )
504 self.add = async_to_streamed_response_wrapper(
505 workspaces.add,
506 )
507 self.remove = async_to_streamed_response_wrapper(
508 workspaces.remove,
509 )