github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationfederationrule.go (about)

     1  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
     2  
     3  package anthropic
     4  
     5  import (
     6  	"context"
     7  	"encoding/json"
     8  	"errors"
     9  	"fmt"
    10  	"net/http"
    11  	"net/url"
    12  	"slices"
    13  	"time"
    14  
    15  	"github.com/anthropics/anthropic-sdk-go/internal/apijson"
    16  	"github.com/anthropics/anthropic-sdk-go/internal/apiquery"
    17  	"github.com/anthropics/anthropic-sdk-go/internal/requestconfig"
    18  	"github.com/anthropics/anthropic-sdk-go/option"
    19  	"github.com/anthropics/anthropic-sdk-go/packages/pagination"
    20  	"github.com/anthropics/anthropic-sdk-go/packages/param"
    21  	"github.com/anthropics/anthropic-sdk-go/packages/respjson"
    22  	"github.com/anthropics/anthropic-sdk-go/shared/constant"
    23  )
    24  
    25  // BetaOrganizationFederationRuleService contains methods and other services that
    26  // help with interacting with the anthropic API.
    27  //
    28  // Note, unlike clients, this service does not read variables from the environment
    29  // automatically. You should not instantiate this service directly, and instead use
    30  // the [NewBetaOrganizationFederationRuleService] method instead.
    31  type BetaOrganizationFederationRuleService struct {
    32  	Options    []option.RequestOption
    33  	Workspaces BetaOrganizationFederationRuleWorkspaceService
    34  }
    35  
    36  // NewBetaOrganizationFederationRuleService generates a new service that applies
    37  // the given options to each request. These options are applied after the parent
    38  // client's options (if there is one), and before any request-specific options.
    39  func NewBetaOrganizationFederationRuleService(opts ...option.RequestOption) (r BetaOrganizationFederationRuleService) {
    40  	r = BetaOrganizationFederationRuleService{}
    41  	r.Options = opts
    42  	r.Workspaces = NewBetaOrganizationFederationRuleWorkspaceService(opts...)
    43  	return
    44  }
    45  
    46  // **Requires an OAuth access token with the `org:admin` scope**, from
    47  // `ant auth login --scope org:admin` or a workload identity federation rule; Admin
    48  // API keys are not accepted. See
    49  // [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
    50  //
    51  // Create a federation rule owned by your organization.
    52  //
    53  // The referenced issuer and the target service account must already exist in the
    54  // same organization; invalid references are rejected with a 400 error. The
    55  // workspace reference is validated. Membership is not checked at rule creation:
    56  // token exchange resolves a single enabled workspace per call and is rejected
    57  // unless the target service account is a member of that workspace (it is
    58  // implicitly a member of the default workspace). Rules on well-known shared
    59  // issuers (GitHub Actions, GitLab, Buildkite, Terraform Cloud, Google) must
    60  // constrain tenant identity via an identity-bearing claim, a tenant-pinning
    61  // subject prefix (such as `repo:YOUR_ORG/...`), or a CEL condition referencing one
    62  // of those identity claims (e.g. `claims.repository_owner`). OAuth callers may
    63  // only manage rules whose `oauth_scope` is `workspace:developer` or
    64  // `workspace:inference`; other scopes require a Console session.
    65  func (r *BetaOrganizationFederationRuleService) New(ctx context.Context, params BetaOrganizationFederationRuleNewParams, opts ...option.RequestOption) (res *BetaFederationRule, err error) {
    66  	for _, v := range params.Betas {
    67  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
    68  	}
    69  	opts = slices.Concat(r.Options, opts)
    70  	path := "v1/organizations/federation_rules?beta=true"
    71  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
    72  	return res, err
    73  }
    74  
    75  // **Requires an OAuth access token with the `org:admin` scope**, from
    76  // `ant auth login --scope org:admin` or a workload identity federation rule; Admin
    77  // API keys are not accepted. See
    78  // [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
    79  //
    80  // Retrieve a federation rule by its ID (`fdrl_...`).
    81  func (r *BetaOrganizationFederationRuleService) Get(ctx context.Context, federationRuleID string, query BetaOrganizationFederationRuleGetParams, opts ...option.RequestOption) (res *BetaFederationRule, err error) {
    82  	for _, v := range query.Betas {
    83  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
    84  	}
    85  	opts = slices.Concat(r.Options, opts)
    86  	if federationRuleID == "" {
    87  		err = errors.New("missing required federation_rule_id parameter")
    88  		return nil, err
    89  	}
    90  	path := fmt.Sprintf("v1/organizations/federation_rules/%s?beta=true", federationRuleID)
    91  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
    92  	return res, err
    93  }
    94  
    95  // **Requires an OAuth access token with the `org:admin` scope**, from
    96  // `ant auth login --scope org:admin` or a workload identity federation rule; Admin
    97  // API keys are not accepted. See
    98  // [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
    99  //
   100  // Partially update a federation rule.
   101  //
   102  // `issuer_id` is immutable. `match` and `target` are replaced as whole objects
   103  // when set. Referenced service accounts and workspaces must exist in your
   104  // organization; invalid references are rejected with a 400 error. Archived rules
   105  // cannot be updated; this returns 400. Create a new rule instead. Rules on
   106  // well-known shared issuers (GitHub Actions, GitLab, Buildkite, Terraform Cloud,
   107  // Google) must constrain tenant identity via an identity-bearing claim, a
   108  // tenant-pinning subject prefix (such as `repo:YOUR_ORG/...`), or a CEL condition
   109  // referencing one of those identity claims (e.g. `claims.repository_owner`). On
   110  // these issuers the requirement is re-checked on every update; if an existing
   111  // rule's stored match does not yet constrain tenant identity, any update (even a
   112  // rename or description change) must also supply a conforming `match` in the same
   113  // request. OAuth callers may only manage rules whose `oauth_scope` is
   114  // `workspace:developer` or `workspace:inference`; other scopes require a Console
   115  // session.
   116  func (r *BetaOrganizationFederationRuleService) Update(ctx context.Context, federationRuleID string, params BetaOrganizationFederationRuleUpdateParams, opts ...option.RequestOption) (res *BetaFederationRule, err error) {
   117  	for _, v := range params.Betas {
   118  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
   119  	}
   120  	opts = slices.Concat(r.Options, opts)
   121  	if federationRuleID == "" {
   122  		err = errors.New("missing required federation_rule_id parameter")
   123  		return nil, err
   124  	}
   125  	path := fmt.Sprintf("v1/organizations/federation_rules/%s?beta=true", federationRuleID)
   126  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
   127  	return res, err
   128  }
   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  // List federation rules in your organization.
   136  //
   137  // Optionally filter by issuer with `issuer_id`. Archived rules are excluded unless
   138  // `include_archived=true`.
   139  func (r *BetaOrganizationFederationRuleService) List(ctx context.Context, params BetaOrganizationFederationRuleListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaFederationRule], err error) {
   140  	var raw *http.Response
   141  	for _, v := range params.Betas {
   142  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
   143  	}
   144  	opts = slices.Concat(r.Options, opts)
   145  	opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
   146  	path := "v1/organizations/federation_rules?beta=true"
   147  	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
   148  	if err != nil {
   149  		return nil, err
   150  	}
   151  	err = cfg.Execute()
   152  	if err != nil {
   153  		return nil, err
   154  	}
   155  	res.SetPageConfig(cfg, raw)
   156  	return res, nil
   157  }
   158  
   159  // **Requires an OAuth access token with the `org:admin` scope**, from
   160  // `ant auth login --scope org:admin` or a workload identity federation rule; Admin
   161  // API keys are not accepted. See
   162  // [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
   163  //
   164  // List federation rules in your organization.
   165  //
   166  // Optionally filter by issuer with `issuer_id`. Archived rules are excluded unless
   167  // `include_archived=true`.
   168  func (r *BetaOrganizationFederationRuleService) ListAutoPaging(ctx context.Context, params BetaOrganizationFederationRuleListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaFederationRule] {
   169  	return pagination.NewPageCursorAutoPager(r.List(ctx, params, opts...))
   170  }
   171  
   172  // **Requires an OAuth access token with the `org:admin` scope**, from
   173  // `ant auth login --scope org:admin` or a workload identity federation rule; Admin
   174  // API keys are not accepted. See
   175  // [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api).
   176  //
   177  // Archive a federation rule.
   178  //
   179  // Token exchange through this rule stops immediately. Idempotent; re-archiving
   180  // returns the rule with its original `archived_at`. Archiving clears the rule's
   181  // workspace targeting (`workspace_id` and `workspace_ids` are emptied). Tokens
   182  // already minted before archive remain valid until they expire. OAuth callers may
   183  // only manage rules whose `oauth_scope` is `workspace:developer` or
   184  // `workspace:inference`; other scopes require a Console session.
   185  func (r *BetaOrganizationFederationRuleService) Archive(ctx context.Context, federationRuleID string, body BetaOrganizationFederationRuleArchiveParams, opts ...option.RequestOption) (res *BetaFederationRule, err error) {
   186  	for _, v := range body.Betas {
   187  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
   188  	}
   189  	opts = slices.Concat(r.Options, opts)
   190  	if federationRuleID == "" {
   191  		err = errors.New("missing required federation_rule_id parameter")
   192  		return nil, err
   193  	}
   194  	path := fmt.Sprintf("v1/organizations/federation_rules/%s/archive?beta=true", federationRuleID)
   195  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
   196  	return res, err
   197  }
   198  
   199  // Authorization rule binding an external OIDC identity to Anthropic.
   200  //
   201  // Evaluates the match conditions and mints an OAuth access token for the resolved
   202  // target, scoped to a single workspace where the rule is enabled (chosen by the
   203  // caller at exchange time when the rule is enabled for more than one). For rules
   204  // enabled via `workspace_ids` or `applies_to_all_workspaces`, the target service
   205  // account must be a member of that workspace (it is implicitly a member of the
   206  // default workspace); rules carrying only the legacy `workspace_id` binding do not
   207  // enforce this.
   208  type BetaFederationRule struct {
   209  	// Tagged ID of the federation rule.
   210  	ID string `json:"id" api:"required"`
   211  	// When true, this rule is enabled for every workspace in the org (including ones
   212  	// created after the rule). `workspace_ids` is ignored at exchange time.
   213  	AppliesToAllWorkspaces bool `json:"applies_to_all_workspaces" api:"required"`
   214  	// If set, this rule is archived and rejects token exchange.
   215  	ArchivedAt time.Time `json:"archived_at" api:"required" format:"date-time"`
   216  	// Tagged ID (`user_`/`svac_`) of the actor that archived this rule.
   217  	ArchivedByActorID string `json:"archived_by_actor_id" api:"required"`
   218  	// CEL expressions extracting named values from claims. Not yet supported; always
   219  	// null.
   220  	Attributes map[string]string `json:"attributes" api:"required"`
   221  	// When this rule was created.
   222  	CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
   223  	// Tagged ID (`user_`/`svac_`) of the actor that created this rule.
   224  	CreatedByActorID string `json:"created_by_actor_id" api:"required"`
   225  	// Optional free-text description.
   226  	Description string `json:"description" api:"required"`
   227  	// Tagged ID of the issuer whose tokens this rule accepts.
   228  	IssuerID string `json:"issuer_id" api:"required"`
   229  	// Issuer's display name at read time.
   230  	IssuerName string `json:"issuer_name" api:"required"`
   231  	// Conditions the verified JWT must satisfy for this rule to apply. All populated
   232  	// matcher fields must pass.
   233  	Match BetaFederationRuleMatch `json:"match" api:"required"`
   234  	// Admin-chosen slug identifier.
   235  	Name string `json:"name" api:"required"`
   236  	// Space-separated OAuth scopes granted on the minted token.
   237  	OAuthScope string `json:"oauth_scope" api:"required"`
   238  	// Identity that tokens minted via this rule act as. Currently always a
   239  	// `service_account` target.
   240  	Target BetaServiceAccountTarget `json:"target" api:"required"`
   241  	// Lifetime in seconds of access tokens minted via this rule. Minted tokens are
   242  	// capped at `max(60, min(this value, 2 × remaining assertion validity))` seconds.
   243  	TokenLifetimeSeconds int64                   `json:"token_lifetime_seconds" api:"required"`
   244  	Type                 constant.FederationRule `json:"type" default:"federation_rule"`
   245  	// When this rule was last updated.
   246  	UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"`
   247  	// Tagged ID (`user_`/`svac_`) of the actor that last updated this rule.
   248  	UpdatedByActorID string `json:"updated_by_actor_id" api:"required"`
   249  	// Legacy single-workspace binding. Prefer `workspace_ids` and the
   250  	// `/federation_rules/{federation_rule_id}/workspaces` sub-resource for managing
   251  	// workspace enablement.
   252  	WorkspaceID string `json:"workspace_id" api:"required"`
   253  	// Tagged IDs of the workspaces this rule is enabled for. May be empty for older
   254  	// rules that only carry the legacy `workspace_id` binding. Ignored at exchange
   255  	// time when `applies_to_all_workspaces` is true (the list may still be non-empty).
   256  	WorkspaceIDs []string `json:"workspace_ids" api:"required"`
   257  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   258  	JSON struct {
   259  		ID                     respjson.Field
   260  		AppliesToAllWorkspaces respjson.Field
   261  		ArchivedAt             respjson.Field
   262  		ArchivedByActorID      respjson.Field
   263  		Attributes             respjson.Field
   264  		CreatedAt              respjson.Field
   265  		CreatedByActorID       respjson.Field
   266  		Description            respjson.Field
   267  		IssuerID               respjson.Field
   268  		IssuerName             respjson.Field
   269  		Match                  respjson.Field
   270  		Name                   respjson.Field
   271  		OAuthScope             respjson.Field
   272  		Target                 respjson.Field
   273  		TokenLifetimeSeconds   respjson.Field
   274  		Type                   respjson.Field
   275  		UpdatedAt              respjson.Field
   276  		UpdatedByActorID       respjson.Field
   277  		WorkspaceID            respjson.Field
   278  		WorkspaceIDs           respjson.Field
   279  		ExtraFields            map[string]respjson.Field
   280  		raw                    string
   281  	} `json:"-"`
   282  }
   283  
   284  // Returns the unmodified JSON received from the API
   285  func (r BetaFederationRule) RawJSON() string { return r.JSON.raw }
   286  func (r *BetaFederationRule) UnmarshalJSON(data []byte) error {
   287  	return apijson.UnmarshalRoot(data, r)
   288  }
   289  
   290  // Does the incoming JWT qualify?
   291  //
   292  // All populated fields must pass; omitted fields are skipped. At least one of
   293  // `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
   294  // `condition` is required; `audience` alone is not sufficient.
   295  type BetaFederationRuleMatch struct {
   296  	// Exact match against the `aud` claim (any element if array). When omitted, the
   297  	// JWT's `aud` must still equal Anthropic's expected audience for the issuer;
   298  	// setting this field overrides that default.
   299  	Audience string `json:"audience" api:"nullable"`
   300  	// Exact-match `{claim: value}` pairs against top-level claims. Only string-valued
   301  	// claims can be matched; use `condition` for non-string claims.
   302  	Claims map[string]string `json:"claims" api:"nullable"`
   303  	// CEL expression over claims for logic the structural fields can't express. Must
   304  	// evaluate to a boolean and may reference only the `claims` variable; a
   305  	// constant-true expression (such as `true`) is rejected with 400.
   306  	Condition string `json:"condition" api:"nullable"`
   307  	// Match the verified JWT `sub` claim. Exact match unless the value ends with `*`,
   308  	// in which case it is a prefix match. Example:
   309  	// `repo:my-org/my-repo:ref:refs/heads/main`.
   310  	SubjectPrefix string `json:"subject_prefix" api:"nullable"`
   311  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   312  	JSON struct {
   313  		Audience      respjson.Field
   314  		Claims        respjson.Field
   315  		Condition     respjson.Field
   316  		SubjectPrefix respjson.Field
   317  		ExtraFields   map[string]respjson.Field
   318  		raw           string
   319  	} `json:"-"`
   320  }
   321  
   322  // Returns the unmodified JSON received from the API
   323  func (r BetaFederationRuleMatch) RawJSON() string { return r.JSON.raw }
   324  func (r *BetaFederationRuleMatch) UnmarshalJSON(data []byte) error {
   325  	return apijson.UnmarshalRoot(data, r)
   326  }
   327  
   328  // ToParam converts this BetaFederationRuleMatch to a BetaFederationRuleMatchParam.
   329  //
   330  // Warning: the fields of the param type will not be present. ToParam should only
   331  // be used at the last possible moment before sending a request. Test for this with
   332  // BetaFederationRuleMatchParam.Overrides()
   333  func (r BetaFederationRuleMatch) ToParam() BetaFederationRuleMatchParam {
   334  	return param.Override[BetaFederationRuleMatchParam](json.RawMessage(r.RawJSON()))
   335  }
   336  
   337  // Does the incoming JWT qualify?
   338  //
   339  // All populated fields must pass; omitted fields are skipped. At least one of
   340  // `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
   341  // `condition` is required; `audience` alone is not sufficient.
   342  type BetaFederationRuleMatchParam struct {
   343  	// Exact match against the `aud` claim (any element if array). When omitted, the
   344  	// JWT's `aud` must still equal Anthropic's expected audience for the issuer;
   345  	// setting this field overrides that default.
   346  	Audience param.Opt[string] `json:"audience,omitzero"`
   347  	// CEL expression over claims for logic the structural fields can't express. Must
   348  	// evaluate to a boolean and may reference only the `claims` variable; a
   349  	// constant-true expression (such as `true`) is rejected with 400.
   350  	Condition param.Opt[string] `json:"condition,omitzero"`
   351  	// Match the verified JWT `sub` claim. Exact match unless the value ends with `*`,
   352  	// in which case it is a prefix match. Example:
   353  	// `repo:my-org/my-repo:ref:refs/heads/main`.
   354  	SubjectPrefix param.Opt[string] `json:"subject_prefix,omitzero"`
   355  	// Exact-match `{claim: value}` pairs against top-level claims. Only string-valued
   356  	// claims can be matched; use `condition` for non-string claims.
   357  	Claims map[string]string `json:"claims,omitzero"`
   358  	paramObj
   359  }
   360  
   361  func (r BetaFederationRuleMatchParam) MarshalJSON() (data []byte, err error) {
   362  	type shadow BetaFederationRuleMatchParam
   363  	return param.MarshalObject(r, (*shadow)(&r))
   364  }
   365  func (r *BetaFederationRuleMatchParam) UnmarshalJSON(data []byte) error {
   366  	return apijson.UnmarshalRoot(data, r)
   367  }
   368  
   369  type BetaFederationRuleWorkspace struct {
   370  	// When this workspace was enabled for the rule.
   371  	CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
   372  	// Tagged ID (`user_...` or `svac_...`) of the actor that enabled this workspace
   373  	// for the rule, if known.
   374  	CreatedByActorID string `json:"created_by_actor_id" api:"required"`
   375  	// Tagged ID of the federation rule.
   376  	FederationRuleID string                           `json:"federation_rule_id" api:"required"`
   377  	Type             constant.FederationRuleWorkspace `json:"type" default:"federation_rule_workspace"`
   378  	// Tagged ID of the workspace this rule is enabled for.
   379  	WorkspaceID string `json:"workspace_id" api:"required"`
   380  	// Workspace display name. Populated when listing; null in the enable response.
   381  	WorkspaceName string `json:"workspace_name" api:"required"`
   382  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   383  	JSON struct {
   384  		CreatedAt        respjson.Field
   385  		CreatedByActorID respjson.Field
   386  		FederationRuleID respjson.Field
   387  		Type             respjson.Field
   388  		WorkspaceID      respjson.Field
   389  		WorkspaceName    respjson.Field
   390  		ExtraFields      map[string]respjson.Field
   391  		raw              string
   392  	} `json:"-"`
   393  }
   394  
   395  // Returns the unmodified JSON received from the API
   396  func (r BetaFederationRuleWorkspace) RawJSON() string { return r.JSON.raw }
   397  func (r *BetaFederationRuleWorkspace) UnmarshalJSON(data []byte) error {
   398  	return apijson.UnmarshalRoot(data, r)
   399  }
   400  
   401  // Bind to a fixed service account by ID.
   402  type BetaServiceAccountTarget struct {
   403  	// Tagged ID of the service account to mint tokens for.
   404  	ServiceAccountID string                  `json:"service_account_id" api:"required"`
   405  	Type             constant.ServiceAccount `json:"type" default:"service_account"`
   406  	// Service account's display name at read time. Ignored on writes.
   407  	ServiceAccountName string `json:"service_account_name" api:"nullable"`
   408  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   409  	JSON struct {
   410  		ServiceAccountID   respjson.Field
   411  		Type               respjson.Field
   412  		ServiceAccountName respjson.Field
   413  		ExtraFields        map[string]respjson.Field
   414  		raw                string
   415  	} `json:"-"`
   416  }
   417  
   418  // Returns the unmodified JSON received from the API
   419  func (r BetaServiceAccountTarget) RawJSON() string { return r.JSON.raw }
   420  func (r *BetaServiceAccountTarget) UnmarshalJSON(data []byte) error {
   421  	return apijson.UnmarshalRoot(data, r)
   422  }
   423  
   424  // ToParam converts this BetaServiceAccountTarget to a
   425  // BetaServiceAccountTargetParam.
   426  //
   427  // Warning: the fields of the param type will not be present. ToParam should only
   428  // be used at the last possible moment before sending a request. Test for this with
   429  // BetaServiceAccountTargetParam.Overrides()
   430  func (r BetaServiceAccountTarget) ToParam() BetaServiceAccountTargetParam {
   431  	return param.Override[BetaServiceAccountTargetParam](json.RawMessage(r.RawJSON()))
   432  }
   433  
   434  // Bind to a fixed service account by ID.
   435  //
   436  // The properties ServiceAccountID, Type are required.
   437  type BetaServiceAccountTargetParam struct {
   438  	// Tagged ID of the service account to mint tokens for.
   439  	ServiceAccountID string `json:"service_account_id" api:"required"`
   440  	// Service account's display name at read time. Ignored on writes.
   441  	ServiceAccountName param.Opt[string] `json:"service_account_name,omitzero"`
   442  	// This field can be elided, and will marshal its zero value as "service_account".
   443  	Type constant.ServiceAccount `json:"type" default:"service_account"`
   444  	paramObj
   445  }
   446  
   447  func (r BetaServiceAccountTargetParam) MarshalJSON() (data []byte, err error) {
   448  	type shadow BetaServiceAccountTargetParam
   449  	return param.MarshalObject(r, (*shadow)(&r))
   450  }
   451  func (r *BetaServiceAccountTargetParam) UnmarshalJSON(data []byte) error {
   452  	return apijson.UnmarshalRoot(data, r)
   453  }
   454  
   455  type BetaOrganizationFederationRuleNewParams struct {
   456  	// Tagged ID of the federation issuer.
   457  	IssuerID string `json:"issuer_id" api:"required"`
   458  	// Conditions the verified JWT must satisfy for this rule to apply. At least one of
   459  	// `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
   460  	// `condition` is required; `audience` alone is not sufficient.
   461  	Match BetaFederationRuleMatchParam `json:"match,omitzero" api:"required"`
   462  	// Slug identifier (lowercase, digits, hyphens). Unique within the organization; a
   463  	// duplicate name returns 409.
   464  	Name string `json:"name" api:"required"`
   465  	// Space-separated OAuth scopes. OAuth callers may only set `workspace:developer`
   466  	// or `workspace:inference`; other scopes (such as `org:admin`) require a Console
   467  	// session.
   468  	OAuthScope string `json:"oauth_scope" api:"required"`
   469  	// Identity that tokens minted via this rule act as. Currently always a
   470  	// `service_account` target.
   471  	Target BetaServiceAccountTargetParam `json:"target,omitzero" api:"required"`
   472  	// Optional free-text description.
   473  	Description param.Opt[string] `json:"description,omitzero"`
   474  	// Tagged ID of the workspace to enable this rule for. Required unless
   475  	// `applies_to_all_workspaces` is true. Additional workspaces can be added via the
   476  	// `/federation_rules/{federation_rule_id}/workspaces` sub-resource.
   477  	WorkspaceID param.Opt[string] `json:"workspace_id,omitzero"`
   478  	// When true, enable this rule for every workspace in the org (including workspaces
   479  	// created later).
   480  	AppliesToAllWorkspaces param.Opt[bool] `json:"applies_to_all_workspaces,omitzero"`
   481  	// Lifetime in seconds for access tokens minted via this rule (60-86400). Defaults
   482  	// to 3600 (1h). Minted tokens are capped at
   483  	// `max(60, min(this value, 2 × remaining assertion validity))` seconds.
   484  	TokenLifetimeSeconds param.Opt[int64] `json:"token_lifetime_seconds,omitzero"`
   485  	// CEL expressions `{name: expr}` extracting named values from claims. Not yet
   486  	// supported; any non-empty value is rejected with 400.
   487  	Attributes map[string]string `json:"attributes,omitzero"`
   488  	// Optional header to specify the beta version(s) you want to use.
   489  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   490  	paramObj
   491  }
   492  
   493  func (r BetaOrganizationFederationRuleNewParams) MarshalJSON() (data []byte, err error) {
   494  	type shadow BetaOrganizationFederationRuleNewParams
   495  	return param.MarshalObject(r, (*shadow)(&r))
   496  }
   497  func (r *BetaOrganizationFederationRuleNewParams) UnmarshalJSON(data []byte) error {
   498  	return apijson.UnmarshalRoot(data, r)
   499  }
   500  
   501  type BetaOrganizationFederationRuleGetParams struct {
   502  	// Optional header to specify the beta version(s) you want to use.
   503  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   504  	paramObj
   505  }
   506  
   507  type BetaOrganizationFederationRuleUpdateParams struct {
   508  	// When true, enables this rule for every workspace in the org (including
   509  	// workspaces created later). Setting `false` is rejected with 400 if no workspace
   510  	// would remain enabled; a rule with only a legacy `workspace_id` binding continues
   511  	// to mint.
   512  	AppliesToAllWorkspaces param.Opt[bool] `json:"applies_to_all_workspaces,omitzero"`
   513  	// Replaces the description. Omit to leave unchanged; send `null` to clear (the
   514  	// field is stored as an empty string).
   515  	Description param.Opt[string] `json:"description,omitzero"`
   516  	// Replaces the slug identifier (lowercase, digits, hyphens). Unique within the
   517  	// organization; a duplicate name returns 409.
   518  	Name param.Opt[string] `json:"name,omitzero"`
   519  	// Replaces the space-separated OAuth scopes granted on minted tokens. OAuth
   520  	// callers may only set `workspace:developer` or `workspace:inference`; other
   521  	// scopes (such as `org:admin`) require a Console session.
   522  	OAuthScope param.Opt[string] `json:"oauth_scope,omitzero"`
   523  	// Replaces the lifetime in seconds for access tokens minted via this rule
   524  	// (60-86400). Minted tokens are capped at
   525  	// `max(60, min(this value, 2 × remaining assertion validity))` seconds.
   526  	TokenLifetimeSeconds param.Opt[int64] `json:"token_lifetime_seconds,omitzero"`
   527  	// Replaces the existing single workspace enablement (the previous one is removed).
   528  	// Rejected with 400 if the rule is enabled for more than one workspace; use the
   529  	// `/federation_rules/{federation_rule_id}/workspaces` sub-resource instead.
   530  	WorkspaceID param.Opt[string] `json:"workspace_id,omitzero"`
   531  	// Replaces the CEL expressions `{name: expr}` extracting named values from claims.
   532  	// Send null to clear them. Not yet supported; any non-empty value is rejected
   533  	// with 400.
   534  	Attributes map[string]string `json:"attributes,omitzero"`
   535  	// Does the incoming JWT qualify?
   536  	//
   537  	// All populated fields must pass; omitted fields are skipped. At least one of
   538  	// `subject_prefix` (other than a wildcard-only value like `*`), `claims`, or
   539  	// `condition` is required; `audience` alone is not sufficient.
   540  	Match BetaFederationRuleMatchParam `json:"match,omitzero"`
   541  	// Bind to a fixed service account by ID.
   542  	Target BetaServiceAccountTargetParam `json:"target,omitzero"`
   543  	// Optional header to specify the beta version(s) you want to use.
   544  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   545  	paramObj
   546  }
   547  
   548  func (r BetaOrganizationFederationRuleUpdateParams) MarshalJSON() (data []byte, err error) {
   549  	type shadow BetaOrganizationFederationRuleUpdateParams
   550  	return param.MarshalObject(r, (*shadow)(&r))
   551  }
   552  func (r *BetaOrganizationFederationRuleUpdateParams) UnmarshalJSON(data []byte) error {
   553  	return apijson.UnmarshalRoot(data, r)
   554  }
   555  
   556  type BetaOrganizationFederationRuleListParams struct {
   557  	// Filter to rules referencing this federation issuer.
   558  	IssuerID param.Opt[string] `query:"issuer_id,omitzero" json:"-"`
   559  	// Opaque cursor from a previous response's `next_page`.
   560  	Page param.Opt[string] `query:"page,omitzero" json:"-"`
   561  	// Include archived resources. Defaults to false.
   562  	IncludeArchived param.Opt[bool] `query:"include_archived,omitzero" json:"-"`
   563  	// Number of results per page.
   564  	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
   565  	// Optional header to specify the beta version(s) you want to use.
   566  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   567  	paramObj
   568  }
   569  
   570  // URLQuery serializes [BetaOrganizationFederationRuleListParams]'s query
   571  // parameters as `url.Values`.
   572  func (r BetaOrganizationFederationRuleListParams) URLQuery() (v url.Values, err error) {
   573  	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
   574  		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
   575  		NestedFormat: apiquery.NestedQueryFormatBrackets,
   576  	})
   577  }
   578  
   579  type BetaOrganizationFederationRuleArchiveParams struct {
   580  	// Optional header to specify the beta version(s) you want to use.
   581  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   582  	paramObj
   583  }