Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#1730)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Apr 10, 2024
1 parent a671211 commit 63baef8
Show file tree
Hide file tree
Showing 387 changed files with 9,644 additions and 15,223 deletions.
95 changes: 56 additions & 39 deletions accounts/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"net/url"
"reflect"
"time"

"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/tidwall/gjson"
)

// AccountService contains methods and other services that help with interacting
Expand All @@ -40,7 +42,7 @@ func NewAccountService(opts ...option.RequestOption) (r *AccountService) {
}

// Update an existing account.
func (r *AccountService) Update(ctx context.Context, params AccountUpdateParams, opts ...option.RequestOption) (res *shared.UnnamedSchemaRef9444735ca60712dbcf8afd832eb5716aUnion, err error) {
func (r *AccountService) Update(ctx context.Context, params AccountUpdateParams, opts ...option.RequestOption) (res *AccountUpdateResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env AccountUpdateResponseEnvelope
path := fmt.Sprintf("accounts/%v", params.AccountID)
Expand Down Expand Up @@ -76,7 +78,7 @@ func (r *AccountService) ListAutoPaging(ctx context.Context, query AccountListPa
}

// Get information about a specific account that you are a member of.
func (r *AccountService) Get(ctx context.Context, query AccountGetParams, opts ...option.RequestOption) (res *shared.UnnamedSchemaRef9444735ca60712dbcf8afd832eb5716aUnion, err error) {
func (r *AccountService) Get(ctx context.Context, query AccountGetParams, opts ...option.RequestOption) (res *AccountGetResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env AccountGetResponseEnvelope
path := fmt.Sprintf("accounts/%v", query.AccountID)
Expand Down Expand Up @@ -185,22 +187,19 @@ func (r AccountSettingsDefaultNameservers) IsKnown() bool {
return false
}

type AccountListResponse = interface{}

type AccountUpdateParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
type AccountParam struct {
// Account name
Name param.Field[string] `json:"name,required"`
// Account settings
Settings param.Field[AccountUpdateParamsSettings] `json:"settings"`
Settings param.Field[AccountSettingsParam] `json:"settings"`
}

func (r AccountUpdateParams) MarshalJSON() (data []byte, err error) {
func (r AccountParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Account settings
type AccountUpdateParamsSettings struct {
type AccountSettingsParam struct {
// Specifies the default nameservers to be used for new zones added to this
// account.
//
Expand All @@ -211,7 +210,7 @@ type AccountUpdateParamsSettings struct {
// See
// [Custom Nameservers](https://developers.cloudflare.com/dns/additional-options/custom-nameservers/)
// for more information.
DefaultNameservers param.Field[AccountUpdateParamsSettingsDefaultNameservers] `json:"default_nameservers"`
DefaultNameservers param.Field[AccountSettingsDefaultNameservers] `json:"default_nameservers"`
// Indicates whether membership in this account requires that Two-Factor
// Authentication is enabled
EnforceTwofactor param.Field[bool] `json:"enforce_twofactor"`
Expand All @@ -222,40 +221,58 @@ type AccountUpdateParamsSettings struct {
UseAccountCustomNSByDefault param.Field[bool] `json:"use_account_custom_ns_by_default"`
}

func (r AccountUpdateParamsSettings) MarshalJSON() (data []byte, err error) {
func (r AccountSettingsParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Specifies the default nameservers to be used for new zones added to this
// account.
//
// - `cloudflare.standard` for Cloudflare-branded nameservers
// - `custom.account` for account custom nameservers
// - `custom.tenant` for tenant custom nameservers
//
// See
// [Custom Nameservers](https://developers.cloudflare.com/dns/additional-options/custom-nameservers/)
// for more information.
type AccountUpdateParamsSettingsDefaultNameservers string
// Union satisfied by [accounts.AccountUpdateResponseUnknown] or
// [shared.UnionString].
type AccountUpdateResponseUnion interface {
ImplementsAccountsAccountUpdateResponseUnion()
}

const (
AccountUpdateParamsSettingsDefaultNameserversCloudflareStandard AccountUpdateParamsSettingsDefaultNameservers = "cloudflare.standard"
AccountUpdateParamsSettingsDefaultNameserversCustomAccount AccountUpdateParamsSettingsDefaultNameservers = "custom.account"
AccountUpdateParamsSettingsDefaultNameserversCustomTenant AccountUpdateParamsSettingsDefaultNameservers = "custom.tenant"
)
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AccountUpdateResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}

func (r AccountUpdateParamsSettingsDefaultNameservers) IsKnown() bool {
switch r {
case AccountUpdateParamsSettingsDefaultNameserversCloudflareStandard, AccountUpdateParamsSettingsDefaultNameserversCustomAccount, AccountUpdateParamsSettingsDefaultNameserversCustomTenant:
return true
}
return false
type AccountListResponse = interface{}

// Union satisfied by [accounts.AccountGetResponseUnknown] or [shared.UnionString].
type AccountGetResponseUnion interface {
ImplementsAccountsAccountGetResponseUnion()
}

func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AccountGetResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}

type AccountUpdateParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
Account AccountParam `json:"account,required"`
}

func (r AccountUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Account)
}

type AccountUpdateResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result shared.UnnamedSchemaRef9444735ca60712dbcf8afd832eb5716aUnion `json:"result,required"`
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result AccountUpdateResponseUnion `json:"result,required"`
// Whether the API call was successful
Success AccountUpdateResponseEnvelopeSuccess `json:"success,required"`
JSON accountUpdateResponseEnvelopeJSON `json:"-"`
Expand Down Expand Up @@ -335,9 +352,9 @@ type AccountGetParams struct {
}

type AccountGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result shared.UnnamedSchemaRef9444735ca60712dbcf8afd832eb5716aUnion `json:"result,required"`
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result AccountGetResponseUnion `json:"result,required"`
// Whether the API call was successful
Success AccountGetResponseEnvelopeSuccess `json:"success,required"`
JSON accountGetResponseEnvelopeJSON `json:"-"`
Expand Down
14 changes: 8 additions & 6 deletions accounts/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ func TestAccountUpdateWithOptionalParams(t *testing.T) {
)
_, err := client.Accounts.Update(context.TODO(), accounts.AccountUpdateParams{
AccountID: cloudflare.F[any](map[string]interface{}{}),
Name: cloudflare.F("Demo Account"),
Settings: cloudflare.F(accounts.AccountUpdateParamsSettings{
DefaultNameservers: cloudflare.F(accounts.AccountUpdateParamsSettingsDefaultNameserversCloudflareStandard),
EnforceTwofactor: cloudflare.F(true),
UseAccountCustomNSByDefault: cloudflare.F(true),
}),
Account: accounts.AccountParam{
Name: cloudflare.F("Demo Account"),
Settings: cloudflare.F(accounts.AccountSettingsParam{
DefaultNameservers: cloudflare.F(accounts.AccountSettingsDefaultNameserversCloudflareStandard),
EnforceTwofactor: cloudflare.F(true),
UseAccountCustomNSByDefault: cloudflare.F(true),
}),
},
})
if err != nil {
var apierr *cloudflare.Error
Expand Down
18 changes: 0 additions & 18 deletions accounts/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,3 @@ type ResponseInfo = shared.ResponseInfo

// This is an alias to an internal type.
type ResponseInfoParam = shared.ResponseInfoParam

// An object configuring the rule's logging behavior.
//
// This is an alias to an internal type.
type UnnamedSchemaRef70f2c6ccd8a405358ac7ef8fc3d6751c = shared.UnnamedSchemaRef70f2c6ccd8a405358ac7ef8fc3d6751c

// An object configuring the rule's logging behavior.
//
// This is an alias to an internal type.
type UnnamedSchemaRef70f2c6ccd8a405358ac7ef8fc3d6751cParam = shared.UnnamedSchemaRef70f2c6ccd8a405358ac7ef8fc3d6751cParam

// This is an alias to an internal type.
type UnnamedSchemaRef9444735ca60712dbcf8afd832eb5716aUnion = shared.UnnamedSchemaRef9444735ca60712dbcf8afd832eb5716aUnion

// JSON encoded metadata about the uploaded parts and Worker configuration.
//
// This is an alias to an internal type.
type UnnamedSchemaRefEe1e79edcb234d14c4dd266880f2fd24Param = shared.UnnamedSchemaRefEe1e79edcb234d14c4dd266880f2fd24Param
85 changes: 53 additions & 32 deletions accounts/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,56 @@ func (r memberUserJSON) RawJSON() string {
return r.raw
}

type MemberParam struct {
// Roles assigned to this member.
Roles param.Field[[]MemberRoleParam] `json:"roles,required"`
}

func (r MemberParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberRoleParam struct {
// Role identifier tag.
ID param.Field[string] `json:"id,required"`
}

func (r MemberRoleParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberRolesPermissionsParam struct {
Analytics param.Field[PermissionGrantParam] `json:"analytics"`
Billing param.Field[PermissionGrantParam] `json:"billing"`
CachePurge param.Field[PermissionGrantParam] `json:"cache_purge"`
DNS param.Field[PermissionGrantParam] `json:"dns"`
DNSRecords param.Field[PermissionGrantParam] `json:"dns_records"`
Lb param.Field[PermissionGrantParam] `json:"lb"`
Logs param.Field[PermissionGrantParam] `json:"logs"`
Organization param.Field[PermissionGrantParam] `json:"organization"`
SSL param.Field[PermissionGrantParam] `json:"ssl"`
WAF param.Field[PermissionGrantParam] `json:"waf"`
ZoneSettings param.Field[PermissionGrantParam] `json:"zone_settings"`
Zones param.Field[PermissionGrantParam] `json:"zones"`
}

func (r MemberRolesPermissionsParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberUserParam struct {
// The contact email address of the user.
Email param.Field[string] `json:"email,required"`
// User's first name
FirstName param.Field[string] `json:"first_name"`
// User's last name
LastName param.Field[string] `json:"last_name"`
}

func (r MemberUserParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberWithInviteCode struct {
// Membership identifier tag.
ID string `json:"id,required"`
Expand Down Expand Up @@ -560,40 +610,11 @@ func (r MemberNewResponseEnvelopeSuccess) IsKnown() bool {

type MemberUpdateParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
// Roles assigned to this member.
Roles param.Field[[]MemberUpdateParamsRole] `json:"roles,required"`
Member MemberParam `json:"member,required"`
}

func (r MemberUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberUpdateParamsRole struct {
// Role identifier tag.
ID param.Field[string] `json:"id,required"`
}

func (r MemberUpdateParamsRole) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberUpdateParamsRolesPermissions struct {
Analytics param.Field[PermissionGrantParam] `json:"analytics"`
Billing param.Field[PermissionGrantParam] `json:"billing"`
CachePurge param.Field[PermissionGrantParam] `json:"cache_purge"`
DNS param.Field[PermissionGrantParam] `json:"dns"`
DNSRecords param.Field[PermissionGrantParam] `json:"dns_records"`
Lb param.Field[PermissionGrantParam] `json:"lb"`
Logs param.Field[PermissionGrantParam] `json:"logs"`
Organization param.Field[PermissionGrantParam] `json:"organization"`
SSL param.Field[PermissionGrantParam] `json:"ssl"`
WAF param.Field[PermissionGrantParam] `json:"waf"`
ZoneSettings param.Field[PermissionGrantParam] `json:"zone_settings"`
Zones param.Field[PermissionGrantParam] `json:"zones"`
}

func (r MemberUpdateParamsRolesPermissions) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
return apijson.MarshalRoot(r.Member)
}

type MemberUpdateResponseEnvelope struct {
Expand Down Expand Up @@ -714,7 +735,7 @@ func (r MemberListParamsStatus) IsKnown() bool {

type MemberDeleteParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
Body param.Field[interface{}] `json:"body,required"`
Body interface{} `json:"body,required"`
}

func (r MemberDeleteParams) MarshalJSON() (data []byte, err error) {
Expand Down
18 changes: 10 additions & 8 deletions accounts/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ func TestMemberUpdate(t *testing.T) {
"4536bcfad5faccb111b47003c79917fa",
accounts.MemberUpdateParams{
AccountID: cloudflare.F[any](map[string]interface{}{}),
Roles: cloudflare.F([]accounts.MemberUpdateParamsRole{{
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}, {
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}, {
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}}),
Member: accounts.MemberParam{
Roles: cloudflare.F([]accounts.MemberRoleParam{{
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}, {
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}, {
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}}),
},
},
)
if err != nil {
Expand Down Expand Up @@ -130,7 +132,7 @@ func TestMemberDelete(t *testing.T) {
"4536bcfad5faccb111b47003c79917fa",
accounts.MemberDeleteParams{
AccountID: cloudflare.F[any](map[string]interface{}{}),
Body: cloudflare.F[any](map[string]interface{}{}),
Body: map[string]interface{}{},
},
)
if err != nil {
Expand Down
Loading

0 comments on commit 63baef8

Please sign in to comment.