Skip to content

Commit 1550391

Browse files
committedFeb 5, 2025
feat(api_token_permission_groups): define get operation for datasources (#3900)
1 parent 6a3c2e1 commit 1550391

6 files changed

+220
-2
lines changed
 

‎.stats.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1524
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-aa93097d3c029937a6c5f40f1de4e577b20ec66ff43fa27c110f6cd3ea718704.yml
1+
configured_endpoints: 1525
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-b9c3a90028bf6b940420332aee2ee13b3cf1fa04e607205d7efe8fdb1c7d41e8.yml

‎accounts/tokenpermissiongroup.go

+34
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,43 @@ func (r *TokenPermissionGroupService) ListAutoPaging(ctx context.Context, query
6060
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
6161
}
6262

63+
// Find all available permission groups for Account Owned API Tokens
64+
func (r *TokenPermissionGroupService) Get(ctx context.Context, query TokenPermissionGroupGetParams, opts ...option.RequestOption) (res *pagination.SinglePage[TokenPermissionGroupGetResponse], err error) {
65+
var raw *http.Response
66+
opts = append(r.Options[:], opts...)
67+
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
68+
if query.AccountID.Value == "" {
69+
err = errors.New("missing required account_id parameter")
70+
return
71+
}
72+
path := fmt.Sprintf("accounts/%s/tokens/permission_groups", query.AccountID)
73+
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, nil, &res, opts...)
74+
if err != nil {
75+
return nil, err
76+
}
77+
err = cfg.Execute()
78+
if err != nil {
79+
return nil, err
80+
}
81+
res.SetPageConfig(cfg, raw)
82+
return res, nil
83+
}
84+
85+
// Find all available permission groups for Account Owned API Tokens
86+
func (r *TokenPermissionGroupService) GetAutoPaging(ctx context.Context, query TokenPermissionGroupGetParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[TokenPermissionGroupGetResponse] {
87+
return pagination.NewSinglePageAutoPager(r.Get(ctx, query, opts...))
88+
}
89+
6390
type TokenPermissionGroupListResponse = interface{}
6491

92+
type TokenPermissionGroupGetResponse = interface{}
93+
6594
type TokenPermissionGroupListParams struct {
6695
// Account identifier tag.
6796
AccountID param.Field[string] `path:"account_id,required"`
6897
}
98+
99+
type TokenPermissionGroupGetParams struct {
100+
// Account identifier tag.
101+
AccountID param.Field[string] `path:"account_id,required"`
102+
}

‎accounts/tokenpermissiongroup_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ func TestTokenPermissionGroupList(t *testing.T) {
3939
t.Fatalf("err should be nil: %s", err.Error())
4040
}
4141
}
42+
43+
func TestTokenPermissionGroupGet(t *testing.T) {
44+
t.Skip("TODO: investigate broken test")
45+
baseURL := "http://localhost:4010"
46+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
47+
baseURL = envURL
48+
}
49+
if !testutil.CheckTestServer(t, baseURL) {
50+
return
51+
}
52+
client := cloudflare.NewClient(
53+
option.WithBaseURL(baseURL),
54+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
55+
option.WithAPIEmail("user@example.com"),
56+
)
57+
_, err := client.Accounts.Tokens.PermissionGroups.Get(context.TODO(), accounts.TokenPermissionGroupGetParams{
58+
AccountID: cloudflare.F("eb78d65290b24279ba6f44721b3ea3c4"),
59+
})
60+
if err != nil {
61+
var apierr *cloudflare.Error
62+
if errors.As(err, &apierr) {
63+
t.Log(string(apierr.DumpRequest(true)))
64+
}
65+
t.Fatalf("err should be nil: %s", err.Error())
66+
}
67+
}

‎api.md

+10
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ Methods:
108108
Response Types:
109109

110110
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#TokenPermissionGroupListResponse">TokenPermissionGroupListResponse</a>
111+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#TokenPermissionGroupGetResponse">TokenPermissionGroupGetResponse</a>
111112

112113
Methods:
113114

114115
- <code title="get /accounts/{account_id}/tokens/permission_groups">client.Accounts.Tokens.PermissionGroups.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#TokenPermissionGroupService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#TokenPermissionGroupListParams">TokenPermissionGroupListParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination#SinglePage">SinglePage</a>[<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#TokenPermissionGroupListResponse">TokenPermissionGroupListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
116+
- <code title="get /accounts/{account_id}/tokens/permission_groups">client.Accounts.Tokens.PermissionGroups.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#TokenPermissionGroupService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#TokenPermissionGroupGetParams">TokenPermissionGroupGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination#SinglePage">SinglePage</a>[<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#TokenPermissionGroupGetResponse">TokenPermissionGroupGetResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
115117

116118
### Value
117119

@@ -750,6 +752,14 @@ Methods:
750752

751753
## Recommendations
752754

755+
Response Types:
756+
757+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl">ssl</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl#RecommendationGetResponse">RecommendationGetResponse</a>
758+
759+
Methods:
760+
761+
- <code title="get /zones/{zone_identifier}/ssl/recommendation">client.SSL.Recommendations.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl#RecommendationService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, zoneIdentifier <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl">ssl</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl#RecommendationGetResponse">RecommendationGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
762+
753763
## Universal
754764

755765
### Settings

‎ssl/recommendation.go

+111
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
package ssl
44

55
import (
6+
"context"
7+
"errors"
8+
"fmt"
9+
"net/http"
10+
"time"
11+
12+
"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
13+
"github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
614
"github.com/cloudflare/cloudflare-go/v4/option"
15+
"github.com/cloudflare/cloudflare-go/v4/shared"
716
)
817

918
// RecommendationService contains methods and other services that help with
@@ -24,3 +33,105 @@ func NewRecommendationService(opts ...option.RequestOption) (r *RecommendationSe
2433
r.Options = opts
2534
return
2635
}
36+
37+
// Retrieve the SSL/TLS Recommender's recommendation for a zone.
38+
func (r *RecommendationService) Get(ctx context.Context, zoneIdentifier string, opts ...option.RequestOption) (res *RecommendationGetResponse, err error) {
39+
var env RecommendationGetResponseEnvelope
40+
opts = append(r.Options[:], opts...)
41+
if zoneIdentifier == "" {
42+
err = errors.New("missing required zone_identifier parameter")
43+
return
44+
}
45+
path := fmt.Sprintf("zones/%s/ssl/recommendation", zoneIdentifier)
46+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
47+
if err != nil {
48+
return
49+
}
50+
res = &env.Result
51+
return
52+
}
53+
54+
type RecommendationGetResponse struct {
55+
// Identifier of a recommedation result.
56+
ID string `json:"id"`
57+
ModifiedOn time.Time `json:"modified_on" format:"date-time"`
58+
Value RecommendationGetResponseValue `json:"value"`
59+
JSON recommendationGetResponseJSON `json:"-"`
60+
}
61+
62+
// recommendationGetResponseJSON contains the JSON metadata for the struct
63+
// [RecommendationGetResponse]
64+
type recommendationGetResponseJSON struct {
65+
ID apijson.Field
66+
ModifiedOn apijson.Field
67+
Value apijson.Field
68+
raw string
69+
ExtraFields map[string]apijson.Field
70+
}
71+
72+
func (r *RecommendationGetResponse) UnmarshalJSON(data []byte) (err error) {
73+
return apijson.UnmarshalRoot(data, r)
74+
}
75+
76+
func (r recommendationGetResponseJSON) RawJSON() string {
77+
return r.raw
78+
}
79+
80+
type RecommendationGetResponseValue string
81+
82+
const (
83+
RecommendationGetResponseValueFlexible RecommendationGetResponseValue = "flexible"
84+
RecommendationGetResponseValueFull RecommendationGetResponseValue = "full"
85+
RecommendationGetResponseValueStrict RecommendationGetResponseValue = "strict"
86+
)
87+
88+
func (r RecommendationGetResponseValue) IsKnown() bool {
89+
switch r {
90+
case RecommendationGetResponseValueFlexible, RecommendationGetResponseValueFull, RecommendationGetResponseValueStrict:
91+
return true
92+
}
93+
return false
94+
}
95+
96+
type RecommendationGetResponseEnvelope struct {
97+
Errors []shared.ResponseInfo `json:"errors,required"`
98+
Messages []shared.ResponseInfo `json:"messages,required"`
99+
Result RecommendationGetResponse `json:"result,required,nullable"`
100+
// Whether the API call was successful
101+
Success RecommendationGetResponseEnvelopeSuccess `json:"success,required"`
102+
JSON recommendationGetResponseEnvelopeJSON `json:"-"`
103+
}
104+
105+
// recommendationGetResponseEnvelopeJSON contains the JSON metadata for the struct
106+
// [RecommendationGetResponseEnvelope]
107+
type recommendationGetResponseEnvelopeJSON struct {
108+
Errors apijson.Field
109+
Messages apijson.Field
110+
Result apijson.Field
111+
Success apijson.Field
112+
raw string
113+
ExtraFields map[string]apijson.Field
114+
}
115+
116+
func (r *RecommendationGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
117+
return apijson.UnmarshalRoot(data, r)
118+
}
119+
120+
func (r recommendationGetResponseEnvelopeJSON) RawJSON() string {
121+
return r.raw
122+
}
123+
124+
// Whether the API call was successful
125+
type RecommendationGetResponseEnvelopeSuccess bool
126+
127+
const (
128+
RecommendationGetResponseEnvelopeSuccessTrue RecommendationGetResponseEnvelopeSuccess = true
129+
)
130+
131+
func (r RecommendationGetResponseEnvelopeSuccess) IsKnown() bool {
132+
switch r {
133+
case RecommendationGetResponseEnvelopeSuccessTrue:
134+
return true
135+
}
136+
return false
137+
}

‎ssl/recommendation_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package ssl_test
4+
5+
import (
6+
"context"
7+
"errors"
8+
"os"
9+
"testing"
10+
11+
"github.com/cloudflare/cloudflare-go/v4"
12+
"github.com/cloudflare/cloudflare-go/v4/internal/testutil"
13+
"github.com/cloudflare/cloudflare-go/v4/option"
14+
)
15+
16+
func TestRecommendationGet(t *testing.T) {
17+
baseURL := "http://localhost:4010"
18+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
19+
baseURL = envURL
20+
}
21+
if !testutil.CheckTestServer(t, baseURL) {
22+
return
23+
}
24+
client := cloudflare.NewClient(
25+
option.WithBaseURL(baseURL),
26+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
27+
option.WithAPIEmail("user@example.com"),
28+
)
29+
_, err := client.SSL.Recommendations.Get(context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353")
30+
if err != nil {
31+
var apierr *cloudflare.Error
32+
if errors.As(err, &apierr) {
33+
t.Log(string(apierr.DumpRequest(true)))
34+
}
35+
t.Fatalf("err should be nil: %s", err.Error())
36+
}
37+
}

0 commit comments

Comments
 (0)
Please sign in to comment.