github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationcompliancesetting.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 "net/http" 9 "slices" 10 11 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 12 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 13 "github.com/anthropics/anthropic-sdk-go/option" 14 "github.com/anthropics/anthropic-sdk-go/packages/param" 15 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 16 "github.com/anthropics/anthropic-sdk-go/shared/constant" 17 ) 18 19 // BetaOrganizationComplianceSettingService contains methods and other services 20 // that help with interacting with the anthropic API. 21 // 22 // Note, unlike clients, this service does not read variables from the environment 23 // automatically. You should not instantiate this service directly, and instead use 24 // the [NewBetaOrganizationComplianceSettingService] method instead. 25 type BetaOrganizationComplianceSettingService struct { 26 Options []option.RequestOption 27 } 28 29 // NewBetaOrganizationComplianceSettingService generates a new service that applies 30 // the given options to each request. These options are applied after the parent 31 // client's options (if there is one), and before any request-specific options. 32 func NewBetaOrganizationComplianceSettingService(opts ...option.RequestOption) (r BetaOrganizationComplianceSettingService) { 33 r = BetaOrganizationComplianceSettingService{} 34 r.Options = opts 35 return 36 } 37 38 // Retrieve your organization's Compliance Settings. 39 // 40 // Compliance Settings is a singleton resource: there is exactly one per 41 // organization, addressed without an identifier. The `state` field reflects 42 // whether the Compliance API is enabled. An organization with a parent 43 // organization reads the state inherited from the parent's configuration. 44 func (r *BetaOrganizationComplianceSettingService) Get(ctx context.Context, opts ...option.RequestOption) (res *BetaComplianceSettings, err error) { 45 opts = slices.Concat(r.Options, opts) 46 path := "v1/organizations/compliance_settings?beta=true" 47 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 48 return res, err 49 } 50 51 // Update your organization's Compliance Settings. 52 // 53 // Setting `state` to `enabled` turns on the Compliance API and begins capturing 54 // organization activity events. Setting it to `disabled` turns both off. `state` 55 // reflects whether the Compliance API is enabled. 56 // 57 // A request that sets `state` to its current value succeeds and leaves the 58 // resource unchanged. A `disabled` request stays in effect until a later `enabled` 59 // request or the organization's next provisioning action that enables Access 60 // Transparency: enabling Access Transparency also enables the Compliance API, 61 // which serves its activity events, so such provisioning (including re-runs) 62 // re-enables the Compliance API even after a `disabled` request. Automated 63 // provisioning never disables compliance settings. 64 func (r *BetaOrganizationComplianceSettingService) Update(ctx context.Context, body BetaOrganizationComplianceSettingUpdateParams, opts ...option.RequestOption) (res *BetaComplianceSettings, err error) { 65 opts = slices.Concat(r.Options, opts) 66 path := "v1/organizations/compliance_settings?beta=true" 67 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) 68 return res, err 69 } 70 71 type BetaComplianceSettings struct { 72 // Whether the Compliance API is enabled for this organization. 73 State BetaComplianceSettingsStateUnion `json:"state" api:"required"` 74 Type constant.ComplianceSettings `json:"type" default:"compliance_settings"` 75 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 76 JSON struct { 77 State respjson.Field 78 Type respjson.Field 79 ExtraFields map[string]respjson.Field 80 raw string 81 } `json:"-"` 82 } 83 84 // Returns the unmodified JSON received from the API 85 func (r BetaComplianceSettings) RawJSON() string { return r.JSON.raw } 86 func (r *BetaComplianceSettings) UnmarshalJSON(data []byte) error { 87 return apijson.UnmarshalRoot(data, r) 88 } 89 90 // BetaComplianceSettingsStateUnion contains all possible properties and values 91 // from [BetaComplianceSettingsStateEnabled], 92 // [BetaComplianceSettingsStateDisabled]. 93 // 94 // Use the [BetaComplianceSettingsStateUnion.AsAny] method to switch on the 95 // variant. 96 // 97 // Use the methods beginning with 'As' to cast the union to one of its variants. 98 type BetaComplianceSettingsStateUnion struct { 99 // Any of "enabled", "disabled". 100 Type string `json:"type"` 101 JSON struct { 102 Type respjson.Field 103 raw string 104 } `json:"-"` 105 } 106 107 // anyBetaComplianceSettingsState is implemented by each variant of 108 // [BetaComplianceSettingsStateUnion] to add type safety for the return type of 109 // [BetaComplianceSettingsStateUnion.AsAny] 110 type anyBetaComplianceSettingsState interface { 111 implBetaComplianceSettingsStateUnion() 112 } 113 114 func (BetaComplianceSettingsStateEnabled) implBetaComplianceSettingsStateUnion() {} 115 func (BetaComplianceSettingsStateDisabled) implBetaComplianceSettingsStateUnion() {} 116 117 // Use the following switch statement to find the correct variant 118 // 119 // switch variant := BetaComplianceSettingsStateUnion.AsAny().(type) { 120 // case anthropic.BetaComplianceSettingsStateEnabled: 121 // case anthropic.BetaComplianceSettingsStateDisabled: 122 // default: 123 // fmt.Errorf("no variant present") 124 // } 125 func (u BetaComplianceSettingsStateUnion) AsAny() anyBetaComplianceSettingsState { 126 switch u.Type { 127 case "enabled": 128 return u.AsEnabled() 129 case "disabled": 130 return u.AsDisabled() 131 } 132 return nil 133 } 134 135 func (u BetaComplianceSettingsStateUnion) AsEnabled() (v BetaComplianceSettingsStateEnabled) { 136 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 137 return 138 } 139 140 func (u BetaComplianceSettingsStateUnion) AsDisabled() (v BetaComplianceSettingsStateDisabled) { 141 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 142 return 143 } 144 145 // Returns the unmodified JSON received from the API 146 func (u BetaComplianceSettingsStateUnion) RawJSON() string { return u.JSON.raw } 147 148 func (r *BetaComplianceSettingsStateUnion) UnmarshalJSON(data []byte) error { 149 return apijson.UnmarshalRoot(data, r) 150 } 151 152 type BetaComplianceSettingsStateDisabled struct { 153 Type constant.Disabled `json:"type" default:"disabled"` 154 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 155 JSON struct { 156 Type respjson.Field 157 ExtraFields map[string]respjson.Field 158 raw string 159 } `json:"-"` 160 } 161 162 // Returns the unmodified JSON received from the API 163 func (r BetaComplianceSettingsStateDisabled) RawJSON() string { return r.JSON.raw } 164 func (r *BetaComplianceSettingsStateDisabled) UnmarshalJSON(data []byte) error { 165 return apijson.UnmarshalRoot(data, r) 166 } 167 168 func NewBetaComplianceSettingsStateDisabledParam() BetaComplianceSettingsStateDisabledParam { 169 return BetaComplianceSettingsStateDisabledParam{ 170 Type: "disabled", 171 } 172 } 173 174 // This struct has a constant value, construct it with 175 // [NewBetaComplianceSettingsStateDisabledParam]. 176 type BetaComplianceSettingsStateDisabledParam struct { 177 Type constant.Disabled `json:"type" default:"disabled"` 178 paramObj 179 } 180 181 func (r BetaComplianceSettingsStateDisabledParam) MarshalJSON() (data []byte, err error) { 182 type shadow BetaComplianceSettingsStateDisabledParam 183 return param.MarshalObject(r, (*shadow)(&r)) 184 } 185 func (r *BetaComplianceSettingsStateDisabledParam) UnmarshalJSON(data []byte) error { 186 return apijson.UnmarshalRoot(data, r) 187 } 188 189 type BetaComplianceSettingsStateEnabled struct { 190 Type constant.Enabled `json:"type" default:"enabled"` 191 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 192 JSON struct { 193 Type respjson.Field 194 ExtraFields map[string]respjson.Field 195 raw string 196 } `json:"-"` 197 } 198 199 // Returns the unmodified JSON received from the API 200 func (r BetaComplianceSettingsStateEnabled) RawJSON() string { return r.JSON.raw } 201 func (r *BetaComplianceSettingsStateEnabled) UnmarshalJSON(data []byte) error { 202 return apijson.UnmarshalRoot(data, r) 203 } 204 205 func NewBetaComplianceSettingsStateEnabledParam() BetaComplianceSettingsStateEnabledParam { 206 return BetaComplianceSettingsStateEnabledParam{ 207 Type: "enabled", 208 } 209 } 210 211 // This struct has a constant value, construct it with 212 // [NewBetaComplianceSettingsStateEnabledParam]. 213 type BetaComplianceSettingsStateEnabledParam struct { 214 Type constant.Enabled `json:"type" default:"enabled"` 215 paramObj 216 } 217 218 func (r BetaComplianceSettingsStateEnabledParam) MarshalJSON() (data []byte, err error) { 219 type shadow BetaComplianceSettingsStateEnabledParam 220 return param.MarshalObject(r, (*shadow)(&r)) 221 } 222 func (r *BetaComplianceSettingsStateEnabledParam) UnmarshalJSON(data []byte) error { 223 return apijson.UnmarshalRoot(data, r) 224 } 225 226 type BetaOrganizationComplianceSettingUpdateParams struct { 227 // Desired state. Accepts the string shorthand "enabled" or "disabled" in place of 228 // the object form; the response always returns the canonical object form. 229 State BetaOrganizationComplianceSettingUpdateParamsStateUnion `json:"state,omitzero" api:"required"` 230 paramObj 231 } 232 233 func (r BetaOrganizationComplianceSettingUpdateParams) MarshalJSON() (data []byte, err error) { 234 type shadow BetaOrganizationComplianceSettingUpdateParams 235 return param.MarshalObject(r, (*shadow)(&r)) 236 } 237 func (r *BetaOrganizationComplianceSettingUpdateParams) UnmarshalJSON(data []byte) error { 238 return apijson.UnmarshalRoot(data, r) 239 } 240 241 // Only one field can be non-zero. 242 // 243 // Use [param.IsOmitted] to confirm if a field is set. 244 type BetaOrganizationComplianceSettingUpdateParamsStateUnion struct { 245 OfEnabled *BetaComplianceSettingsStateEnabledParam `json:",omitzero,inline"` 246 OfDisabled *BetaComplianceSettingsStateDisabledParam `json:",omitzero,inline"` 247 paramUnion 248 } 249 250 func (u BetaOrganizationComplianceSettingUpdateParamsStateUnion) MarshalJSON() ([]byte, error) { 251 return param.MarshalUnion(u, u.OfEnabled, u.OfDisabled) 252 } 253 func (u *BetaOrganizationComplianceSettingUpdateParamsStateUnion) UnmarshalJSON(data []byte) error { 254 return apijson.UnmarshalRoot(data, u) 255 } 256 257 func (u *BetaOrganizationComplianceSettingUpdateParamsStateUnion) asAny() any { 258 if !param.IsOmitted(u.OfEnabled) { 259 return u.OfEnabled 260 } else if !param.IsOmitted(u.OfDisabled) { 261 return u.OfDisabled 262 } 263 return nil 264 } 265 266 // Returns a pointer to the underlying variant's property, if present. 267 func (u BetaOrganizationComplianceSettingUpdateParamsStateUnion) GetType() *string { 268 if vt := u.OfEnabled; vt != nil { 269 return (*string)(&vt.Type) 270 } else if vt := u.OfDisabled; vt != nil { 271 return (*string)(&vt.Type) 272 } 273 return nil 274 } 275 276 func init() { 277 apijson.RegisterUnion[BetaOrganizationComplianceSettingUpdateParamsStateUnion]( 278 "type", 279 apijson.Discriminator[BetaComplianceSettingsStateEnabledParam]("enabled"), 280 apijson.Discriminator[BetaComplianceSettingsStateDisabledParam]("disabled"), 281 ) 282 }