github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationexternalkey.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  // BetaOrganizationExternalKeyService contains methods and other services that help
    26  // 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 [NewBetaOrganizationExternalKeyService] method instead.
    31  type BetaOrganizationExternalKeyService struct {
    32  	Options []option.RequestOption
    33  }
    34  
    35  // NewBetaOrganizationExternalKeyService generates a new service that applies the
    36  // given options to each request. These options are applied after the parent
    37  // client's options (if there is one), and before any request-specific options.
    38  func NewBetaOrganizationExternalKeyService(opts ...option.RequestOption) (r BetaOrganizationExternalKeyService) {
    39  	r = BetaOrganizationExternalKeyService{}
    40  	r.Options = opts
    41  	return
    42  }
    43  
    44  // Create an external key config owned by the caller's organization.
    45  func (r *BetaOrganizationExternalKeyService) New(ctx context.Context, body BetaOrganizationExternalKeyNewParams, opts ...option.RequestOption) (res *BetaExternalKey, err error) {
    46  	opts = slices.Concat(r.Options, opts)
    47  	path := "v1/organizations/external_keys?beta=true"
    48  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
    49  	return res, err
    50  }
    51  
    52  // Retrieve a single external key config in the caller's organization by ID.
    53  func (r *BetaOrganizationExternalKeyService) Get(ctx context.Context, externalKeyID string, opts ...option.RequestOption) (res *BetaExternalKey, err error) {
    54  	opts = slices.Concat(r.Options, opts)
    55  	if externalKeyID == "" {
    56  		err = errors.New("missing required external_key_id parameter")
    57  		return nil, err
    58  	}
    59  	path := fmt.Sprintf("v1/organizations/external_keys/%s?beta=true", externalKeyID)
    60  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
    61  	return res, err
    62  }
    63  
    64  // Partially update an external key config. Omitted fields are left unchanged.
    65  //
    66  // `display_name` is always editable. `geo` and `provider_config` cannot be changed
    67  // once any workspace references this config, because previously encrypted data
    68  // requires the original key identity to decrypt.
    69  func (r *BetaOrganizationExternalKeyService) Update(ctx context.Context, externalKeyID string, body BetaOrganizationExternalKeyUpdateParams, opts ...option.RequestOption) (res *BetaExternalKey, err error) {
    70  	opts = slices.Concat(r.Options, opts)
    71  	if externalKeyID == "" {
    72  		err = errors.New("missing required external_key_id parameter")
    73  		return nil, err
    74  	}
    75  	path := fmt.Sprintf("v1/organizations/external_keys/%s?beta=true", externalKeyID)
    76  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
    77  	return res, err
    78  }
    79  
    80  // List external key configs in the caller's organization.
    81  //
    82  // Results are ordered by creation time (newest first). Use the `next_page` cursor
    83  // from the response to fetch subsequent pages.
    84  func (r *BetaOrganizationExternalKeyService) List(ctx context.Context, query BetaOrganizationExternalKeyListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaExternalKey], err error) {
    85  	var raw *http.Response
    86  	opts = slices.Concat(r.Options, opts)
    87  	opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
    88  	path := "v1/organizations/external_keys?beta=true"
    89  	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
    90  	if err != nil {
    91  		return nil, err
    92  	}
    93  	err = cfg.Execute()
    94  	if err != nil {
    95  		return nil, err
    96  	}
    97  	res.SetPageConfig(cfg, raw)
    98  	return res, nil
    99  }
   100  
   101  // List external key configs in the caller's organization.
   102  //
   103  // Results are ordered by creation time (newest first). Use the `next_page` cursor
   104  // from the response to fetch subsequent pages.
   105  func (r *BetaOrganizationExternalKeyService) ListAutoPaging(ctx context.Context, query BetaOrganizationExternalKeyListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaExternalKey] {
   106  	return pagination.NewPageCursorAutoPager(r.List(ctx, query, opts...))
   107  }
   108  
   109  // Delete an external key config.
   110  //
   111  // The request is rejected if any workspace still references this config.
   112  func (r *BetaOrganizationExternalKeyService) Delete(ctx context.Context, externalKeyID string, opts ...option.RequestOption) (res *BetaOrganizationExternalKeyDeleteResponse, err error) {
   113  	opts = slices.Concat(r.Options, opts)
   114  	if externalKeyID == "" {
   115  		err = errors.New("missing required external_key_id parameter")
   116  		return nil, err
   117  	}
   118  	path := fmt.Sprintf("v1/organizations/external_keys/%s?beta=true", externalKeyID)
   119  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
   120  	return res, err
   121  }
   122  
   123  // Validate an external key config against the customer's KMS.
   124  //
   125  // Anthropic performs an encrypt/decrypt roundtrip against the configured KMS key
   126  // and waits up to 30 seconds for the result. The response status is `success` if
   127  // the roundtrip succeeded, or `failure` with an error message if it failed or
   128  // timed out.
   129  func (r *BetaOrganizationExternalKeyService) Validate(ctx context.Context, externalKeyID string, opts ...option.RequestOption) (res *BetaOrganizationExternalKeyValidateResponse, err error) {
   130  	opts = slices.Concat(r.Options, opts)
   131  	if externalKeyID == "" {
   132  		err = errors.New("missing required external_key_id parameter")
   133  		return nil, err
   134  	}
   135  	path := fmt.Sprintf("v1/organizations/external_keys/%s/validate?beta=true", externalKeyID)
   136  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
   137  	return res, err
   138  }
   139  
   140  type BetaAWSExternalKeyConfig struct {
   141  	// Full ARN of the AWS KMS key. On Claude Platform on AWS the key must be a
   142  	// single-Region key in your organization's own AWS account; cross-account keys,
   143  	// multi-Region keys, and alias ARNs are rejected.
   144  	KMSARN string       `json:"kms_arn" api:"required"`
   145  	Type   constant.AWS `json:"type" default:"aws"`
   146  	// AWS region. Derived from `kms_arn` if omitted.
   147  	Region string `json:"region" api:"nullable"`
   148  	// IAM role ARN. Deprecated — Anthropic reaches the KMS key through its own
   149  	// intermediate role (or, on Claude Platform on AWS, with credentials AWS issues
   150  	// for the Workspace); this field is ignored.
   151  	//
   152  	// Deprecated: deprecated
   153  	RoleARN string `json:"role_arn" api:"nullable"`
   154  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   155  	JSON struct {
   156  		KMSARN      respjson.Field
   157  		Type        respjson.Field
   158  		Region      respjson.Field
   159  		RoleARN     respjson.Field
   160  		ExtraFields map[string]respjson.Field
   161  		raw         string
   162  	} `json:"-"`
   163  }
   164  
   165  // Returns the unmodified JSON received from the API
   166  func (r BetaAWSExternalKeyConfig) RawJSON() string { return r.JSON.raw }
   167  func (r *BetaAWSExternalKeyConfig) UnmarshalJSON(data []byte) error {
   168  	return apijson.UnmarshalRoot(data, r)
   169  }
   170  
   171  // ToParam converts this BetaAWSExternalKeyConfig to a
   172  // BetaAWSExternalKeyConfigParam.
   173  //
   174  // Warning: the fields of the param type will not be present. ToParam should only
   175  // be used at the last possible moment before sending a request. Test for this with
   176  // BetaAWSExternalKeyConfigParam.Overrides()
   177  func (r BetaAWSExternalKeyConfig) ToParam() BetaAWSExternalKeyConfigParam {
   178  	return param.Override[BetaAWSExternalKeyConfigParam](json.RawMessage(r.RawJSON()))
   179  }
   180  
   181  // The properties KMSARN, Type are required.
   182  type BetaAWSExternalKeyConfigParam struct {
   183  	// Full ARN of the AWS KMS key. On Claude Platform on AWS the key must be a
   184  	// single-Region key in your organization's own AWS account; cross-account keys,
   185  	// multi-Region keys, and alias ARNs are rejected.
   186  	KMSARN string `json:"kms_arn" api:"required"`
   187  	// AWS region. Derived from `kms_arn` if omitted.
   188  	Region param.Opt[string] `json:"region,omitzero"`
   189  	// IAM role ARN. Deprecated — Anthropic reaches the KMS key through its own
   190  	// intermediate role (or, on Claude Platform on AWS, with credentials AWS issues
   191  	// for the Workspace); this field is ignored.
   192  	//
   193  	// Deprecated: deprecated
   194  	RoleARN param.Opt[string] `json:"role_arn,omitzero"`
   195  	// This field can be elided, and will marshal its zero value as "aws".
   196  	Type constant.AWS `json:"type" default:"aws"`
   197  	paramObj
   198  }
   199  
   200  func (r BetaAWSExternalKeyConfigParam) MarshalJSON() (data []byte, err error) {
   201  	type shadow BetaAWSExternalKeyConfigParam
   202  	return param.MarshalObject(r, (*shadow)(&r))
   203  }
   204  func (r *BetaAWSExternalKeyConfigParam) UnmarshalJSON(data []byte) error {
   205  	return apijson.UnmarshalRoot(data, r)
   206  }
   207  
   208  type BetaAzureExternalKeyConfig struct {
   209  	// Name of the key within the vault.
   210  	KeyName string `json:"key_name" api:"required"`
   211  	// Azure AD tenant ID.
   212  	TenantID string         `json:"tenant_id" api:"required"`
   213  	Type     constant.Azure `json:"type" default:"azure"`
   214  	// Key Vault data-plane URI — `https://{vault-name}.vault.azure.net` or
   215  	// `https://{hsm-name}.managedhsm.azure.net`.
   216  	VaultURI string `json:"vault_uri" api:"required"`
   217  	// Azure AD application (client) ID. Omit to use Anthropic's multitenant app.
   218  	// Provide only if using a single-tenant app registration in the customer's
   219  	// directory.
   220  	ClientID string `json:"client_id" api:"nullable"`
   221  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   222  	JSON struct {
   223  		KeyName     respjson.Field
   224  		TenantID    respjson.Field
   225  		Type        respjson.Field
   226  		VaultURI    respjson.Field
   227  		ClientID    respjson.Field
   228  		ExtraFields map[string]respjson.Field
   229  		raw         string
   230  	} `json:"-"`
   231  }
   232  
   233  // Returns the unmodified JSON received from the API
   234  func (r BetaAzureExternalKeyConfig) RawJSON() string { return r.JSON.raw }
   235  func (r *BetaAzureExternalKeyConfig) UnmarshalJSON(data []byte) error {
   236  	return apijson.UnmarshalRoot(data, r)
   237  }
   238  
   239  // Azure Key Vault provider configuration.
   240  //
   241  // The properties KeyName, TenantID, Type, VaultURI are required.
   242  type BetaAzureExternalKeyConfigParam struct {
   243  	// Name of the key within the vault.
   244  	KeyName string `json:"key_name" api:"required"`
   245  	// Azure AD tenant ID.
   246  	TenantID string `json:"tenant_id" api:"required"`
   247  	// Key Vault data-plane URI — `https://{vault-name}.vault.azure.net` or
   248  	// `https://{hsm-name}.managedhsm.azure.net`.
   249  	VaultURI string `json:"vault_uri" api:"required"`
   250  	// Azure AD application (client) ID. Omit to use Anthropic's multitenant app.
   251  	// Provide only if using a single-tenant app registration in the customer's
   252  	// directory.
   253  	ClientID param.Opt[string] `json:"client_id,omitzero"`
   254  	// This field can be elided, and will marshal its zero value as "azure".
   255  	Type constant.Azure `json:"type" default:"azure"`
   256  	paramObj
   257  }
   258  
   259  func (r BetaAzureExternalKeyConfigParam) MarshalJSON() (data []byte, err error) {
   260  	type shadow BetaAzureExternalKeyConfigParam
   261  	return param.MarshalObject(r, (*shadow)(&r))
   262  }
   263  func (r *BetaAzureExternalKeyConfigParam) UnmarshalJSON(data []byte) error {
   264  	return apijson.UnmarshalRoot(data, r)
   265  }
   266  
   267  // CMEK external key config belonging to the caller's organization.
   268  //
   269  // Configs are organization-scoped. Workspaces attach to a config; once any
   270  // workspace references it, the provider fields become effectively immutable
   271  // (existing encrypted data needs the config for decrypt).
   272  type BetaExternalKey struct {
   273  	// Identifier of the external key config. A tagged ID prefixed `ekey_`, or — for
   274  	// organizations on the Claude Platform on AWS — the AWS KMS key ARN.
   275  	ID string `json:"id" api:"required"`
   276  	// Whether any workspace uses this config to encrypt its data — counting live and
   277  	// archived workspaces (an archived workspace's data remains encrypted under the
   278  	// config), excluding deleted ones. Only an attached config is used by the
   279  	// encryption path; an `unattached` config is inert and can be deleted.
   280  	Attachment BetaExternalKeyAttachmentUnion `json:"attachment" api:"required"`
   281  	CreatedAt  time.Time                      `json:"created_at" api:"required" format:"date-time"`
   282  	// Human-friendly display name. Null if none was set.
   283  	DisplayName string `json:"display_name" api:"required"`
   284  	// Data residency geo. Selects which regional validator handles this key's
   285  	// encrypt/decrypt roundtrips.
   286  	Geo string `json:"geo" api:"required"`
   287  	// KMS provider identity and auth coordinates.
   288  	ProviderConfig BetaExternalKeyProviderConfigUnion `json:"provider_config" api:"required"`
   289  	Type           constant.ExternalKey               `json:"type" default:"external_key"`
   290  	UpdatedAt      time.Time                          `json:"updated_at" api:"required" format:"date-time"`
   291  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   292  	JSON struct {
   293  		ID             respjson.Field
   294  		Attachment     respjson.Field
   295  		CreatedAt      respjson.Field
   296  		DisplayName    respjson.Field
   297  		Geo            respjson.Field
   298  		ProviderConfig respjson.Field
   299  		Type           respjson.Field
   300  		UpdatedAt      respjson.Field
   301  		ExtraFields    map[string]respjson.Field
   302  		raw            string
   303  	} `json:"-"`
   304  }
   305  
   306  // Returns the unmodified JSON received from the API
   307  func (r BetaExternalKey) RawJSON() string { return r.JSON.raw }
   308  func (r *BetaExternalKey) UnmarshalJSON(data []byte) error {
   309  	return apijson.UnmarshalRoot(data, r)
   310  }
   311  
   312  // BetaExternalKeyAttachmentUnion contains all possible properties and values from
   313  // [BetaExternalKeyAttachedAttachment], [BetaExternalKeyUnattachedAttachment].
   314  //
   315  // Use the [BetaExternalKeyAttachmentUnion.AsAny] method to switch on the variant.
   316  //
   317  // Use the methods beginning with 'As' to cast the union to one of its variants.
   318  type BetaExternalKeyAttachmentUnion struct {
   319  	// Any of "attached", "unattached".
   320  	Type string `json:"type"`
   321  	JSON struct {
   322  		Type respjson.Field
   323  		raw  string
   324  	} `json:"-"`
   325  }
   326  
   327  // anyBetaExternalKeyAttachment is implemented by each variant of
   328  // [BetaExternalKeyAttachmentUnion] to add type safety for the return type of
   329  // [BetaExternalKeyAttachmentUnion.AsAny]
   330  type anyBetaExternalKeyAttachment interface {
   331  	implBetaExternalKeyAttachmentUnion()
   332  }
   333  
   334  func (BetaExternalKeyAttachedAttachment) implBetaExternalKeyAttachmentUnion()   {}
   335  func (BetaExternalKeyUnattachedAttachment) implBetaExternalKeyAttachmentUnion() {}
   336  
   337  // Use the following switch statement to find the correct variant
   338  //
   339  //	switch variant := BetaExternalKeyAttachmentUnion.AsAny().(type) {
   340  //	case anthropic.BetaExternalKeyAttachedAttachment:
   341  //	case anthropic.BetaExternalKeyUnattachedAttachment:
   342  //	default:
   343  //	  fmt.Errorf("no variant present")
   344  //	}
   345  func (u BetaExternalKeyAttachmentUnion) AsAny() anyBetaExternalKeyAttachment {
   346  	switch u.Type {
   347  	case "attached":
   348  		return u.AsAttached()
   349  	case "unattached":
   350  		return u.AsUnattached()
   351  	}
   352  	return nil
   353  }
   354  
   355  func (u BetaExternalKeyAttachmentUnion) AsAttached() (v BetaExternalKeyAttachedAttachment) {
   356  	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
   357  	return
   358  }
   359  
   360  func (u BetaExternalKeyAttachmentUnion) AsUnattached() (v BetaExternalKeyUnattachedAttachment) {
   361  	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
   362  	return
   363  }
   364  
   365  // Returns the unmodified JSON received from the API
   366  func (u BetaExternalKeyAttachmentUnion) RawJSON() string { return u.JSON.raw }
   367  
   368  func (r *BetaExternalKeyAttachmentUnion) UnmarshalJSON(data []byte) error {
   369  	return apijson.UnmarshalRoot(data, r)
   370  }
   371  
   372  // BetaExternalKeyProviderConfigUnion contains all possible properties and values
   373  // from [BetaAWSExternalKeyConfig], [BetaGCPExternalKeyConfig],
   374  // [BetaAzureExternalKeyConfig].
   375  //
   376  // Use the [BetaExternalKeyProviderConfigUnion.AsAny] method to switch on the
   377  // variant.
   378  //
   379  // Use the methods beginning with 'As' to cast the union to one of its variants.
   380  type BetaExternalKeyProviderConfigUnion struct {
   381  	// This field is from variant [BetaAWSExternalKeyConfig].
   382  	KMSARN string `json:"kms_arn"`
   383  	// Any of "aws", "gcp", "azure".
   384  	Type string `json:"type"`
   385  	// This field is from variant [BetaAWSExternalKeyConfig].
   386  	Region string `json:"region"`
   387  	// This field is from variant [BetaAWSExternalKeyConfig].
   388  	RoleARN string `json:"role_arn"`
   389  	KeyName string `json:"key_name"`
   390  	// This field is from variant [BetaAzureExternalKeyConfig].
   391  	TenantID string `json:"tenant_id"`
   392  	// This field is from variant [BetaAzureExternalKeyConfig].
   393  	VaultURI string `json:"vault_uri"`
   394  	// This field is from variant [BetaAzureExternalKeyConfig].
   395  	ClientID string `json:"client_id"`
   396  	JSON     struct {
   397  		KMSARN   respjson.Field
   398  		Type     respjson.Field
   399  		Region   respjson.Field
   400  		RoleARN  respjson.Field
   401  		KeyName  respjson.Field
   402  		TenantID respjson.Field
   403  		VaultURI respjson.Field
   404  		ClientID respjson.Field
   405  		raw      string
   406  	} `json:"-"`
   407  }
   408  
   409  // anyBetaExternalKeyProviderConfig is implemented by each variant of
   410  // [BetaExternalKeyProviderConfigUnion] to add type safety for the return type of
   411  // [BetaExternalKeyProviderConfigUnion.AsAny]
   412  type anyBetaExternalKeyProviderConfig interface {
   413  	implBetaExternalKeyProviderConfigUnion()
   414  }
   415  
   416  func (BetaAWSExternalKeyConfig) implBetaExternalKeyProviderConfigUnion()   {}
   417  func (BetaGCPExternalKeyConfig) implBetaExternalKeyProviderConfigUnion()   {}
   418  func (BetaAzureExternalKeyConfig) implBetaExternalKeyProviderConfigUnion() {}
   419  
   420  // Use the following switch statement to find the correct variant
   421  //
   422  //	switch variant := BetaExternalKeyProviderConfigUnion.AsAny().(type) {
   423  //	case anthropic.BetaAWSExternalKeyConfig:
   424  //	case anthropic.BetaGCPExternalKeyConfig:
   425  //	case anthropic.BetaAzureExternalKeyConfig:
   426  //	default:
   427  //	  fmt.Errorf("no variant present")
   428  //	}
   429  func (u BetaExternalKeyProviderConfigUnion) AsAny() anyBetaExternalKeyProviderConfig {
   430  	switch u.Type {
   431  	case "aws":
   432  		return u.AsAWS()
   433  	case "gcp":
   434  		return u.AsGCP()
   435  	case "azure":
   436  		return u.AsAzure()
   437  	}
   438  	return nil
   439  }
   440  
   441  func (u BetaExternalKeyProviderConfigUnion) AsAWS() (v BetaAWSExternalKeyConfig) {
   442  	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
   443  	return
   444  }
   445  
   446  func (u BetaExternalKeyProviderConfigUnion) AsGCP() (v BetaGCPExternalKeyConfig) {
   447  	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
   448  	return
   449  }
   450  
   451  func (u BetaExternalKeyProviderConfigUnion) AsAzure() (v BetaAzureExternalKeyConfig) {
   452  	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
   453  	return
   454  }
   455  
   456  // Returns the unmodified JSON received from the API
   457  func (u BetaExternalKeyProviderConfigUnion) RawJSON() string { return u.JSON.raw }
   458  
   459  func (r *BetaExternalKeyProviderConfigUnion) UnmarshalJSON(data []byte) error {
   460  	return apijson.UnmarshalRoot(data, r)
   461  }
   462  
   463  type BetaExternalKeyAttachedAttachment struct {
   464  	Type constant.Attached `json:"type" default:"attached"`
   465  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   466  	JSON struct {
   467  		Type        respjson.Field
   468  		ExtraFields map[string]respjson.Field
   469  		raw         string
   470  	} `json:"-"`
   471  }
   472  
   473  // Returns the unmodified JSON received from the API
   474  func (r BetaExternalKeyAttachedAttachment) RawJSON() string { return r.JSON.raw }
   475  func (r *BetaExternalKeyAttachedAttachment) UnmarshalJSON(data []byte) error {
   476  	return apijson.UnmarshalRoot(data, r)
   477  }
   478  
   479  type BetaExternalKeyUnattachedAttachment struct {
   480  	Type constant.Unattached `json:"type" default:"unattached"`
   481  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   482  	JSON struct {
   483  		Type        respjson.Field
   484  		ExtraFields map[string]respjson.Field
   485  		raw         string
   486  	} `json:"-"`
   487  }
   488  
   489  // Returns the unmodified JSON received from the API
   490  func (r BetaExternalKeyUnattachedAttachment) RawJSON() string { return r.JSON.raw }
   491  func (r *BetaExternalKeyUnattachedAttachment) UnmarshalJSON(data []byte) error {
   492  	return apijson.UnmarshalRoot(data, r)
   493  }
   494  
   495  type BetaGCPExternalKeyConfig struct {
   496  	// Full resource name of the Cloud KMS key.
   497  	KeyName string       `json:"key_name" api:"required"`
   498  	Type    constant.GCP `json:"type" default:"gcp"`
   499  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   500  	JSON struct {
   501  		KeyName     respjson.Field
   502  		Type        respjson.Field
   503  		ExtraFields map[string]respjson.Field
   504  		raw         string
   505  	} `json:"-"`
   506  }
   507  
   508  // Returns the unmodified JSON received from the API
   509  func (r BetaGCPExternalKeyConfig) RawJSON() string { return r.JSON.raw }
   510  func (r *BetaGCPExternalKeyConfig) UnmarshalJSON(data []byte) error {
   511  	return apijson.UnmarshalRoot(data, r)
   512  }
   513  
   514  // ToParam converts this BetaGCPExternalKeyConfig to a
   515  // BetaGCPExternalKeyConfigParam.
   516  //
   517  // Warning: the fields of the param type will not be present. ToParam should only
   518  // be used at the last possible moment before sending a request. Test for this with
   519  // BetaGCPExternalKeyConfigParam.Overrides()
   520  func (r BetaGCPExternalKeyConfig) ToParam() BetaGCPExternalKeyConfigParam {
   521  	return param.Override[BetaGCPExternalKeyConfigParam](json.RawMessage(r.RawJSON()))
   522  }
   523  
   524  // The properties KeyName, Type are required.
   525  type BetaGCPExternalKeyConfigParam struct {
   526  	// Full resource name of the Cloud KMS key.
   527  	KeyName string `json:"key_name" api:"required"`
   528  	// This field can be elided, and will marshal its zero value as "gcp".
   529  	Type constant.GCP `json:"type" default:"gcp"`
   530  	paramObj
   531  }
   532  
   533  func (r BetaGCPExternalKeyConfigParam) MarshalJSON() (data []byte, err error) {
   534  	type shadow BetaGCPExternalKeyConfigParam
   535  	return param.MarshalObject(r, (*shadow)(&r))
   536  }
   537  func (r *BetaGCPExternalKeyConfigParam) UnmarshalJSON(data []byte) error {
   538  	return apijson.UnmarshalRoot(data, r)
   539  }
   540  
   541  type BetaOrganizationExternalKeyDeleteResponse struct {
   542  	// ID of the deleted External Key.
   543  	ID   string                      `json:"id" api:"required"`
   544  	Type constant.ExternalKeyDeleted `json:"type" default:"external_key_deleted"`
   545  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   546  	JSON struct {
   547  		ID          respjson.Field
   548  		Type        respjson.Field
   549  		ExtraFields map[string]respjson.Field
   550  		raw         string
   551  	} `json:"-"`
   552  }
   553  
   554  // Returns the unmodified JSON received from the API
   555  func (r BetaOrganizationExternalKeyDeleteResponse) RawJSON() string { return r.JSON.raw }
   556  func (r *BetaOrganizationExternalKeyDeleteResponse) UnmarshalJSON(data []byte) error {
   557  	return apijson.UnmarshalRoot(data, r)
   558  }
   559  
   560  // Result of a validation roundtrip against the customer's KMS.
   561  //
   562  // HTTP 200 for both outcomes — the operation completed; `status` says whether the
   563  // key works.
   564  type BetaOrganizationExternalKeyValidateResponse struct {
   565  	// Error message when status is `failure`. Null otherwise.
   566  	Error string `json:"error" api:"required"`
   567  	// `success` — encrypt/decrypt roundtrip succeeded. `failure` — the roundtrip
   568  	// failed or timed out; see `error`.
   569  	//
   570  	// Any of "failure", "success".
   571  	Status BetaOrganizationExternalKeyValidateResponseStatus `json:"status" api:"required"`
   572  	Type   constant.ExternalKeyValidation                    `json:"type" default:"external_key_validation"`
   573  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   574  	JSON struct {
   575  		Error       respjson.Field
   576  		Status      respjson.Field
   577  		Type        respjson.Field
   578  		ExtraFields map[string]respjson.Field
   579  		raw         string
   580  	} `json:"-"`
   581  }
   582  
   583  // Returns the unmodified JSON received from the API
   584  func (r BetaOrganizationExternalKeyValidateResponse) RawJSON() string { return r.JSON.raw }
   585  func (r *BetaOrganizationExternalKeyValidateResponse) UnmarshalJSON(data []byte) error {
   586  	return apijson.UnmarshalRoot(data, r)
   587  }
   588  
   589  // `success` — encrypt/decrypt roundtrip succeeded. `failure` — the roundtrip
   590  // failed or timed out; see `error`.
   591  type BetaOrganizationExternalKeyValidateResponseStatus string
   592  
   593  const (
   594  	BetaOrganizationExternalKeyValidateResponseStatusFailure BetaOrganizationExternalKeyValidateResponseStatus = "failure"
   595  	BetaOrganizationExternalKeyValidateResponseStatusSuccess BetaOrganizationExternalKeyValidateResponseStatus = "success"
   596  )
   597  
   598  type BetaOrganizationExternalKeyNewParams struct {
   599  	// KMS provider identity and auth coordinates.
   600  	ProviderConfig BetaOrganizationExternalKeyNewParamsProviderConfigUnion `json:"provider_config,omitzero" api:"required"`
   601  	// Human-friendly display name.
   602  	DisplayName param.Opt[string] `json:"display_name,omitzero"`
   603  	// Data residency geo. Only `us` is supported.
   604  	//
   605  	// Any of "us".
   606  	Geo BetaOrganizationExternalKeyNewParamsGeo `json:"geo,omitzero"`
   607  	paramObj
   608  }
   609  
   610  func (r BetaOrganizationExternalKeyNewParams) MarshalJSON() (data []byte, err error) {
   611  	type shadow BetaOrganizationExternalKeyNewParams
   612  	return param.MarshalObject(r, (*shadow)(&r))
   613  }
   614  func (r *BetaOrganizationExternalKeyNewParams) UnmarshalJSON(data []byte) error {
   615  	return apijson.UnmarshalRoot(data, r)
   616  }
   617  
   618  // Only one field can be non-zero.
   619  //
   620  // Use [param.IsOmitted] to confirm if a field is set.
   621  type BetaOrganizationExternalKeyNewParamsProviderConfigUnion struct {
   622  	OfAWS   *BetaAWSExternalKeyConfigParam   `json:",omitzero,inline"`
   623  	OfGCP   *BetaGCPExternalKeyConfigParam   `json:",omitzero,inline"`
   624  	OfAzure *BetaAzureExternalKeyConfigParam `json:",omitzero,inline"`
   625  	paramUnion
   626  }
   627  
   628  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) MarshalJSON() ([]byte, error) {
   629  	return param.MarshalUnion(u, u.OfAWS, u.OfGCP, u.OfAzure)
   630  }
   631  func (u *BetaOrganizationExternalKeyNewParamsProviderConfigUnion) UnmarshalJSON(data []byte) error {
   632  	return apijson.UnmarshalRoot(data, u)
   633  }
   634  
   635  func (u *BetaOrganizationExternalKeyNewParamsProviderConfigUnion) asAny() any {
   636  	if !param.IsOmitted(u.OfAWS) {
   637  		return u.OfAWS
   638  	} else if !param.IsOmitted(u.OfGCP) {
   639  		return u.OfGCP
   640  	} else if !param.IsOmitted(u.OfAzure) {
   641  		return u.OfAzure
   642  	}
   643  	return nil
   644  }
   645  
   646  // Returns a pointer to the underlying variant's property, if present.
   647  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) GetKMSARN() *string {
   648  	if vt := u.OfAWS; vt != nil {
   649  		return &vt.KMSARN
   650  	}
   651  	return nil
   652  }
   653  
   654  // Returns a pointer to the underlying variant's property, if present.
   655  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) GetRegion() *string {
   656  	if vt := u.OfAWS; vt != nil && vt.Region.Valid() {
   657  		return &vt.Region.Value
   658  	}
   659  	return nil
   660  }
   661  
   662  // Returns a pointer to the underlying variant's property, if present.
   663  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) GetRoleARN() *string {
   664  	if vt := u.OfAWS; vt != nil && vt.RoleARN.Valid() {
   665  		return &vt.RoleARN.Value
   666  	}
   667  	return nil
   668  }
   669  
   670  // Returns a pointer to the underlying variant's property, if present.
   671  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) GetTenantID() *string {
   672  	if vt := u.OfAzure; vt != nil {
   673  		return &vt.TenantID
   674  	}
   675  	return nil
   676  }
   677  
   678  // Returns a pointer to the underlying variant's property, if present.
   679  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) GetVaultURI() *string {
   680  	if vt := u.OfAzure; vt != nil {
   681  		return &vt.VaultURI
   682  	}
   683  	return nil
   684  }
   685  
   686  // Returns a pointer to the underlying variant's property, if present.
   687  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) GetClientID() *string {
   688  	if vt := u.OfAzure; vt != nil && vt.ClientID.Valid() {
   689  		return &vt.ClientID.Value
   690  	}
   691  	return nil
   692  }
   693  
   694  // Returns a pointer to the underlying variant's property, if present.
   695  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) GetType() *string {
   696  	if vt := u.OfAWS; vt != nil {
   697  		return (*string)(&vt.Type)
   698  	} else if vt := u.OfGCP; vt != nil {
   699  		return (*string)(&vt.Type)
   700  	} else if vt := u.OfAzure; vt != nil {
   701  		return (*string)(&vt.Type)
   702  	}
   703  	return nil
   704  }
   705  
   706  // Returns a pointer to the underlying variant's property, if present.
   707  func (u BetaOrganizationExternalKeyNewParamsProviderConfigUnion) GetKeyName() *string {
   708  	if vt := u.OfGCP; vt != nil {
   709  		return (*string)(&vt.KeyName)
   710  	} else if vt := u.OfAzure; vt != nil {
   711  		return (*string)(&vt.KeyName)
   712  	}
   713  	return nil
   714  }
   715  
   716  func init() {
   717  	apijson.RegisterUnion[BetaOrganizationExternalKeyNewParamsProviderConfigUnion](
   718  		"type",
   719  		apijson.Discriminator[BetaAWSExternalKeyConfigParam]("aws"),
   720  		apijson.Discriminator[BetaGCPExternalKeyConfigParam]("gcp"),
   721  		apijson.Discriminator[BetaAzureExternalKeyConfigParam]("azure"),
   722  	)
   723  }
   724  
   725  // Data residency geo. Only `us` is supported.
   726  type BetaOrganizationExternalKeyNewParamsGeo string
   727  
   728  const (
   729  	BetaOrganizationExternalKeyNewParamsGeoUs BetaOrganizationExternalKeyNewParamsGeo = "us"
   730  )
   731  
   732  type BetaOrganizationExternalKeyUpdateParams struct {
   733  	// Human-friendly display name.
   734  	DisplayName param.Opt[string] `json:"display_name,omitzero"`
   735  	// Data residency geo. Only `us` is supported.
   736  	//
   737  	// Any of "us".
   738  	Geo BetaOrganizationExternalKeyUpdateParamsGeo `json:"geo,omitzero"`
   739  	// KMS provider identity and auth coordinates.
   740  	ProviderConfig BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion `json:"provider_config,omitzero"`
   741  	paramObj
   742  }
   743  
   744  func (r BetaOrganizationExternalKeyUpdateParams) MarshalJSON() (data []byte, err error) {
   745  	type shadow BetaOrganizationExternalKeyUpdateParams
   746  	return param.MarshalObject(r, (*shadow)(&r))
   747  }
   748  func (r *BetaOrganizationExternalKeyUpdateParams) UnmarshalJSON(data []byte) error {
   749  	return apijson.UnmarshalRoot(data, r)
   750  }
   751  
   752  // Data residency geo. Only `us` is supported.
   753  type BetaOrganizationExternalKeyUpdateParamsGeo string
   754  
   755  const (
   756  	BetaOrganizationExternalKeyUpdateParamsGeoUs BetaOrganizationExternalKeyUpdateParamsGeo = "us"
   757  )
   758  
   759  // Only one field can be non-zero.
   760  //
   761  // Use [param.IsOmitted] to confirm if a field is set.
   762  type BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion struct {
   763  	OfAWS   *BetaAWSExternalKeyConfigParam   `json:",omitzero,inline"`
   764  	OfGCP   *BetaGCPExternalKeyConfigParam   `json:",omitzero,inline"`
   765  	OfAzure *BetaAzureExternalKeyConfigParam `json:",omitzero,inline"`
   766  	paramUnion
   767  }
   768  
   769  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) MarshalJSON() ([]byte, error) {
   770  	return param.MarshalUnion(u, u.OfAWS, u.OfGCP, u.OfAzure)
   771  }
   772  func (u *BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) UnmarshalJSON(data []byte) error {
   773  	return apijson.UnmarshalRoot(data, u)
   774  }
   775  
   776  func (u *BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) asAny() any {
   777  	if !param.IsOmitted(u.OfAWS) {
   778  		return u.OfAWS
   779  	} else if !param.IsOmitted(u.OfGCP) {
   780  		return u.OfGCP
   781  	} else if !param.IsOmitted(u.OfAzure) {
   782  		return u.OfAzure
   783  	}
   784  	return nil
   785  }
   786  
   787  // Returns a pointer to the underlying variant's property, if present.
   788  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) GetKMSARN() *string {
   789  	if vt := u.OfAWS; vt != nil {
   790  		return &vt.KMSARN
   791  	}
   792  	return nil
   793  }
   794  
   795  // Returns a pointer to the underlying variant's property, if present.
   796  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) GetRegion() *string {
   797  	if vt := u.OfAWS; vt != nil && vt.Region.Valid() {
   798  		return &vt.Region.Value
   799  	}
   800  	return nil
   801  }
   802  
   803  // Returns a pointer to the underlying variant's property, if present.
   804  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) GetRoleARN() *string {
   805  	if vt := u.OfAWS; vt != nil && vt.RoleARN.Valid() {
   806  		return &vt.RoleARN.Value
   807  	}
   808  	return nil
   809  }
   810  
   811  // Returns a pointer to the underlying variant's property, if present.
   812  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) GetTenantID() *string {
   813  	if vt := u.OfAzure; vt != nil {
   814  		return &vt.TenantID
   815  	}
   816  	return nil
   817  }
   818  
   819  // Returns a pointer to the underlying variant's property, if present.
   820  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) GetVaultURI() *string {
   821  	if vt := u.OfAzure; vt != nil {
   822  		return &vt.VaultURI
   823  	}
   824  	return nil
   825  }
   826  
   827  // Returns a pointer to the underlying variant's property, if present.
   828  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) GetClientID() *string {
   829  	if vt := u.OfAzure; vt != nil && vt.ClientID.Valid() {
   830  		return &vt.ClientID.Value
   831  	}
   832  	return nil
   833  }
   834  
   835  // Returns a pointer to the underlying variant's property, if present.
   836  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) GetType() *string {
   837  	if vt := u.OfAWS; vt != nil {
   838  		return (*string)(&vt.Type)
   839  	} else if vt := u.OfGCP; vt != nil {
   840  		return (*string)(&vt.Type)
   841  	} else if vt := u.OfAzure; vt != nil {
   842  		return (*string)(&vt.Type)
   843  	}
   844  	return nil
   845  }
   846  
   847  // Returns a pointer to the underlying variant's property, if present.
   848  func (u BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion) GetKeyName() *string {
   849  	if vt := u.OfGCP; vt != nil {
   850  		return (*string)(&vt.KeyName)
   851  	} else if vt := u.OfAzure; vt != nil {
   852  		return (*string)(&vt.KeyName)
   853  	}
   854  	return nil
   855  }
   856  
   857  func init() {
   858  	apijson.RegisterUnion[BetaOrganizationExternalKeyUpdateParamsProviderConfigUnion](
   859  		"type",
   860  		apijson.Discriminator[BetaAWSExternalKeyConfigParam]("aws"),
   861  		apijson.Discriminator[BetaGCPExternalKeyConfigParam]("gcp"),
   862  		apijson.Discriminator[BetaAzureExternalKeyConfigParam]("azure"),
   863  	)
   864  }
   865  
   866  type BetaOrganizationExternalKeyListParams struct {
   867  	// Opaque cursor from a previous response's `next_page`.
   868  	Page param.Opt[string] `query:"page,omitzero" json:"-"`
   869  	// Number of results per page.
   870  	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
   871  	paramObj
   872  }
   873  
   874  // URLQuery serializes [BetaOrganizationExternalKeyListParams]'s query parameters
   875  // as `url.Values`.
   876  func (r BetaOrganizationExternalKeyListParams) URLQuery() (v url.Values, err error) {
   877  	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
   878  		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
   879  		NestedFormat: apiquery.NestedQueryFormatBrackets,
   880  	})
   881  }