Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#2509)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Jun 14, 2024
1 parent 36bfe19 commit 5c488a9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 85 deletions.
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Methods:
Params Types:

- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/user">user</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/user#CIDRListParam">CIDRListParam</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/user">user</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/user#PolicyParam">PolicyParam</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/user">user</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/user#TokenParam">TokenParam</a>

Response Types:
Expand Down
102 changes: 31 additions & 71 deletions user/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,62 +131,62 @@ func (r *TokenService) Verify(ctx context.Context, opts ...option.RequestOption)

type CIDRListParam = string

type TokenParam struct {
// Token name.
Name param.Field[string] `json:"name,required"`
// List of access policies assigned to the token.
Policies param.Field[[]TokenPolicyParam] `json:"policies,required"`
// Status of the token.
Status param.Field[TokenStatus] `json:"status,required"`
Condition param.Field[TokenConditionParam] `json:"condition"`
// The expiration time on or after which the JWT MUST NOT be accepted for
// processing.
ExpiresOn param.Field[time.Time] `json:"expires_on" format:"date-time"`
// The time before which the token MUST NOT be accepted for processing.
NotBefore param.Field[time.Time] `json:"not_before" format:"date-time"`
}

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

type TokenPolicyParam struct {
type PolicyParam struct {
// Allow or deny operations against the resources.
Effect param.Field[TokenPoliciesEffect] `json:"effect,required"`
Effect param.Field[PolicyEffect] `json:"effect,required"`
// A set of permission groups that are specified to the policy.
PermissionGroups param.Field[[]TokenPoliciesPermissionGroupParam] `json:"permission_groups,required"`
PermissionGroups param.Field[[]PolicyPermissionGroupParam] `json:"permission_groups,required"`
// A list of resource names that the policy applies to.
Resources param.Field[interface{}] `json:"resources,required"`
}

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

// Allow or deny operations against the resources.
type TokenPoliciesEffect string
type PolicyEffect string

const (
TokenPoliciesEffectAllow TokenPoliciesEffect = "allow"
TokenPoliciesEffectDeny TokenPoliciesEffect = "deny"
PolicyEffectAllow PolicyEffect = "allow"
PolicyEffectDeny PolicyEffect = "deny"
)

func (r TokenPoliciesEffect) IsKnown() bool {
func (r PolicyEffect) IsKnown() bool {
switch r {
case TokenPoliciesEffectAllow, TokenPoliciesEffectDeny:
case PolicyEffectAllow, PolicyEffectDeny:
return true
}
return false
}

// A named group of permissions that map to a group of operations against
// resources.
type TokenPoliciesPermissionGroupParam struct {
type PolicyPermissionGroupParam struct {
// Attributes associated to the permission group.
Meta param.Field[interface{}] `json:"meta"`
}

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

type TokenParam struct {
// Token name.
Name param.Field[string] `json:"name,required"`
// List of access policies assigned to the token.
Policies param.Field[[]PolicyParam] `json:"policies,required"`
// Status of the token.
Status param.Field[TokenStatus] `json:"status,required"`
Condition param.Field[TokenConditionParam] `json:"condition"`
// The expiration time on or after which the JWT MUST NOT be accepted for
// processing.
ExpiresOn param.Field[time.Time] `json:"expires_on" format:"date-time"`
// The time before which the token MUST NOT be accepted for processing.
NotBefore param.Field[time.Time] `json:"not_before" format:"date-time"`
}

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

Expand Down Expand Up @@ -331,7 +331,7 @@ type TokenNewParams struct {
// Token name.
Name param.Field[string] `json:"name,required"`
// List of access policies assigned to the token.
Policies param.Field[[]TokenNewParamsPolicy] `json:"policies,required"`
Policies param.Field[[]PolicyParam] `json:"policies,required"`
Condition param.Field[TokenNewParamsCondition] `json:"condition"`
// The expiration time on or after which the JWT MUST NOT be accepted for
// processing.
Expand All @@ -344,46 +344,6 @@ func (r TokenNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type TokenNewParamsPolicy struct {
// Allow or deny operations against the resources.
Effect param.Field[TokenNewParamsPoliciesEffect] `json:"effect,required"`
// A set of permission groups that are specified to the policy.
PermissionGroups param.Field[[]TokenNewParamsPoliciesPermissionGroup] `json:"permission_groups,required"`
// A list of resource names that the policy applies to.
Resources param.Field[interface{}] `json:"resources,required"`
}

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

// Allow or deny operations against the resources.
type TokenNewParamsPoliciesEffect string

const (
TokenNewParamsPoliciesEffectAllow TokenNewParamsPoliciesEffect = "allow"
TokenNewParamsPoliciesEffectDeny TokenNewParamsPoliciesEffect = "deny"
)

func (r TokenNewParamsPoliciesEffect) IsKnown() bool {
switch r {
case TokenNewParamsPoliciesEffectAllow, TokenNewParamsPoliciesEffectDeny:
return true
}
return false
}

// A named group of permissions that map to a group of operations against
// resources.
type TokenNewParamsPoliciesPermissionGroup struct {
// Attributes associated to the permission group.
Meta param.Field[interface{}] `json:"meta"`
}

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

type TokenNewParamsCondition struct {
// Client IP restrictions.
RequestIP param.Field[TokenNewParamsConditionRequestIP] `json:"request_ip"`
Expand Down
28 changes: 14 additions & 14 deletions user/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func TestTokenNewWithOptionalParams(t *testing.T) {
)
_, err := client.User.Tokens.New(context.TODO(), user.TokenNewParams{
Name: cloudflare.F("readonly token"),
Policies: cloudflare.F([]user.TokenNewParamsPolicy{{
Effect: cloudflare.F(user.TokenNewParamsPoliciesEffectAllow),
PermissionGroups: cloudflare.F([]user.TokenNewParamsPoliciesPermissionGroup{{
Policies: cloudflare.F([]user.PolicyParam{{
Effect: cloudflare.F(user.PolicyEffectAllow),
PermissionGroups: cloudflare.F([]user.PolicyPermissionGroupParam{{
Meta: cloudflare.F[any](map[string]interface{}{
"label": "load_balancer_admin",
"scopes": "com.cloudflare.api.account",
Expand All @@ -49,8 +49,8 @@ func TestTokenNewWithOptionalParams(t *testing.T) {
"com.cloudflare.api.account.zone.eb78d65290b24279ba6f44721b3ea3c4": "*",
}),
}, {
Effect: cloudflare.F(user.TokenNewParamsPoliciesEffectAllow),
PermissionGroups: cloudflare.F([]user.TokenNewParamsPoliciesPermissionGroup{{
Effect: cloudflare.F(user.PolicyEffectAllow),
PermissionGroups: cloudflare.F([]user.PolicyPermissionGroupParam{{
Meta: cloudflare.F[any](map[string]interface{}{
"label": "load_balancer_admin",
"scopes": "com.cloudflare.api.account",
Expand All @@ -66,8 +66,8 @@ func TestTokenNewWithOptionalParams(t *testing.T) {
"com.cloudflare.api.account.zone.eb78d65290b24279ba6f44721b3ea3c4": "*",
}),
}, {
Effect: cloudflare.F(user.TokenNewParamsPoliciesEffectAllow),
PermissionGroups: cloudflare.F([]user.TokenNewParamsPoliciesPermissionGroup{{
Effect: cloudflare.F(user.PolicyEffectAllow),
PermissionGroups: cloudflare.F([]user.PolicyPermissionGroupParam{{
Meta: cloudflare.F[any](map[string]interface{}{
"label": "load_balancer_admin",
"scopes": "com.cloudflare.api.account",
Expand Down Expand Up @@ -129,9 +129,9 @@ func TestTokenUpdateWithOptionalParams(t *testing.T) {
ExpiresOn: cloudflare.F(time.Now()),
Name: cloudflare.F("readonly token"),
NotBefore: cloudflare.F(time.Now()),
Policies: cloudflare.F([]user.TokenPolicyParam{{
Effect: cloudflare.F(user.TokenPoliciesEffectAllow),
PermissionGroups: cloudflare.F([]user.TokenPoliciesPermissionGroupParam{{
Policies: cloudflare.F([]user.PolicyParam{{
Effect: cloudflare.F(user.PolicyEffectAllow),
PermissionGroups: cloudflare.F([]user.PolicyPermissionGroupParam{{
Meta: cloudflare.F[any](map[string]interface{}{
"label": "load_balancer_admin",
"scopes": "com.cloudflare.api.account",
Expand All @@ -147,8 +147,8 @@ func TestTokenUpdateWithOptionalParams(t *testing.T) {
"com.cloudflare.api.account.zone.eb78d65290b24279ba6f44721b3ea3c4": "*",
}),
}, {
Effect: cloudflare.F(user.TokenPoliciesEffectAllow),
PermissionGroups: cloudflare.F([]user.TokenPoliciesPermissionGroupParam{{
Effect: cloudflare.F(user.PolicyEffectAllow),
PermissionGroups: cloudflare.F([]user.PolicyPermissionGroupParam{{
Meta: cloudflare.F[any](map[string]interface{}{
"label": "load_balancer_admin",
"scopes": "com.cloudflare.api.account",
Expand All @@ -164,8 +164,8 @@ func TestTokenUpdateWithOptionalParams(t *testing.T) {
"com.cloudflare.api.account.zone.eb78d65290b24279ba6f44721b3ea3c4": "*",
}),
}, {
Effect: cloudflare.F(user.TokenPoliciesEffectAllow),
PermissionGroups: cloudflare.F([]user.TokenPoliciesPermissionGroupParam{{
Effect: cloudflare.F(user.PolicyEffectAllow),
PermissionGroups: cloudflare.F([]user.PolicyPermissionGroupParam{{
Meta: cloudflare.F[any](map[string]interface{}{
"label": "load_balancer_admin",
"scopes": "com.cloudflare.api.account",
Expand Down

0 comments on commit 5c488a9

Please sign in to comment.