Debian Codegraph @

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

raw
1 from __future__ import annotations
2
3 from typing import Dict, List, Optional
4
5 import httpx2
6
7 from .workspaces import (
8 Workspaces,
9 AsyncWorkspaces,
10 WorkspacesWithRawResponse,
11 AsyncWorkspacesWithRawResponse,
12 WorkspacesWithStreamingResponse,
13 AsyncWorkspacesWithStreamingResponse,
14 )
15 from ......_types import Body, Omit, Query, Headers, NotGiven, omit, not_given
16 from ......_utils import is_given, path_template, strip_not_given
17 from ......_compat import cached_property
18 from ......_resource import SyncAPIResource, AsyncAPIResource
19 from ......_response import (
20 to_raw_response_wrapper,
21 to_streamed_response_wrapper,
22 async_to_raw_response_wrapper,
23 async_to_streamed_response_wrapper,
24 )
25 from ......pagination import SyncPageCursor, AsyncPageCursor
26 from ......_base_client import AsyncPaginator, make_request_options
27 from ......types.anthropic_beta_param import AnthropicBetaParam
28 from ......types.beta.organization.federation.beta_federation_rule import BetaFederationRule
29 from ......types.beta.organization.federation.beta_federation_rule_match_param import BetaFederationRuleMatchParam
30 from ......types.beta.organization.federation.beta_service_account_target_param import BetaServiceAccountTargetParam
31
32 __all__ = ["Rules", "AsyncRules"]
33
34
35 class Rules(SyncAPIResource):
36 @cached_property
37 def workspaces(self) -> Workspaces:
38 return Workspaces(self._client)
39
40 @cached_property
41 def with_raw_response(self) -> RulesWithRawResponse:
42 """
43 This property can be used as a prefix for any HTTP method call to return
44 the raw response object instead of the parsed content.
45
46 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
47 """
48 return RulesWithRawResponse(self)
49
50 @cached_property
51 def with_streaming_response(self) -> RulesWithStreamingResponse:
52 """
53 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
54
55 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
56 """
57 return RulesWithStreamingResponse(self)
58
59 def create(
60 self,
61 *,
62 issuer_id: str,
63 match: BetaFederationRuleMatchParam,
64 name: str,
65 oauth_scope: str,
66 target: BetaServiceAccountTargetParam,
67 applies_to_all_workspaces: bool | Omit = omit,
68 attributes: Optional[Dict[str, str]] | Omit = omit,
69 description: Optional[str] | Omit = omit,
70 token_lifetime_seconds: int | Omit = omit,
71 workspace_id: Optional[str] | Omit = omit,
72 betas: List[AnthropicBetaParam] | Omit = omit,
73 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
74 # The extra values given here take precedence over values defined on the client or passed to this method.
75 extra_headers: Headers | None = None,
76 extra_query: Query | None = None,
77 extra_body: Body | None = None,
78 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
79 ) -> BetaFederationRule:
80 """
81 **Requires an OAuth access token with the `org:admin` scope**, from
82 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
83 API keys are not accepted. See
84 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
85
86 Create a federation rule owned by your organization.
87
88 The referenced issuer and the target service account must already exist in the
89 same organization; invalid references are rejected with a 400 error. The
90 workspace reference is validated. Membership is not checked at rule creation:
91 token exchange resolves a single enabled workspace per call and is rejected
92 unless the target service account is a member of that workspace (it is
93 implicitly a member of the default workspace). Rules on well-known shared
94 issuers (GitHub Actions, GitLab, Buildkite, Terraform Cloud, Google) must
95 constrain tenant identity via an identity-bearing claim, a tenant-pinning
96 subject prefix (such as `repo:YOUR_ORG/...`), or a CEL condition referencing one
97 of those identity claims (e.g. `claims.repository_owner`). OAuth callers may
98 only manage rules whose `oauth_scope` is `workspace:developer` or
99 `workspace:inference`; other scopes require a Console session.
100
101 Args:
102 issuer_id: Tagged ID of the federation issuer.
103
104 match: Conditions the verified JWT must satisfy for this rule to apply. At least one of
105 `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
106 `condition` is required; `audience` alone is not sufficient.
107
108 name: Slug identifier (lowercase, digits, hyphens). Unique within the organization; a
109 duplicate name returns 409.
110
111 oauth_scope: Space-separated OAuth scopes. OAuth callers may only set `workspace:developer`
112 or `workspace:inference`; other scopes (such as `org:admin`) require a Console
113 session.
114
115 target: Identity that tokens minted via this rule act as. Currently always a
116 `service_account` target.
117
118 applies_to_all_workspaces: When true, enable this rule for every workspace in the org (including workspaces
119 created later).
120
121 attributes: CEL expressions `{name: expr}` extracting named values from claims. Not yet
122 supported; any non-empty value is rejected with 400.
123
124 description: Optional free-text description.
125
126 token_lifetime_seconds: Lifetime in seconds for access tokens minted via this rule (60-86400). Defaults
127 to 3600 (1h). Minted tokens are capped at
128 `max(60, min(this value, 2 × remaining assertion validity))` seconds.
129
130 workspace_id: Tagged ID of the workspace to enable this rule for. Required unless
131 `applies_to_all_workspaces` is true. Additional workspaces can be added via the
132 `/federation_rules/{federation_rule_id}/workspaces` sub-resource.
133
134 betas: Optional header to specify the beta version(s) you want to use.
135
136 extra_headers: Send extra headers
137
138 extra_query: Add additional query parameters to the request
139
140 extra_body: Add additional JSON properties to the request
141
142 timeout: Override the client-level default timeout for this request, in seconds
143 """
144 extra_headers = {
145 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
146 **(extra_headers or {}),
147 }
148 return self._post(
149 "/v1/organizations/federation_rules?beta=true",
150 body={
151 "issuer_id": issuer_id,
152 "match": match,
153 "name": name,
154 "oauth_scope": oauth_scope,
155 "target": target,
156 "applies_to_all_workspaces": applies_to_all_workspaces,
157 "attributes": attributes,
158 "description": description,
159 "token_lifetime_seconds": token_lifetime_seconds,
160 "workspace_id": workspace_id,
161 },
162 options=make_request_options(
163 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
164 ),
165 cast_to=BetaFederationRule,
166 )
167
168 def retrieve(
169 self,
170 federation_rule_id: str,
171 *,
172 betas: List[AnthropicBetaParam] | Omit = omit,
173 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
174 # The extra values given here take precedence over values defined on the client or passed to this method.
175 extra_headers: Headers | None = None,
176 extra_query: Query | None = None,
177 extra_body: Body | None = None,
178 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
179 ) -> BetaFederationRule:
180 """
181 **Requires an OAuth access token with the `org:admin` scope**, from
182 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
183 API keys are not accepted. See
184 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
185
186 Retrieve a federation rule by its ID (`fdrl_...`).
187
188 Args:
189 federation_rule_id: ID of the federation rule.
190
191 betas: Optional header to specify the beta version(s) you want to use.
192
193 extra_headers: Send extra headers
194
195 extra_query: Add additional query parameters to the request
196
197 extra_body: Add additional JSON properties to the request
198
199 timeout: Override the client-level default timeout for this request, in seconds
200 """
201 if not federation_rule_id:
202 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
203 extra_headers = {
204 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
205 **(extra_headers or {}),
206 }
207 return self._get(
208 path_template(
209 "/v1/organizations/federation_rules/{federation_rule_id}?beta=true",
210 federation_rule_id=federation_rule_id,
211 ),
212 options=make_request_options(
213 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
214 ),
215 cast_to=BetaFederationRule,
216 )
217
218 def update(
219 self,
220 federation_rule_id: str,
221 *,
222 applies_to_all_workspaces: Optional[bool] | Omit = omit,
223 attributes: Optional[Dict[str, str]] | Omit = omit,
224 description: Optional[str] | Omit = omit,
225 match: Optional[BetaFederationRuleMatchParam] | Omit = omit,
226 name: Optional[str] | Omit = omit,
227 oauth_scope: Optional[str] | Omit = omit,
228 target: Optional[BetaServiceAccountTargetParam] | Omit = omit,
229 token_lifetime_seconds: Optional[int] | Omit = omit,
230 workspace_id: Optional[str] | Omit = omit,
231 betas: List[AnthropicBetaParam] | Omit = omit,
232 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
233 # The extra values given here take precedence over values defined on the client or passed to this method.
234 extra_headers: Headers | None = None,
235 extra_query: Query | None = None,
236 extra_body: Body | None = None,
237 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
238 ) -> BetaFederationRule:
239 """
240 **Requires an OAuth access token with the `org:admin` scope**, from
241 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
242 API keys are not accepted. See
243 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
244
245 Partially update a federation rule.
246
247 `issuer_id` is immutable. `match` and `target` are replaced as whole objects
248 when set. Referenced service accounts and workspaces must exist in your
249 organization; invalid references are rejected with a 400 error. Archived rules
250 cannot be updated; this returns 400. Create a new rule instead. Rules on
251 well-known shared issuers (GitHub Actions, GitLab, Buildkite, Terraform Cloud,
252 Google) must constrain tenant identity via an identity-bearing claim, a
253 tenant-pinning subject prefix (such as `repo:YOUR_ORG/...`), or a CEL condition
254 referencing one of those identity claims (e.g. `claims.repository_owner`). On
255 these issuers the requirement is re-checked on every update; if an existing
256 rule's stored match does not yet constrain tenant identity, any update (even a
257 rename or description change) must also supply a conforming `match` in the same
258 request. OAuth callers may only manage rules whose `oauth_scope` is
259 `workspace:developer` or `workspace:inference`; other scopes require a Console
260 session.
261
262 Args:
263 federation_rule_id: ID of the federation rule to update.
264
265 applies_to_all_workspaces: When true, enables this rule for every workspace in the org (including
266 workspaces created later). Setting `false` is rejected with 400 if no workspace
267 would remain enabled; a rule with only a legacy `workspace_id` binding continues
268 to mint.
269
270 attributes: Replaces the CEL expressions `{name: expr}` extracting named values from claims.
271 Send null to clear them. Not yet supported; any non-empty value is rejected
272 with 400.
273
274 description: Replaces the description. Omit to leave unchanged; send `null` to clear (the
275 field is stored as an empty string).
276
277 match: Replaces the entire match object. All populated matcher fields must pass.
278
279 name: Replaces the slug identifier (lowercase, digits, hyphens). Unique within the
280 organization; a duplicate name returns 409.
281
282 oauth_scope: Replaces the space-separated OAuth scopes granted on minted tokens. OAuth
283 callers may only set `workspace:developer` or `workspace:inference`; other
284 scopes (such as `org:admin`) require a Console session.
285
286 target: Replaces the entire target object. Currently always a `service_account` target.
287
288 token_lifetime_seconds: Replaces the lifetime in seconds for access tokens minted via this rule
289 (60-86400). Minted tokens are capped at
290 `max(60, min(this value, 2 × remaining assertion validity))` seconds.
291
292 workspace_id: Replaces the existing single workspace enablement (the previous one is removed).
293 Rejected with 400 if the rule is enabled for more than one workspace; use the
294 `/federation_rules/{federation_rule_id}/workspaces` sub-resource instead.
295
296 betas: Optional header to specify the beta version(s) you want to use.
297
298 extra_headers: Send extra headers
299
300 extra_query: Add additional query parameters to the request
301
302 extra_body: Add additional JSON properties to the request
303
304 timeout: Override the client-level default timeout for this request, in seconds
305 """
306 if not federation_rule_id:
307 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
308 extra_headers = {
309 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
310 **(extra_headers or {}),
311 }
312 return self._post(
313 path_template(
314 "/v1/organizations/federation_rules/{federation_rule_id}?beta=true",
315 federation_rule_id=federation_rule_id,
316 ),
317 body={
318 "applies_to_all_workspaces": applies_to_all_workspaces,
319 "attributes": attributes,
320 "description": description,
321 "match": match,
322 "name": name,
323 "oauth_scope": oauth_scope,
324 "target": target,
325 "token_lifetime_seconds": token_lifetime_seconds,
326 "workspace_id": workspace_id,
327 },
328 options=make_request_options(
329 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
330 ),
331 cast_to=BetaFederationRule,
332 )
333
334 def list(
335 self,
336 *,
337 include_archived: bool | Omit = omit,
338 issuer_id: Optional[str] | Omit = omit,
339 limit: int | Omit = omit,
340 page: Optional[str] | Omit = omit,
341 betas: List[AnthropicBetaParam] | Omit = omit,
342 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
343 # The extra values given here take precedence over values defined on the client or passed to this method.
344 extra_headers: Headers | None = None,
345 extra_query: Query | None = None,
346 extra_body: Body | None = None,
347 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
348 ) -> SyncPageCursor[BetaFederationRule]:
349 """
350 **Requires an OAuth access token with the `org:admin` scope**, from
351 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
352 API keys are not accepted. See
353 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
354
355 List federation rules in your organization.
356
357 Optionally filter by issuer with `issuer_id`. Archived rules are excluded unless
358 `include_archived=true`.
359
360 Args:
361 include_archived: Include archived resources. Defaults to false.
362
363 issuer_id: Filter to rules referencing this federation issuer.
364
365 limit: Number of results per page.
366
367 page: Opaque cursor from a previous response's `next_page`.
368
369 betas: Optional header to specify the beta version(s) you want to use.
370
371 extra_headers: Send extra headers
372
373 extra_query: Add additional query parameters to the request
374
375 extra_body: Add additional JSON properties to the request
376
377 timeout: Override the client-level default timeout for this request, in seconds
378 """
379 extra_headers = {
380 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
381 **(extra_headers or {}),
382 }
383 return self._get_api_list(
384 "/v1/organizations/federation_rules?beta=true",
385 page=SyncPageCursor[BetaFederationRule],
386 options=make_request_options(
387 extra_headers=extra_headers,
388 extra_query=extra_query,
389 extra_body=extra_body,
390 timeout=timeout,
391 query={
392 "include_archived": include_archived,
393 "issuer_id": issuer_id,
394 "limit": limit,
395 "page": page,
396 },
397 ),
398 model=BetaFederationRule,
399 )
400
401 def archive(
402 self,
403 federation_rule_id: str,
404 *,
405 betas: List[AnthropicBetaParam] | Omit = omit,
406 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
407 # The extra values given here take precedence over values defined on the client or passed to this method.
408 extra_headers: Headers | None = None,
409 extra_query: Query | None = None,
410 extra_body: Body | None = None,
411 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
412 ) -> BetaFederationRule:
413 """
414 **Requires an OAuth access token with the `org:admin` scope**, from
415 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
416 API keys are not accepted. See
417 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
418
419 Archive a federation rule.
420
421 Token exchange through this rule stops immediately. Idempotent; re-archiving
422 returns the rule with its original `archived_at`. Archiving clears the rule's
423 workspace targeting (`workspace_id` and `workspace_ids` are emptied). Tokens
424 already minted before archive remain valid until they expire. OAuth callers may
425 only manage rules whose `oauth_scope` is `workspace:developer` or
426 `workspace:inference`; other scopes require a Console session.
427
428 Args:
429 federation_rule_id: ID of the federation rule to archive.
430
431 betas: Optional header to specify the beta version(s) you want to use.
432
433 extra_headers: Send extra headers
434
435 extra_query: Add additional query parameters to the request
436
437 extra_body: Add additional JSON properties to the request
438
439 timeout: Override the client-level default timeout for this request, in seconds
440 """
441 if not federation_rule_id:
442 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
443 extra_headers = {
444 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
445 **(extra_headers or {}),
446 }
447 return self._post(
448 path_template(
449 "/v1/organizations/federation_rules/{federation_rule_id}/archive?beta=true",
450 federation_rule_id=federation_rule_id,
451 ),
452 options=make_request_options(
453 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
454 ),
455 cast_to=BetaFederationRule,
456 )
457
458
459 class AsyncRules(AsyncAPIResource):
460 @cached_property
461 def workspaces(self) -> AsyncWorkspaces:
462 return AsyncWorkspaces(self._client)
463
464 @cached_property
465 def with_raw_response(self) -> AsyncRulesWithRawResponse:
466 """
467 This property can be used as a prefix for any HTTP method call to return
468 the raw response object instead of the parsed content.
469
470 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
471 """
472 return AsyncRulesWithRawResponse(self)
473
474 @cached_property
475 def with_streaming_response(self) -> AsyncRulesWithStreamingResponse:
476 """
477 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
478
479 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
480 """
481 return AsyncRulesWithStreamingResponse(self)
482
483 async def create(
484 self,
485 *,
486 issuer_id: str,
487 match: BetaFederationRuleMatchParam,
488 name: str,
489 oauth_scope: str,
490 target: BetaServiceAccountTargetParam,
491 applies_to_all_workspaces: bool | Omit = omit,
492 attributes: Optional[Dict[str, str]] | Omit = omit,
493 description: Optional[str] | Omit = omit,
494 token_lifetime_seconds: int | Omit = omit,
495 workspace_id: Optional[str] | Omit = omit,
496 betas: List[AnthropicBetaParam] | Omit = omit,
497 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
498 # The extra values given here take precedence over values defined on the client or passed to this method.
499 extra_headers: Headers | None = None,
500 extra_query: Query | None = None,
501 extra_body: Body | None = None,
502 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
503 ) -> BetaFederationRule:
504 """
505 **Requires an OAuth access token with the `org:admin` scope**, from
506 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
507 API keys are not accepted. See
508 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
509
510 Create a federation rule owned by your organization.
511
512 The referenced issuer and the target service account must already exist in the
513 same organization; invalid references are rejected with a 400 error. The
514 workspace reference is validated. Membership is not checked at rule creation:
515 token exchange resolves a single enabled workspace per call and is rejected
516 unless the target service account is a member of that workspace (it is
517 implicitly a member of the default workspace). Rules on well-known shared
518 issuers (GitHub Actions, GitLab, Buildkite, Terraform Cloud, Google) must
519 constrain tenant identity via an identity-bearing claim, a tenant-pinning
520 subject prefix (such as `repo:YOUR_ORG/...`), or a CEL condition referencing one
521 of those identity claims (e.g. `claims.repository_owner`). OAuth callers may
522 only manage rules whose `oauth_scope` is `workspace:developer` or
523 `workspace:inference`; other scopes require a Console session.
524
525 Args:
526 issuer_id: Tagged ID of the federation issuer.
527
528 match: Conditions the verified JWT must satisfy for this rule to apply. At least one of
529 `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
530 `condition` is required; `audience` alone is not sufficient.
531
532 name: Slug identifier (lowercase, digits, hyphens). Unique within the organization; a
533 duplicate name returns 409.
534
535 oauth_scope: Space-separated OAuth scopes. OAuth callers may only set `workspace:developer`
536 or `workspace:inference`; other scopes (such as `org:admin`) require a Console
537 session.
538
539 target: Identity that tokens minted via this rule act as. Currently always a
540 `service_account` target.
541
542 applies_to_all_workspaces: When true, enable this rule for every workspace in the org (including workspaces
543 created later).
544
545 attributes: CEL expressions `{name: expr}` extracting named values from claims. Not yet
546 supported; any non-empty value is rejected with 400.
547
548 description: Optional free-text description.
549
550 token_lifetime_seconds: Lifetime in seconds for access tokens minted via this rule (60-86400). Defaults
551 to 3600 (1h). Minted tokens are capped at
552 `max(60, min(this value, 2 × remaining assertion validity))` seconds.
553
554 workspace_id: Tagged ID of the workspace to enable this rule for. Required unless
555 `applies_to_all_workspaces` is true. Additional workspaces can be added via the
556 `/federation_rules/{federation_rule_id}/workspaces` sub-resource.
557
558 betas: Optional header to specify the beta version(s) you want to use.
559
560 extra_headers: Send extra headers
561
562 extra_query: Add additional query parameters to the request
563
564 extra_body: Add additional JSON properties to the request
565
566 timeout: Override the client-level default timeout for this request, in seconds
567 """
568 extra_headers = {
569 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
570 **(extra_headers or {}),
571 }
572 return await self._post(
573 "/v1/organizations/federation_rules?beta=true",
574 body={
575 "issuer_id": issuer_id,
576 "match": match,
577 "name": name,
578 "oauth_scope": oauth_scope,
579 "target": target,
580 "applies_to_all_workspaces": applies_to_all_workspaces,
581 "attributes": attributes,
582 "description": description,
583 "token_lifetime_seconds": token_lifetime_seconds,
584 "workspace_id": workspace_id,
585 },
586 options=make_request_options(
587 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
588 ),
589 cast_to=BetaFederationRule,
590 )
591
592 async def retrieve(
593 self,
594 federation_rule_id: str,
595 *,
596 betas: List[AnthropicBetaParam] | Omit = omit,
597 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
598 # The extra values given here take precedence over values defined on the client or passed to this method.
599 extra_headers: Headers | None = None,
600 extra_query: Query | None = None,
601 extra_body: Body | None = None,
602 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
603 ) -> BetaFederationRule:
604 """
605 **Requires an OAuth access token with the `org:admin` scope**, from
606 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
607 API keys are not accepted. See
608 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
609
610 Retrieve a federation rule by its ID (`fdrl_...`).
611
612 Args:
613 federation_rule_id: ID of the federation rule.
614
615 betas: Optional header to specify the beta version(s) you want to use.
616
617 extra_headers: Send extra headers
618
619 extra_query: Add additional query parameters to the request
620
621 extra_body: Add additional JSON properties to the request
622
623 timeout: Override the client-level default timeout for this request, in seconds
624 """
625 if not federation_rule_id:
626 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
627 extra_headers = {
628 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
629 **(extra_headers or {}),
630 }
631 return await self._get(
632 path_template(
633 "/v1/organizations/federation_rules/{federation_rule_id}?beta=true",
634 federation_rule_id=federation_rule_id,
635 ),
636 options=make_request_options(
637 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
638 ),
639 cast_to=BetaFederationRule,
640 )
641
642 async def update(
643 self,
644 federation_rule_id: str,
645 *,
646 applies_to_all_workspaces: Optional[bool] | Omit = omit,
647 attributes: Optional[Dict[str, str]] | Omit = omit,
648 description: Optional[str] | Omit = omit,
649 match: Optional[BetaFederationRuleMatchParam] | Omit = omit,
650 name: Optional[str] | Omit = omit,
651 oauth_scope: Optional[str] | Omit = omit,
652 target: Optional[BetaServiceAccountTargetParam] | Omit = omit,
653 token_lifetime_seconds: Optional[int] | Omit = omit,
654 workspace_id: Optional[str] | Omit = omit,
655 betas: List[AnthropicBetaParam] | Omit = omit,
656 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
657 # The extra values given here take precedence over values defined on the client or passed to this method.
658 extra_headers: Headers | None = None,
659 extra_query: Query | None = None,
660 extra_body: Body | None = None,
661 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
662 ) -> BetaFederationRule:
663 """
664 **Requires an OAuth access token with the `org:admin` scope**, from
665 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
666 API keys are not accepted. See
667 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
668
669 Partially update a federation rule.
670
671 `issuer_id` is immutable. `match` and `target` are replaced as whole objects
672 when set. Referenced service accounts and workspaces must exist in your
673 organization; invalid references are rejected with a 400 error. Archived rules
674 cannot be updated; this returns 400. Create a new rule instead. Rules on
675 well-known shared issuers (GitHub Actions, GitLab, Buildkite, Terraform Cloud,
676 Google) must constrain tenant identity via an identity-bearing claim, a
677 tenant-pinning subject prefix (such as `repo:YOUR_ORG/...`), or a CEL condition
678 referencing one of those identity claims (e.g. `claims.repository_owner`). On
679 these issuers the requirement is re-checked on every update; if an existing
680 rule's stored match does not yet constrain tenant identity, any update (even a
681 rename or description change) must also supply a conforming `match` in the same
682 request. OAuth callers may only manage rules whose `oauth_scope` is
683 `workspace:developer` or `workspace:inference`; other scopes require a Console
684 session.
685
686 Args:
687 federation_rule_id: ID of the federation rule to update.
688
689 applies_to_all_workspaces: When true, enables this rule for every workspace in the org (including
690 workspaces created later). Setting `false` is rejected with 400 if no workspace
691 would remain enabled; a rule with only a legacy `workspace_id` binding continues
692 to mint.
693
694 attributes: Replaces the CEL expressions `{name: expr}` extracting named values from claims.
695 Send null to clear them. Not yet supported; any non-empty value is rejected
696 with 400.
697
698 description: Replaces the description. Omit to leave unchanged; send `null` to clear (the
699 field is stored as an empty string).
700
701 match: Replaces the entire match object. All populated matcher fields must pass.
702
703 name: Replaces the slug identifier (lowercase, digits, hyphens). Unique within the
704 organization; a duplicate name returns 409.
705
706 oauth_scope: Replaces the space-separated OAuth scopes granted on minted tokens. OAuth
707 callers may only set `workspace:developer` or `workspace:inference`; other
708 scopes (such as `org:admin`) require a Console session.
709
710 target: Replaces the entire target object. Currently always a `service_account` target.
711
712 token_lifetime_seconds: Replaces the lifetime in seconds for access tokens minted via this rule
713 (60-86400). Minted tokens are capped at
714 `max(60, min(this value, 2 × remaining assertion validity))` seconds.
715
716 workspace_id: Replaces the existing single workspace enablement (the previous one is removed).
717 Rejected with 400 if the rule is enabled for more than one workspace; use the
718 `/federation_rules/{federation_rule_id}/workspaces` sub-resource instead.
719
720 betas: Optional header to specify the beta version(s) you want to use.
721
722 extra_headers: Send extra headers
723
724 extra_query: Add additional query parameters to the request
725
726 extra_body: Add additional JSON properties to the request
727
728 timeout: Override the client-level default timeout for this request, in seconds
729 """
730 if not federation_rule_id:
731 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
732 extra_headers = {
733 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
734 **(extra_headers or {}),
735 }
736 return await self._post(
737 path_template(
738 "/v1/organizations/federation_rules/{federation_rule_id}?beta=true",
739 federation_rule_id=federation_rule_id,
740 ),
741 body={
742 "applies_to_all_workspaces": applies_to_all_workspaces,
743 "attributes": attributes,
744 "description": description,
745 "match": match,
746 "name": name,
747 "oauth_scope": oauth_scope,
748 "target": target,
749 "token_lifetime_seconds": token_lifetime_seconds,
750 "workspace_id": workspace_id,
751 },
752 options=make_request_options(
753 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
754 ),
755 cast_to=BetaFederationRule,
756 )
757
758 def list(
759 self,
760 *,
761 include_archived: bool | Omit = omit,
762 issuer_id: Optional[str] | Omit = omit,
763 limit: int | Omit = omit,
764 page: Optional[str] | Omit = omit,
765 betas: List[AnthropicBetaParam] | Omit = omit,
766 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
767 # The extra values given here take precedence over values defined on the client or passed to this method.
768 extra_headers: Headers | None = None,
769 extra_query: Query | None = None,
770 extra_body: Body | None = None,
771 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
772 ) -> AsyncPaginator[BetaFederationRule, AsyncPageCursor[BetaFederationRule]]:
773 """
774 **Requires an OAuth access token with the `org:admin` scope**, from
775 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
776 API keys are not accepted. See
777 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
778
779 List federation rules in your organization.
780
781 Optionally filter by issuer with `issuer_id`. Archived rules are excluded unless
782 `include_archived=true`.
783
784 Args:
785 include_archived: Include archived resources. Defaults to false.
786
787 issuer_id: Filter to rules referencing this federation issuer.
788
789 limit: Number of results per page.
790
791 page: Opaque cursor from a previous response's `next_page`.
792
793 betas: Optional header to specify the beta version(s) you want to use.
794
795 extra_headers: Send extra headers
796
797 extra_query: Add additional query parameters to the request
798
799 extra_body: Add additional JSON properties to the request
800
801 timeout: Override the client-level default timeout for this request, in seconds
802 """
803 extra_headers = {
804 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
805 **(extra_headers or {}),
806 }
807 return self._get_api_list(
808 "/v1/organizations/federation_rules?beta=true",
809 page=AsyncPageCursor[BetaFederationRule],
810 options=make_request_options(
811 extra_headers=extra_headers,
812 extra_query=extra_query,
813 extra_body=extra_body,
814 timeout=timeout,
815 query={
816 "include_archived": include_archived,
817 "issuer_id": issuer_id,
818 "limit": limit,
819 "page": page,
820 },
821 ),
822 model=BetaFederationRule,
823 )
824
825 async def archive(
826 self,
827 federation_rule_id: str,
828 *,
829 betas: List[AnthropicBetaParam] | Omit = omit,
830 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
831 # The extra values given here take precedence over values defined on the client or passed to this method.
832 extra_headers: Headers | None = None,
833 extra_query: Query | None = None,
834 extra_body: Body | None = None,
835 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
836 ) -> BetaFederationRule:
837 """
838 **Requires an OAuth access token with the `org:admin` scope**, from
839 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
840 API keys are not accepted. See
841 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
842
843 Archive a federation rule.
844
845 Token exchange through this rule stops immediately. Idempotent; re-archiving
846 returns the rule with its original `archived_at`. Archiving clears the rule's
847 workspace targeting (`workspace_id` and `workspace_ids` are emptied). Tokens
848 already minted before archive remain valid until they expire. OAuth callers may
849 only manage rules whose `oauth_scope` is `workspace:developer` or
850 `workspace:inference`; other scopes require a Console session.
851
852 Args:
853 federation_rule_id: ID of the federation rule to archive.
854
855 betas: Optional header to specify the beta version(s) you want to use.
856
857 extra_headers: Send extra headers
858
859 extra_query: Add additional query parameters to the request
860
861 extra_body: Add additional JSON properties to the request
862
863 timeout: Override the client-level default timeout for this request, in seconds
864 """
865 if not federation_rule_id:
866 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
867 extra_headers = {
868 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
869 **(extra_headers or {}),
870 }
871 return await self._post(
872 path_template(
873 "/v1/organizations/federation_rules/{federation_rule_id}/archive?beta=true",
874 federation_rule_id=federation_rule_id,
875 ),
876 options=make_request_options(
877 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
878 ),
879 cast_to=BetaFederationRule,
880 )
881
882
883 class RulesWithRawResponse:
884 def __init__(self, rules: Rules) -> None:
885 self._rules = rules
886
887 self.create = to_raw_response_wrapper(
888 rules.create,
889 )
890 self.retrieve = to_raw_response_wrapper(
891 rules.retrieve,
892 )
893 self.update = to_raw_response_wrapper(
894 rules.update,
895 )
896 self.list = to_raw_response_wrapper(
897 rules.list,
898 )
899 self.archive = to_raw_response_wrapper(
900 rules.archive,
901 )
902
903 @cached_property
904 def workspaces(self) -> WorkspacesWithRawResponse:
905 return WorkspacesWithRawResponse(self._rules.workspaces)
906
907
908 class AsyncRulesWithRawResponse:
909 def __init__(self, rules: AsyncRules) -> None:
910 self._rules = rules
911
912 self.create = async_to_raw_response_wrapper(
913 rules.create,
914 )
915 self.retrieve = async_to_raw_response_wrapper(
916 rules.retrieve,
917 )
918 self.update = async_to_raw_response_wrapper(
919 rules.update,
920 )
921 self.list = async_to_raw_response_wrapper(
922 rules.list,
923 )
924 self.archive = async_to_raw_response_wrapper(
925 rules.archive,
926 )
927
928 @cached_property
929 def workspaces(self) -> AsyncWorkspacesWithRawResponse:
930 return AsyncWorkspacesWithRawResponse(self._rules.workspaces)
931
932
933 class RulesWithStreamingResponse:
934 def __init__(self, rules: Rules) -> None:
935 self._rules = rules
936
937 self.create = to_streamed_response_wrapper(
938 rules.create,
939 )
940 self.retrieve = to_streamed_response_wrapper(
941 rules.retrieve,
942 )
943 self.update = to_streamed_response_wrapper(
944 rules.update,
945 )
946 self.list = to_streamed_response_wrapper(
947 rules.list,
948 )
949 self.archive = to_streamed_response_wrapper(
950 rules.archive,
951 )
952
953 @cached_property
954 def workspaces(self) -> WorkspacesWithStreamingResponse:
955 return WorkspacesWithStreamingResponse(self._rules.workspaces)
956
957
958 class AsyncRulesWithStreamingResponse:
959 def __init__(self, rules: AsyncRules) -> None:
960 self._rules = rules
961
962 self.create = async_to_streamed_response_wrapper(
963 rules.create,
964 )
965 self.retrieve = async_to_streamed_response_wrapper(
966 rules.retrieve,
967 )
968 self.update = async_to_streamed_response_wrapper(
969 rules.update,
970 )
971 self.list = async_to_streamed_response_wrapper(
972 rules.list,
973 )
974 self.archive = async_to_streamed_response_wrapper(
975 rules.archive,
976 )
977
978 @cached_property
979 def workspaces(self) -> AsyncWorkspacesWithStreamingResponse:
980 return AsyncWorkspacesWithStreamingResponse(self._rules.workspaces)