From 5c488a9037a1e8d24c7068819d0510694f626331 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Fri, 14 Jun 2024 04:47:29 +0000
Subject: [PATCH] feat(api): update via SDK Studio (#2509)
---
api.md | 1 +
user/token.go | 102 ++++++++++++++-------------------------------
user/token_test.go | 28 ++++++-------
3 files changed, 46 insertions(+), 85 deletions(-)
diff --git a/api.md b/api.md
index bd8cbef6d39..93725a55387 100644
--- a/api.md
+++ b/api.md
@@ -212,6 +212,7 @@ Methods:
Params Types:
- user.CIDRListParam
+- user.PolicyParam
- user.TokenParam
Response Types:
diff --git a/user/token.go b/user/token.go
index 0a183decf07..45cec627c3d 100644
--- a/user/token.go
+++ b/user/token.go
@@ -131,49 +131,30 @@ 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
@@ -181,12 +162,31 @@ func (r TokenPoliciesEffect) IsKnown() bool {
// 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)
}
@@ -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.
@@ -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"`
diff --git a/user/token_test.go b/user/token_test.go
index 8c0d02efaa7..0def720b0fc 100644
--- a/user/token_test.go
+++ b/user/token_test.go
@@ -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",
@@ -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",
@@ -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",
@@ -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",
@@ -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",
@@ -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",