Skip to content

Commit

Permalink
feat(api_token_permission_groups): define get operation for datasou…
Browse files Browse the repository at this point in the history
…rces (#3900)
  • Loading branch information
stainless-app[bot] committed Feb 5, 2025
1 parent 6a3c2e1 commit 1550391
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions accounts/tokenpermissiongroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
26 changes: 26 additions & 0 deletions accounts/tokenpermissiongroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]"),
)
_, 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())
}
}
10 changes: 10 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ Methods:
Response Types:

- <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/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>

Methods:

- <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>
- <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>

### Value

Expand Down Expand Up @@ -750,6 +752,14 @@ Methods:

## Recommendations

Response Types:

- <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>

Methods:

- <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>

## Universal

### Settings
Expand Down
111 changes: 111 additions & 0 deletions ssl/recommendation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
37 changes: 37 additions & 0 deletions ssl/recommendation_test.go
Original file line number Diff line number Diff line change
@@ -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("[email protected]"),
)
_, 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())
}
}

0 comments on commit 1550391

Please sign in to comment.