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: Does the incoming JWT qualify?
278
279 All populated fields must pass; omitted fields are skipped. At least one of
280 `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
281 `condition` is required; `audience` alone is not sufficient.
282
283 name: Replaces the slug identifier (lowercase, digits, hyphens). Unique within the
284 organization; a duplicate name returns 409.
285
286 oauth_scope: Replaces the space-separated OAuth scopes granted on minted tokens. OAuth
287 callers may only set `workspace:developer` or `workspace:inference`; other
288 scopes (such as `org:admin`) require a Console session.
289
290 target: Bind to a fixed service account by ID.
291
292 token_lifetime_seconds: Replaces the lifetime in seconds for access tokens minted via this rule
293 (60-86400). Minted tokens are capped at
294 `max(60, min(this value, 2 × remaining assertion validity))` seconds.
295
296 workspace_id: Replaces the existing single workspace enablement (the previous one is removed).
297 Rejected with 400 if the rule is enabled for more than one workspace; use the
298 `/federation_rules/{federation_rule_id}/workspaces` sub-resource instead.
299
300 betas: Optional header to specify the beta version(s) you want to use.
301
302 extra_headers: Send extra headers
303
304 extra_query: Add additional query parameters to the request
305
306 extra_body: Add additional JSON properties to the request
307
308 timeout: Override the client-level default timeout for this request, in seconds
309 """
310 if not federation_rule_id:
311 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
312 extra_headers = {
313 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
314 **(extra_headers or {}),
315 }
316 return self._post(
317 path_template(
318 "/v1/organizations/federation_rules/{federation_rule_id}?beta=true",
319 federation_rule_id=federation_rule_id,
320 ),
321 body={
322 "applies_to_all_workspaces": applies_to_all_workspaces,
323 "attributes": attributes,
324 "description": description,
325 "match": match,
326 "name": name,
327 "oauth_scope": oauth_scope,
328 "target": target,
329 "token_lifetime_seconds": token_lifetime_seconds,
330 "workspace_id": workspace_id,
331 },
332 options=make_request_options(
333 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
334 ),
335 cast_to=BetaFederationRule,
336 )
337
338 def list(
339 self,
340 *,
341 include_archived: bool | Omit = omit,
342 issuer_id: Optional[str] | Omit = omit,
343 limit: int | Omit = omit,
344 page: Optional[str] | Omit = omit,
345 betas: List[AnthropicBetaParam] | Omit = omit,
346 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
347 # The extra values given here take precedence over values defined on the client or passed to this method.
348 extra_headers: Headers | None = None,
349 extra_query: Query | None = None,
350 extra_body: Body | None = None,
351 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
352 ) -> SyncPageCursor[BetaFederationRule]:
353 """
354 **Requires an OAuth access token with the `org:admin` scope**, from
355 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
356 API keys are not accepted. See
357 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
358
359 List federation rules in your organization.
360
361 Optionally filter by issuer with `issuer_id`. Archived rules are excluded unless
362 `include_archived=true`.
363
364 Args:
365 include_archived: Include archived resources. Defaults to false.
366
367 issuer_id: Filter to rules referencing this federation issuer.
368
369 limit: Number of results per page.
370
371 page: Opaque cursor from a previous response's `next_page`.
372
373 betas: Optional header to specify the beta version(s) you want to use.
374
375 extra_headers: Send extra headers
376
377 extra_query: Add additional query parameters to the request
378
379 extra_body: Add additional JSON properties to the request
380
381 timeout: Override the client-level default timeout for this request, in seconds
382 """
383 extra_headers = {
384 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
385 **(extra_headers or {}),
386 }
387 return self._get_api_list(
388 "/v1/organizations/federation_rules?beta=true",
389 page=SyncPageCursor[BetaFederationRule],
390 options=make_request_options(
391 extra_headers=extra_headers,
392 extra_query=extra_query,
393 extra_body=extra_body,
394 timeout=timeout,
395 query={
396 "include_archived": include_archived,
397 "issuer_id": issuer_id,
398 "limit": limit,
399 "page": page,
400 },
401 ),
402 model=BetaFederationRule,
403 )
404
405 def archive(
406 self,
407 federation_rule_id: str,
408 *,
409 betas: List[AnthropicBetaParam] | Omit = omit,
410 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
411 # The extra values given here take precedence over values defined on the client or passed to this method.
412 extra_headers: Headers | None = None,
413 extra_query: Query | None = None,
414 extra_body: Body | None = None,
415 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
416 ) -> BetaFederationRule:
417 """
418 **Requires an OAuth access token with the `org:admin` scope**, from
419 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
420 API keys are not accepted. See
421 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
422
423 Archive a federation rule.
424
425 Token exchange through this rule stops immediately. Idempotent; re-archiving
426 returns the rule with its original `archived_at`. Archiving clears the rule's
427 workspace targeting (`workspace_id` and `workspace_ids` are emptied). Tokens
428 already minted before archive remain valid until they expire. OAuth callers may
429 only manage rules whose `oauth_scope` is `workspace:developer` or
430 `workspace:inference`; other scopes require a Console session.
431
432 Args:
433 federation_rule_id: ID of the federation rule to archive.
434
435 betas: Optional header to specify the beta version(s) you want to use.
436
437 extra_headers: Send extra headers
438
439 extra_query: Add additional query parameters to the request
440
441 extra_body: Add additional JSON properties to the request
442
443 timeout: Override the client-level default timeout for this request, in seconds
444 """
445 if not federation_rule_id:
446 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
447 extra_headers = {
448 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
449 **(extra_headers or {}),
450 }
451 return self._post(
452 path_template(
453 "/v1/organizations/federation_rules/{federation_rule_id}/archive?beta=true",
454 federation_rule_id=federation_rule_id,
455 ),
456 options=make_request_options(
457 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
458 ),
459 cast_to=BetaFederationRule,
460 )
461
462
463 class AsyncRules(AsyncAPIResource):
464 @cached_property
465 def workspaces(self) -> AsyncWorkspaces:
466 return AsyncWorkspaces(self._client)
467
468 @cached_property
469 def with_raw_response(self) -> AsyncRulesWithRawResponse:
470 """
471 This property can be used as a prefix for any HTTP method call to return
472 the raw response object instead of the parsed content.
473
474 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
475 """
476 return AsyncRulesWithRawResponse(self)
477
478 @cached_property
479 def with_streaming_response(self) -> AsyncRulesWithStreamingResponse:
480 """
481 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
482
483 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
484 """
485 return AsyncRulesWithStreamingResponse(self)
486
487 async def create(
488 self,
489 *,
490 issuer_id: str,
491 match: BetaFederationRuleMatchParam,
492 name: str,
493 oauth_scope: str,
494 target: BetaServiceAccountTargetParam,
495 applies_to_all_workspaces: bool | Omit = omit,
496 attributes: Optional[Dict[str, str]] | Omit = omit,
497 description: Optional[str] | Omit = omit,
498 token_lifetime_seconds: int | Omit = omit,
499 workspace_id: Optional[str] | Omit = omit,
500 betas: List[AnthropicBetaParam] | Omit = omit,
501 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
502 # The extra values given here take precedence over values defined on the client or passed to this method.
503 extra_headers: Headers | None = None,
504 extra_query: Query | None = None,
505 extra_body: Body | None = None,
506 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
507 ) -> BetaFederationRule:
508 """
509 **Requires an OAuth access token with the `org:admin` scope**, from
510 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
511 API keys are not accepted. See
512 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
513
514 Create a federation rule owned by your organization.
515
516 The referenced issuer and the target service account must already exist in the
517 same organization; invalid references are rejected with a 400 error. The
518 workspace reference is validated. Membership is not checked at rule creation:
519 token exchange resolves a single enabled workspace per call and is rejected
520 unless the target service account is a member of that workspace (it is
521 implicitly a member of the default workspace). Rules on well-known shared
522 issuers (GitHub Actions, GitLab, Buildkite, Terraform Cloud, Google) must
523 constrain tenant identity via an identity-bearing claim, a tenant-pinning
524 subject prefix (such as `repo:YOUR_ORG/...`), or a CEL condition referencing one
525 of those identity claims (e.g. `claims.repository_owner`). OAuth callers may
526 only manage rules whose `oauth_scope` is `workspace:developer` or
527 `workspace:inference`; other scopes require a Console session.
528
529 Args:
530 issuer_id: Tagged ID of the federation issuer.
531
532 match: Conditions the verified JWT must satisfy for this rule to apply. At least one of
533 `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
534 `condition` is required; `audience` alone is not sufficient.
535
536 name: Slug identifier (lowercase, digits, hyphens). Unique within the organization; a
537 duplicate name returns 409.
538
539 oauth_scope: Space-separated OAuth scopes. OAuth callers may only set `workspace:developer`
540 or `workspace:inference`; other scopes (such as `org:admin`) require a Console
541 session.
542
543 target: Identity that tokens minted via this rule act as. Currently always a
544 `service_account` target.
545
546 applies_to_all_workspaces: When true, enable this rule for every workspace in the org (including workspaces
547 created later).
548
549 attributes: CEL expressions `{name: expr}` extracting named values from claims. Not yet
550 supported; any non-empty value is rejected with 400.
551
552 description: Optional free-text description.
553
554 token_lifetime_seconds: Lifetime in seconds for access tokens minted via this rule (60-86400). Defaults
555 to 3600 (1h). Minted tokens are capped at
556 `max(60, min(this value, 2 × remaining assertion validity))` seconds.
557
558 workspace_id: Tagged ID of the workspace to enable this rule for. Required unless
559 `applies_to_all_workspaces` is true. Additional workspaces can be added via the
560 `/federation_rules/{federation_rule_id}/workspaces` sub-resource.
561
562 betas: Optional header to specify the beta version(s) you want to use.
563
564 extra_headers: Send extra headers
565
566 extra_query: Add additional query parameters to the request
567
568 extra_body: Add additional JSON properties to the request
569
570 timeout: Override the client-level default timeout for this request, in seconds
571 """
572 extra_headers = {
573 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
574 **(extra_headers or {}),
575 }
576 return await self._post(
577 "/v1/organizations/federation_rules?beta=true",
578 body={
579 "issuer_id": issuer_id,
580 "match": match,
581 "name": name,
582 "oauth_scope": oauth_scope,
583 "target": target,
584 "applies_to_all_workspaces": applies_to_all_workspaces,
585 "attributes": attributes,
586 "description": description,
587 "token_lifetime_seconds": token_lifetime_seconds,
588 "workspace_id": workspace_id,
589 },
590 options=make_request_options(
591 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
592 ),
593 cast_to=BetaFederationRule,
594 )
595
596 async def retrieve(
597 self,
598 federation_rule_id: str,
599 *,
600 betas: List[AnthropicBetaParam] | Omit = omit,
601 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
602 # The extra values given here take precedence over values defined on the client or passed to this method.
603 extra_headers: Headers | None = None,
604 extra_query: Query | None = None,
605 extra_body: Body | None = None,
606 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
607 ) -> BetaFederationRule:
608 """
609 **Requires an OAuth access token with the `org:admin` scope**, from
610 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
611 API keys are not accepted. See
612 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
613
614 Retrieve a federation rule by its ID (`fdrl_...`).
615
616 Args:
617 federation_rule_id: ID of the federation rule.
618
619 betas: Optional header to specify the beta version(s) you want to use.
620
621 extra_headers: Send extra headers
622
623 extra_query: Add additional query parameters to the request
624
625 extra_body: Add additional JSON properties to the request
626
627 timeout: Override the client-level default timeout for this request, in seconds
628 """
629 if not federation_rule_id:
630 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
631 extra_headers = {
632 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
633 **(extra_headers or {}),
634 }
635 return await self._get(
636 path_template(
637 "/v1/organizations/federation_rules/{federation_rule_id}?beta=true",
638 federation_rule_id=federation_rule_id,
639 ),
640 options=make_request_options(
641 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
642 ),
643 cast_to=BetaFederationRule,
644 )
645
646 async def update(
647 self,
648 federation_rule_id: str,
649 *,
650 applies_to_all_workspaces: Optional[bool] | Omit = omit,
651 attributes: Optional[Dict[str, str]] | Omit = omit,
652 description: Optional[str] | Omit = omit,
653 match: Optional[BetaFederationRuleMatchParam] | Omit = omit,
654 name: Optional[str] | Omit = omit,
655 oauth_scope: Optional[str] | Omit = omit,
656 target: Optional[BetaServiceAccountTargetParam] | Omit = omit,
657 token_lifetime_seconds: Optional[int] | Omit = omit,
658 workspace_id: Optional[str] | Omit = omit,
659 betas: List[AnthropicBetaParam] | Omit = omit,
660 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
661 # The extra values given here take precedence over values defined on the client or passed to this method.
662 extra_headers: Headers | None = None,
663 extra_query: Query | None = None,
664 extra_body: Body | None = None,
665 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
666 ) -> BetaFederationRule:
667 """
668 **Requires an OAuth access token with the `org:admin` scope**, from
669 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
670 API keys are not accepted. See
671 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
672
673 Partially update a federation rule.
674
675 `issuer_id` is immutable. `match` and `target` are replaced as whole objects
676 when set. Referenced service accounts and workspaces must exist in your
677 organization; invalid references are rejected with a 400 error. Archived rules
678 cannot be updated; this returns 400. Create a new rule instead. Rules on
679 well-known shared issuers (GitHub Actions, GitLab, Buildkite, Terraform Cloud,
680 Google) must constrain tenant identity via an identity-bearing claim, a
681 tenant-pinning subject prefix (such as `repo:YOUR_ORG/...`), or a CEL condition
682 referencing one of those identity claims (e.g. `claims.repository_owner`). On
683 these issuers the requirement is re-checked on every update; if an existing
684 rule's stored match does not yet constrain tenant identity, any update (even a
685 rename or description change) must also supply a conforming `match` in the same
686 request. OAuth callers may only manage rules whose `oauth_scope` is
687 `workspace:developer` or `workspace:inference`; other scopes require a Console
688 session.
689
690 Args:
691 federation_rule_id: ID of the federation rule to update.
692
693 applies_to_all_workspaces: When true, enables this rule for every workspace in the org (including
694 workspaces created later). Setting `false` is rejected with 400 if no workspace
695 would remain enabled; a rule with only a legacy `workspace_id` binding continues
696 to mint.
697
698 attributes: Replaces the CEL expressions `{name: expr}` extracting named values from claims.
699 Send null to clear them. Not yet supported; any non-empty value is rejected
700 with 400.
701
702 description: Replaces the description. Omit to leave unchanged; send `null` to clear (the
703 field is stored as an empty string).
704
705 match: Does the incoming JWT qualify?
706
707 All populated fields must pass; omitted fields are skipped. At least one of
708 `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
709 `condition` is required; `audience` alone is not sufficient.
710
711 name: Replaces the slug identifier (lowercase, digits, hyphens). Unique within the
712 organization; a duplicate name returns 409.
713
714 oauth_scope: Replaces the space-separated OAuth scopes granted on minted tokens. OAuth
715 callers may only set `workspace:developer` or `workspace:inference`; other
716 scopes (such as `org:admin`) require a Console session.
717
718 target: Bind to a fixed service account by ID.
719
720 token_lifetime_seconds: Replaces the lifetime in seconds for access tokens minted via this rule
721 (60-86400). Minted tokens are capped at
722 `max(60, min(this value, 2 × remaining assertion validity))` seconds.
723
724 workspace_id: Replaces the existing single workspace enablement (the previous one is removed).
725 Rejected with 400 if the rule is enabled for more than one workspace; use the
726 `/federation_rules/{federation_rule_id}/workspaces` sub-resource instead.
727
728 betas: Optional header to specify the beta version(s) you want to use.
729
730 extra_headers: Send extra headers
731
732 extra_query: Add additional query parameters to the request
733
734 extra_body: Add additional JSON properties to the request
735
736 timeout: Override the client-level default timeout for this request, in seconds
737 """
738 if not federation_rule_id:
739 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
740 extra_headers = {
741 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
742 **(extra_headers or {}),
743 }
744 return await self._post(
745 path_template(
746 "/v1/organizations/federation_rules/{federation_rule_id}?beta=true",
747 federation_rule_id=federation_rule_id,
748 ),
749 body={
750 "applies_to_all_workspaces": applies_to_all_workspaces,
751 "attributes": attributes,
752 "description": description,
753 "match": match,
754 "name": name,
755 "oauth_scope": oauth_scope,
756 "target": target,
757 "token_lifetime_seconds": token_lifetime_seconds,
758 "workspace_id": workspace_id,
759 },
760 options=make_request_options(
761 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
762 ),
763 cast_to=BetaFederationRule,
764 )
765
766 def list(
767 self,
768 *,
769 include_archived: bool | Omit = omit,
770 issuer_id: Optional[str] | Omit = omit,
771 limit: int | Omit = omit,
772 page: Optional[str] | Omit = omit,
773 betas: List[AnthropicBetaParam] | Omit = omit,
774 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
775 # The extra values given here take precedence over values defined on the client or passed to this method.
776 extra_headers: Headers | None = None,
777 extra_query: Query | None = None,
778 extra_body: Body | None = None,
779 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
780 ) -> AsyncPaginator[BetaFederationRule, AsyncPageCursor[BetaFederationRule]]:
781 """
782 **Requires an OAuth access token with the `org:admin` scope**, from
783 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
784 API keys are not accepted. See
785 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
786
787 List federation rules in your organization.
788
789 Optionally filter by issuer with `issuer_id`. Archived rules are excluded unless
790 `include_archived=true`.
791
792 Args:
793 include_archived: Include archived resources. Defaults to false.
794
795 issuer_id: Filter to rules referencing this federation issuer.
796
797 limit: Number of results per page.
798
799 page: Opaque cursor from a previous response's `next_page`.
800
801 betas: Optional header to specify the beta version(s) you want to use.
802
803 extra_headers: Send extra headers
804
805 extra_query: Add additional query parameters to the request
806
807 extra_body: Add additional JSON properties to the request
808
809 timeout: Override the client-level default timeout for this request, in seconds
810 """
811 extra_headers = {
812 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
813 **(extra_headers or {}),
814 }
815 return self._get_api_list(
816 "/v1/organizations/federation_rules?beta=true",
817 page=AsyncPageCursor[BetaFederationRule],
818 options=make_request_options(
819 extra_headers=extra_headers,
820 extra_query=extra_query,
821 extra_body=extra_body,
822 timeout=timeout,
823 query={
824 "include_archived": include_archived,
825 "issuer_id": issuer_id,
826 "limit": limit,
827 "page": page,
828 },
829 ),
830 model=BetaFederationRule,
831 )
832
833 async def archive(
834 self,
835 federation_rule_id: str,
836 *,
837 betas: List[AnthropicBetaParam] | Omit = omit,
838 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
839 # The extra values given here take precedence over values defined on the client or passed to this method.
840 extra_headers: Headers | None = None,
841 extra_query: Query | None = None,
842 extra_body: Body | None = None,
843 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
844 ) -> BetaFederationRule:
845 """
846 **Requires an OAuth access token with the `org:admin` scope**, from
847 `ant auth login --scope org:admin` or a workload identity federation rule; Admin
848 API keys are not accepted. See
849 [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
850
851 Archive a federation rule.
852
853 Token exchange through this rule stops immediately. Idempotent; re-archiving
854 returns the rule with its original `archived_at`. Archiving clears the rule's
855 workspace targeting (`workspace_id` and `workspace_ids` are emptied). Tokens
856 already minted before archive remain valid until they expire. OAuth callers may
857 only manage rules whose `oauth_scope` is `workspace:developer` or
858 `workspace:inference`; other scopes require a Console session.
859
860 Args:
861 federation_rule_id: ID of the federation rule to archive.
862
863 betas: Optional header to specify the beta version(s) you want to use.
864
865 extra_headers: Send extra headers
866
867 extra_query: Add additional query parameters to the request
868
869 extra_body: Add additional JSON properties to the request
870
871 timeout: Override the client-level default timeout for this request, in seconds
872 """
873 if not federation_rule_id:
874 raise ValueError(f"Expected a non-empty value for `federation_rule_id` but received {federation_rule_id!r}")
875 extra_headers = {
876 **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
877 **(extra_headers or {}),
878 }
879 return await self._post(
880 path_template(
881 "/v1/organizations/federation_rules/{federation_rule_id}/archive?beta=true",
882 federation_rule_id=federation_rule_id,
883 ),
884 options=make_request_options(
885 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
886 ),
887 cast_to=BetaFederationRule,
888 )
889
890
891 class RulesWithRawResponse:
892 def __init__(self, rules: Rules) -> None:
893 self._rules = rules
894
895 self.create = to_raw_response_wrapper(
896 rules.create,
897 )
898 self.retrieve = to_raw_response_wrapper(
899 rules.retrieve,
900 )
901 self.update = to_raw_response_wrapper(
902 rules.update,
903 )
904 self.list = to_raw_response_wrapper(
905 rules.list,
906 )
907 self.archive = to_raw_response_wrapper(
908 rules.archive,
909 )
910
911 @cached_property
912 def workspaces(self) -> WorkspacesWithRawResponse:
913 return WorkspacesWithRawResponse(self._rules.workspaces)
914
915
916 class AsyncRulesWithRawResponse:
917 def __init__(self, rules: AsyncRules) -> None:
918 self._rules = rules
919
920 self.create = async_to_raw_response_wrapper(
921 rules.create,
922 )
923 self.retrieve = async_to_raw_response_wrapper(
924 rules.retrieve,
925 )
926 self.update = async_to_raw_response_wrapper(
927 rules.update,
928 )
929 self.list = async_to_raw_response_wrapper(
930 rules.list,
931 )
932 self.archive = async_to_raw_response_wrapper(
933 rules.archive,
934 )
935
936 @cached_property
937 def workspaces(self) -> AsyncWorkspacesWithRawResponse:
938 return AsyncWorkspacesWithRawResponse(self._rules.workspaces)
939
940
941 class RulesWithStreamingResponse:
942 def __init__(self, rules: Rules) -> None:
943 self._rules = rules
944
945 self.create = to_streamed_response_wrapper(
946 rules.create,
947 )
948 self.retrieve = to_streamed_response_wrapper(
949 rules.retrieve,
950 )
951 self.update = to_streamed_response_wrapper(
952 rules.update,
953 )
954 self.list = to_streamed_response_wrapper(
955 rules.list,
956 )
957 self.archive = to_streamed_response_wrapper(
958 rules.archive,
959 )
960
961 @cached_property
962 def workspaces(self) -> WorkspacesWithStreamingResponse:
963 return WorkspacesWithStreamingResponse(self._rules.workspaces)
964
965
966 class AsyncRulesWithStreamingResponse:
967 def __init__(self, rules: AsyncRules) -> None:
968 self._rules = rules
969
970 self.create = async_to_streamed_response_wrapper(
971 rules.create,
972 )
973 self.retrieve = async_to_streamed_response_wrapper(
974 rules.retrieve,
975 )
976 self.update = async_to_streamed_response_wrapper(
977 rules.update,
978 )
979 self.list = async_to_streamed_response_wrapper(
980 rules.list,
981 )
982 self.archive = async_to_streamed_response_wrapper(
983 rules.archive,
984 )
985
986 @cached_property
987 def workspaces(self) -> AsyncWorkspacesWithStreamingResponse:
988 return AsyncWorkspacesWithStreamingResponse(self._rules.workspaces)