github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationfederationruleworkspace.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 "errors" 8 "fmt" 9 "net/http" 10 "net/url" 11 "slices" 12 13 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 14 "github.com/anthropics/anthropic-sdk-go/internal/apiquery" 15 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 16 "github.com/anthropics/anthropic-sdk-go/option" 17 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 18 "github.com/anthropics/anthropic-sdk-go/packages/param" 19 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 20 "github.com/anthropics/anthropic-sdk-go/shared/constant" 21 ) 22 23 // BetaOrganizationFederationRuleWorkspaceService contains methods and other 24 // services that help with interacting with the anthropic API. 25 // 26 // Note, unlike clients, this service does not read variables from the environment 27 // automatically. You should not instantiate this service directly, and instead use 28 // the [NewBetaOrganizationFederationRuleWorkspaceService] method instead. 29 type BetaOrganizationFederationRuleWorkspaceService struct { 30 Options []option.RequestOption 31 } 32 33 // NewBetaOrganizationFederationRuleWorkspaceService generates a new service that 34 // applies the given options to each request. These options are applied after the 35 // parent client's options (if there is one), and before any request-specific 36 // options. 37 func NewBetaOrganizationFederationRuleWorkspaceService(opts ...option.RequestOption) (r BetaOrganizationFederationRuleWorkspaceService) { 38 r = BetaOrganizationFederationRuleWorkspaceService{} 39 r.Options = opts 40 return 41 } 42 43 // **Requires an OAuth access token with the `org:admin` scope**, from 44 // `ant auth login --scope org:admin` or a workload identity federation rule; Admin 45 // API keys are not accepted. See 46 // [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api). 47 // 48 // List workspaces where this federation rule is enabled. 49 // 50 // Returns all workspace enablements in a single response; the `limit` and `page` 51 // parameters are accepted but have no effect, and `next_page` is always `null`. 52 // Returns explicit per-workspace enablements only; for rules with 53 // `applies_to_all_workspaces` or a legacy single `workspace_id`, check those 54 // fields on the rule itself. 55 func (r *BetaOrganizationFederationRuleWorkspaceService) List(ctx context.Context, federationRuleID string, params BetaOrganizationFederationRuleWorkspaceListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaFederationRuleWorkspace], err error) { 56 var raw *http.Response 57 for _, v := range params.Betas { 58 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 59 } 60 opts = slices.Concat(r.Options, opts) 61 opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) 62 if federationRuleID == "" { 63 err = errors.New("missing required federation_rule_id parameter") 64 return nil, err 65 } 66 path := fmt.Sprintf("v1/organizations/federation_rules/%s/workspaces?beta=true", federationRuleID) 67 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 68 if err != nil { 69 return nil, err 70 } 71 err = cfg.Execute() 72 if err != nil { 73 return nil, err 74 } 75 res.SetPageConfig(cfg, raw) 76 return res, nil 77 } 78 79 // **Requires an OAuth access token with the `org:admin` scope**, from 80 // `ant auth login --scope org:admin` or a workload identity federation rule; Admin 81 // API keys are not accepted. See 82 // [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api). 83 // 84 // List workspaces where this federation rule is enabled. 85 // 86 // Returns all workspace enablements in a single response; the `limit` and `page` 87 // parameters are accepted but have no effect, and `next_page` is always `null`. 88 // Returns explicit per-workspace enablements only; for rules with 89 // `applies_to_all_workspaces` or a legacy single `workspace_id`, check those 90 // fields on the rule itself. 91 func (r *BetaOrganizationFederationRuleWorkspaceService) ListAutoPaging(ctx context.Context, federationRuleID string, params BetaOrganizationFederationRuleWorkspaceListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaFederationRuleWorkspace] { 92 return pagination.NewPageCursorAutoPager(r.List(ctx, federationRuleID, params, opts...)) 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 // Enable a federation rule for a workspace. 101 // 102 // Idempotent; re-enabling returns the existing enablement. The rule and workspace 103 // must both belong to your organization. Membership of the rule's target service 104 // account in this workspace is not checked at enablement: token exchange into this 105 // workspace is rejected unless the target is a member (it is implicitly a member 106 // of the default workspace). Archived rules are rejected with 400. OAuth callers 107 // may only manage rules whose `oauth_scope` is `workspace:developer` or 108 // `workspace:inference`; other scopes require a Console session. 109 func (r *BetaOrganizationFederationRuleWorkspaceService) Add(ctx context.Context, federationRuleID string, params BetaOrganizationFederationRuleWorkspaceAddParams, opts ...option.RequestOption) (res *BetaFederationRuleWorkspace, err error) { 110 for _, v := range params.Betas { 111 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 112 } 113 opts = slices.Concat(r.Options, opts) 114 if federationRuleID == "" { 115 err = errors.New("missing required federation_rule_id parameter") 116 return nil, err 117 } 118 path := fmt.Sprintf("v1/organizations/federation_rules/%s/workspaces?beta=true", federationRuleID) 119 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 120 return res, err 121 } 122 123 // **Requires an OAuth access token with the `org:admin` scope**, from 124 // `ant auth login --scope org:admin` or a workload identity federation rule; Admin 125 // API keys are not accepted. See 126 // [Manage WIF with the Admin API](/docs/en/manage-claude/wif-admin-api). 127 // 128 // Disable a federation rule for a workspace. 129 // 130 // Idempotent; succeeds even if the enablement was already removed. OAuth callers 131 // may only manage rules whose `oauth_scope` is `workspace:developer` or 132 // `workspace:inference`; other scopes require a Console session. 133 func (r *BetaOrganizationFederationRuleWorkspaceService) Remove(ctx context.Context, workspaceID string, params BetaOrganizationFederationRuleWorkspaceRemoveParams, opts ...option.RequestOption) (res *BetaOrganizationFederationRuleWorkspaceRemoveResponse, err error) { 134 for _, v := range params.Betas { 135 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 136 } 137 opts = slices.Concat(r.Options, opts) 138 if params.FederationRuleID == "" { 139 err = errors.New("missing required federation_rule_id parameter") 140 return nil, err 141 } 142 if workspaceID == "" { 143 err = errors.New("missing required workspace_id parameter") 144 return nil, err 145 } 146 path := fmt.Sprintf("v1/organizations/federation_rules/%s/workspaces/%s?beta=true", params.FederationRuleID, workspaceID) 147 err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) 148 return res, err 149 } 150 151 type BetaOrganizationFederationRuleWorkspaceRemoveResponse struct { 152 // Tagged ID of the federation rule. 153 FederationRuleID string `json:"federation_rule_id" api:"required"` 154 Type constant.FederationRuleWorkspaceDeleted `json:"type" default:"federation_rule_workspace_deleted"` 155 // Tagged ID of the workspace named in the delete request. Removal is idempotent. 156 WorkspaceID string `json:"workspace_id" api:"required"` 157 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 158 JSON struct { 159 FederationRuleID respjson.Field 160 Type respjson.Field 161 WorkspaceID respjson.Field 162 ExtraFields map[string]respjson.Field 163 raw string 164 } `json:"-"` 165 } 166 167 // Returns the unmodified JSON received from the API 168 func (r BetaOrganizationFederationRuleWorkspaceRemoveResponse) RawJSON() string { return r.JSON.raw } 169 func (r *BetaOrganizationFederationRuleWorkspaceRemoveResponse) UnmarshalJSON(data []byte) error { 170 return apijson.UnmarshalRoot(data, r) 171 } 172 173 type BetaOrganizationFederationRuleWorkspaceListParams struct { 174 // Opaque cursor from a previous response's `next_page`. 175 Page param.Opt[string] `query:"page,omitzero" json:"-"` 176 // Number of results per page. 177 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 178 // Optional header to specify the beta version(s) you want to use. 179 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 180 paramObj 181 } 182 183 // URLQuery serializes [BetaOrganizationFederationRuleWorkspaceListParams]'s query 184 // parameters as `url.Values`. 185 func (r BetaOrganizationFederationRuleWorkspaceListParams) URLQuery() (v url.Values, err error) { 186 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 187 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 188 NestedFormat: apiquery.NestedQueryFormatBrackets, 189 }) 190 } 191 192 type BetaOrganizationFederationRuleWorkspaceAddParams struct { 193 // Tagged ID of the workspace to enable this rule for. 194 WorkspaceID string `json:"workspace_id" api:"required"` 195 // Optional header to specify the beta version(s) you want to use. 196 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 197 paramObj 198 } 199 200 func (r BetaOrganizationFederationRuleWorkspaceAddParams) MarshalJSON() (data []byte, err error) { 201 type shadow BetaOrganizationFederationRuleWorkspaceAddParams 202 return param.MarshalObject(r, (*shadow)(&r)) 203 } 204 func (r *BetaOrganizationFederationRuleWorkspaceAddParams) UnmarshalJSON(data []byte) error { 205 return apijson.UnmarshalRoot(data, r) 206 } 207 208 type BetaOrganizationFederationRuleWorkspaceRemoveParams struct { 209 // ID of the federation rule. 210 FederationRuleID string `path:"federation_rule_id" api:"required" json:"-"` 211 // Optional header to specify the beta version(s) you want to use. 212 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 213 paramObj 214 }