From 15503913ec67ba4d89e37f430e07c2e6b4892ef9 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Wed, 5 Feb 2025 23:40:22 +0000
Subject: [PATCH] feat(api_token_permission_groups): define `get` operation for
datasources (#3900)
---
.stats.yml | 4 +-
accounts/tokenpermissiongroup.go | 34 ++++++++
accounts/tokenpermissiongroup_test.go | 26 ++++++
api.md | 10 +++
ssl/recommendation.go | 111 ++++++++++++++++++++++++++
ssl/recommendation_test.go | 37 +++++++++
6 files changed, 220 insertions(+), 2 deletions(-)
create mode 100644 ssl/recommendation_test.go
diff --git a/.stats.yml b/.stats.yml
index 7cd6eed1290..f3c978f2e90 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,2 +1,2 @@
-configured_endpoints: 1524
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-aa93097d3c029937a6c5f40f1de4e577b20ec66ff43fa27c110f6cd3ea718704.yml
+configured_endpoints: 1525
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-b9c3a90028bf6b940420332aee2ee13b3cf1fa04e607205d7efe8fdb1c7d41e8.yml
diff --git a/accounts/tokenpermissiongroup.go b/accounts/tokenpermissiongroup.go
index 224f568345e..d49e6a67527 100644
--- a/accounts/tokenpermissiongroup.go
+++ b/accounts/tokenpermissiongroup.go
@@ -60,9 +60,43 @@ func (r *TokenPermissionGroupService) ListAutoPaging(ctx context.Context, query
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}
+// Find all available permission groups for Account Owned API Tokens
+func (r *TokenPermissionGroupService) Get(ctx context.Context, query TokenPermissionGroupGetParams, opts ...option.RequestOption) (res *pagination.SinglePage[TokenPermissionGroupGetResponse], err error) {
+ var raw *http.Response
+ opts = append(r.Options[:], opts...)
+ opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
+ if query.AccountID.Value == "" {
+ err = errors.New("missing required account_id parameter")
+ return
+ }
+ path := fmt.Sprintf("accounts/%s/tokens/permission_groups", query.AccountID)
+ cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, nil, &res, opts...)
+ if err != nil {
+ return nil, err
+ }
+ err = cfg.Execute()
+ if err != nil {
+ return nil, err
+ }
+ res.SetPageConfig(cfg, raw)
+ return res, nil
+}
+
+// Find all available permission groups for Account Owned API Tokens
+func (r *TokenPermissionGroupService) GetAutoPaging(ctx context.Context, query TokenPermissionGroupGetParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[TokenPermissionGroupGetResponse] {
+ return pagination.NewSinglePageAutoPager(r.Get(ctx, query, opts...))
+}
+
type TokenPermissionGroupListResponse = interface{}
+type TokenPermissionGroupGetResponse = interface{}
+
type TokenPermissionGroupListParams struct {
// Account identifier tag.
AccountID param.Field[string] `path:"account_id,required"`
}
+
+type TokenPermissionGroupGetParams struct {
+ // Account identifier tag.
+ AccountID param.Field[string] `path:"account_id,required"`
+}
diff --git a/accounts/tokenpermissiongroup_test.go b/accounts/tokenpermissiongroup_test.go
index 11cda3d68f8..108fad98379 100644
--- a/accounts/tokenpermissiongroup_test.go
+++ b/accounts/tokenpermissiongroup_test.go
@@ -39,3 +39,29 @@ func TestTokenPermissionGroupList(t *testing.T) {
t.Fatalf("err should be nil: %s", err.Error())
}
}
+
+func TestTokenPermissionGroupGet(t *testing.T) {
+ t.Skip("TODO: investigate broken test")
+ baseURL := "http://localhost:4010"
+ if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
+ baseURL = envURL
+ }
+ if !testutil.CheckTestServer(t, baseURL) {
+ return
+ }
+ client := cloudflare.NewClient(
+ option.WithBaseURL(baseURL),
+ option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
+ option.WithAPIEmail("user@example.com"),
+ )
+ _, err := client.Accounts.Tokens.PermissionGroups.Get(context.TODO(), accounts.TokenPermissionGroupGetParams{
+ AccountID: cloudflare.F("eb78d65290b24279ba6f44721b3ea3c4"),
+ })
+ if err != nil {
+ var apierr *cloudflare.Error
+ if errors.As(err, &apierr) {
+ t.Log(string(apierr.DumpRequest(true)))
+ }
+ t.Fatalf("err should be nil: %s", err.Error())
+ }
+}
diff --git a/api.md b/api.md
index df951795dd2..785996e2d9b 100644
--- a/api.md
+++ b/api.md
@@ -108,10 +108,12 @@ Methods:
Response Types:
- accounts.TokenPermissionGroupListResponse
+- accounts.TokenPermissionGroupGetResponse
Methods:
- client.Accounts.Tokens.PermissionGroups.List(ctx context.Context, query accounts.TokenPermissionGroupListParams) (pagination.SinglePage[accounts.TokenPermissionGroupListResponse], error)
+- client.Accounts.Tokens.PermissionGroups.Get(ctx context.Context, query accounts.TokenPermissionGroupGetParams) (pagination.SinglePage[accounts.TokenPermissionGroupGetResponse], error)
### Value
@@ -750,6 +752,14 @@ Methods:
## Recommendations
+Response Types:
+
+- ssl.RecommendationGetResponse
+
+Methods:
+
+- client.SSL.Recommendations.Get(ctx context.Context, zoneIdentifier string) (ssl.RecommendationGetResponse, error)
+
## Universal
### Settings
diff --git a/ssl/recommendation.go b/ssl/recommendation.go
index b096951b10b..3874e9cd948 100644
--- a/ssl/recommendation.go
+++ b/ssl/recommendation.go
@@ -3,7 +3,16 @@
package ssl
import (
+ "context"
+ "errors"
+ "fmt"
+ "net/http"
+ "time"
+
+ "github.com/cloudflare/cloudflare-go/v4/internal/apijson"
+ "github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v4/option"
+ "github.com/cloudflare/cloudflare-go/v4/shared"
)
// RecommendationService contains methods and other services that help with
@@ -24,3 +33,105 @@ func NewRecommendationService(opts ...option.RequestOption) (r *RecommendationSe
r.Options = opts
return
}
+
+// Retrieve the SSL/TLS Recommender's recommendation for a zone.
+func (r *RecommendationService) Get(ctx context.Context, zoneIdentifier string, opts ...option.RequestOption) (res *RecommendationGetResponse, err error) {
+ var env RecommendationGetResponseEnvelope
+ opts = append(r.Options[:], opts...)
+ if zoneIdentifier == "" {
+ err = errors.New("missing required zone_identifier parameter")
+ return
+ }
+ path := fmt.Sprintf("zones/%s/ssl/recommendation", zoneIdentifier)
+ err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
+ if err != nil {
+ return
+ }
+ res = &env.Result
+ return
+}
+
+type RecommendationGetResponse struct {
+ // Identifier of a recommedation result.
+ ID string `json:"id"`
+ ModifiedOn time.Time `json:"modified_on" format:"date-time"`
+ Value RecommendationGetResponseValue `json:"value"`
+ JSON recommendationGetResponseJSON `json:"-"`
+}
+
+// recommendationGetResponseJSON contains the JSON metadata for the struct
+// [RecommendationGetResponse]
+type recommendationGetResponseJSON struct {
+ ID apijson.Field
+ ModifiedOn apijson.Field
+ Value apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *RecommendationGetResponse) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r recommendationGetResponseJSON) RawJSON() string {
+ return r.raw
+}
+
+type RecommendationGetResponseValue string
+
+const (
+ RecommendationGetResponseValueFlexible RecommendationGetResponseValue = "flexible"
+ RecommendationGetResponseValueFull RecommendationGetResponseValue = "full"
+ RecommendationGetResponseValueStrict RecommendationGetResponseValue = "strict"
+)
+
+func (r RecommendationGetResponseValue) IsKnown() bool {
+ switch r {
+ case RecommendationGetResponseValueFlexible, RecommendationGetResponseValueFull, RecommendationGetResponseValueStrict:
+ return true
+ }
+ return false
+}
+
+type RecommendationGetResponseEnvelope struct {
+ Errors []shared.ResponseInfo `json:"errors,required"`
+ Messages []shared.ResponseInfo `json:"messages,required"`
+ Result RecommendationGetResponse `json:"result,required,nullable"`
+ // Whether the API call was successful
+ Success RecommendationGetResponseEnvelopeSuccess `json:"success,required"`
+ JSON recommendationGetResponseEnvelopeJSON `json:"-"`
+}
+
+// recommendationGetResponseEnvelopeJSON contains the JSON metadata for the struct
+// [RecommendationGetResponseEnvelope]
+type recommendationGetResponseEnvelopeJSON struct {
+ Errors apijson.Field
+ Messages apijson.Field
+ Result apijson.Field
+ Success apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *RecommendationGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r recommendationGetResponseEnvelopeJSON) RawJSON() string {
+ return r.raw
+}
+
+// Whether the API call was successful
+type RecommendationGetResponseEnvelopeSuccess bool
+
+const (
+ RecommendationGetResponseEnvelopeSuccessTrue RecommendationGetResponseEnvelopeSuccess = true
+)
+
+func (r RecommendationGetResponseEnvelopeSuccess) IsKnown() bool {
+ switch r {
+ case RecommendationGetResponseEnvelopeSuccessTrue:
+ return true
+ }
+ return false
+}
diff --git a/ssl/recommendation_test.go b/ssl/recommendation_test.go
new file mode 100644
index 00000000000..0354e272fdf
--- /dev/null
+++ b/ssl/recommendation_test.go
@@ -0,0 +1,37 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+package ssl_test
+
+import (
+ "context"
+ "errors"
+ "os"
+ "testing"
+
+ "github.com/cloudflare/cloudflare-go/v4"
+ "github.com/cloudflare/cloudflare-go/v4/internal/testutil"
+ "github.com/cloudflare/cloudflare-go/v4/option"
+)
+
+func TestRecommendationGet(t *testing.T) {
+ baseURL := "http://localhost:4010"
+ if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
+ baseURL = envURL
+ }
+ if !testutil.CheckTestServer(t, baseURL) {
+ return
+ }
+ client := cloudflare.NewClient(
+ option.WithBaseURL(baseURL),
+ option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
+ option.WithAPIEmail("user@example.com"),
+ )
+ _, err := client.SSL.Recommendations.Get(context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353")
+ if err != nil {
+ var apierr *cloudflare.Error
+ if errors.As(err, &apierr) {
+ t.Log(string(apierr.DumpRequest(true)))
+ }
+ t.Fatalf("err should be nil: %s", err.Error())
+ }
+}