Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df5cd91

Browse files
committedMar 13, 2025
feat(api): cloudforce one port scan APIs (#3978)
1 parent e3d71a9 commit df5cd91

9 files changed

+979
-2
lines changed
 

‎.stats.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1570
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-4ef7459c0be2e1b6d28303982b9691909dadc52b214cb490fcce792ba09b5089.yml
1+
configured_endpoints: 1574
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-57941121e4dcca4a3b62a9a160cb9961838e37d92d5b393f36695fad87c68a3f.yml

‎api.md

+26
Original file line numberDiff line numberDiff line change
@@ -8229,3 +8229,29 @@ Response Types:
82298229
Methods:
82308230

82318231
- <code title="post /accounts/{accountId}/browser-rendering/snapshot">client.BrowserRendering.Snapshot.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/browser_rendering#SnapshotService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, accountID <a href="https://pkg.go.dev/builtin#string">string</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/browser_rendering">browser_rendering</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/browser_rendering#SnapshotNewParams">SnapshotNewParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/browser_rendering">browser_rendering</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/browser_rendering#SnapshotNewResponse">SnapshotNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
8232+
8233+
# PortScans
8234+
8235+
## Config
8236+
8237+
Response Types:
8238+
8239+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigNewResponse">ConfigNewResponse</a>
8240+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigDeleteResponse">ConfigDeleteResponse</a>
8241+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigGetResponse">ConfigGetResponse</a>
8242+
8243+
Methods:
8244+
8245+
- <code title="post /{account_id}/scans/config">client.PortScans.Config.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigNewParams">ConfigNewParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigNewResponse">ConfigNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
8246+
- <code title="delete /{account_id}/scans/config">client.PortScans.Config.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigDeleteParams">ConfigDeleteParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigDeleteResponse">ConfigDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
8247+
- <code title="get /{account_id}/scans/config">client.PortScans.Config.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigService.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/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigGetParams">ConfigGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ConfigGetResponse">ConfigGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
8248+
8249+
## Results
8250+
8251+
Response Types:
8252+
8253+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ResultListResponse">ResultListResponse</a>
8254+
8255+
Methods:
8256+
8257+
- <code title="get /{account_id}/scans/results">client.PortScans.Results.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ResultService.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/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ResultListParams">ResultListParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans">port_scans</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/port_scans#ResultListResponse">ResultListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

‎client.go

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import (
6969
"github.com/cloudflare/cloudflare-go/v4/page_rules"
7070
"github.com/cloudflare/cloudflare-go/v4/page_shield"
7171
"github.com/cloudflare/cloudflare-go/v4/pages"
72+
"github.com/cloudflare/cloudflare-go/v4/port_scans"
7273
"github.com/cloudflare/cloudflare-go/v4/queues"
7374
"github.com/cloudflare/cloudflare-go/v4/r2"
7475
"github.com/cloudflare/cloudflare-go/v4/radar"
@@ -204,6 +205,7 @@ type Client struct {
204205
AI *ai.AIService
205206
SecurityCenter *security_center.SecurityCenterService
206207
BrowserRendering *browser_rendering.BrowserRenderingService
208+
PortScans *port_scans.PortScanService
207209
}
208210

209211
// NewClient generates a new client with the default option read from the
@@ -319,6 +321,7 @@ func NewClient(opts ...option.RequestOption) (r *Client) {
319321
r.AI = ai.NewAIService(opts...)
320322
r.SecurityCenter = security_center.NewSecurityCenterService(opts...)
321323
r.BrowserRendering = browser_rendering.NewBrowserRenderingService(opts...)
324+
r.PortScans = port_scans.NewPortScanService(opts...)
322325

323326
return
324327
}

‎port_scans/aliases.go

+418
Large diffs are not rendered by default.

‎port_scans/config.go

+239
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package port_scans
4+
5+
import (
6+
"context"
7+
"errors"
8+
"fmt"
9+
"net/http"
10+
11+
"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
12+
"github.com/cloudflare/cloudflare-go/v4/internal/param"
13+
"github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
14+
"github.com/cloudflare/cloudflare-go/v4/option"
15+
)
16+
17+
// ConfigService contains methods and other services that help with interacting
18+
// with the cloudflare API.
19+
//
20+
// Note, unlike clients, this service does not read variables from the environment
21+
// automatically. You should not instantiate this service directly, and instead use
22+
// the [NewConfigService] method instead.
23+
type ConfigService struct {
24+
Options []option.RequestOption
25+
}
26+
27+
// NewConfigService generates a new service that applies the given options to each
28+
// request. These options are applied after the parent client's options (if there
29+
// is one), and before any request-specific options.
30+
func NewConfigService(opts ...option.RequestOption) (r *ConfigService) {
31+
r = &ConfigService{}
32+
r.Options = opts
33+
return
34+
}
35+
36+
// Create a new Scan Config
37+
func (r *ConfigService) New(ctx context.Context, params ConfigNewParams, opts ...option.RequestOption) (res *ConfigNewResponse, err error) {
38+
var env ConfigNewResponseEnvelope
39+
opts = append(r.Options[:], opts...)
40+
if params.AccountID.Value == "" {
41+
err = errors.New("missing required account_id parameter")
42+
return
43+
}
44+
path := fmt.Sprintf("%s/scans/config", params.AccountID)
45+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
46+
if err != nil {
47+
return
48+
}
49+
res = &env.Result
50+
return
51+
}
52+
53+
// Delete the Scan Config for an Account
54+
func (r *ConfigService) Delete(ctx context.Context, body ConfigDeleteParams, opts ...option.RequestOption) (res *ConfigDeleteResponse, err error) {
55+
var env ConfigDeleteResponseEnvelope
56+
opts = append(r.Options[:], opts...)
57+
if body.AccountID.Value == "" {
58+
err = errors.New("missing required account_id parameter")
59+
return
60+
}
61+
path := fmt.Sprintf("%s/scans/config", body.AccountID)
62+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
63+
if err != nil {
64+
return
65+
}
66+
res = &env.Result
67+
return
68+
}
69+
70+
// Get the Scan Config for An Account
71+
func (r *ConfigService) Get(ctx context.Context, query ConfigGetParams, opts ...option.RequestOption) (res *ConfigGetResponse, err error) {
72+
var env ConfigGetResponseEnvelope
73+
opts = append(r.Options[:], opts...)
74+
if query.AccountID.Value == "" {
75+
err = errors.New("missing required account_id parameter")
76+
return
77+
}
78+
path := fmt.Sprintf("%s/scans/config", query.AccountID)
79+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
80+
if err != nil {
81+
return
82+
}
83+
res = &env.Result
84+
return
85+
}
86+
87+
type ConfigNewResponse struct {
88+
AccountID string `json:"account_id,required"`
89+
Frequency float64 `json:"frequency,required"`
90+
IPs []string `json:"ips,required"`
91+
JSON configNewResponseJSON `json:"-"`
92+
}
93+
94+
// configNewResponseJSON contains the JSON metadata for the struct
95+
// [ConfigNewResponse]
96+
type configNewResponseJSON struct {
97+
AccountID apijson.Field
98+
Frequency apijson.Field
99+
IPs apijson.Field
100+
raw string
101+
ExtraFields map[string]apijson.Field
102+
}
103+
104+
func (r *ConfigNewResponse) UnmarshalJSON(data []byte) (err error) {
105+
return apijson.UnmarshalRoot(data, r)
106+
}
107+
108+
func (r configNewResponseJSON) RawJSON() string {
109+
return r.raw
110+
}
111+
112+
type ConfigDeleteResponse = interface{}
113+
114+
type ConfigGetResponse struct {
115+
AccountID string `json:"account_id,required"`
116+
Frequency float64 `json:"frequency,required"`
117+
IPs []string `json:"ips,required"`
118+
JSON configGetResponseJSON `json:"-"`
119+
}
120+
121+
// configGetResponseJSON contains the JSON metadata for the struct
122+
// [ConfigGetResponse]
123+
type configGetResponseJSON struct {
124+
AccountID apijson.Field
125+
Frequency apijson.Field
126+
IPs apijson.Field
127+
raw string
128+
ExtraFields map[string]apijson.Field
129+
}
130+
131+
func (r *ConfigGetResponse) UnmarshalJSON(data []byte) (err error) {
132+
return apijson.UnmarshalRoot(data, r)
133+
}
134+
135+
func (r configGetResponseJSON) RawJSON() string {
136+
return r.raw
137+
}
138+
139+
type ConfigNewParams struct {
140+
// Account ID
141+
AccountID param.Field[string] `path:"account_id,required"`
142+
Frequency param.Field[float64] `json:"frequency,required"`
143+
IPs param.Field[[]string] `json:"ips,required"`
144+
}
145+
146+
func (r ConfigNewParams) MarshalJSON() (data []byte, err error) {
147+
return apijson.MarshalRoot(r)
148+
}
149+
150+
type ConfigNewResponseEnvelope struct {
151+
Errors []string `json:"errors,required"`
152+
Messages []string `json:"messages,required"`
153+
Result ConfigNewResponse `json:"result,required"`
154+
Success bool `json:"success,required"`
155+
JSON configNewResponseEnvelopeJSON `json:"-"`
156+
}
157+
158+
// configNewResponseEnvelopeJSON contains the JSON metadata for the struct
159+
// [ConfigNewResponseEnvelope]
160+
type configNewResponseEnvelopeJSON struct {
161+
Errors apijson.Field
162+
Messages apijson.Field
163+
Result apijson.Field
164+
Success apijson.Field
165+
raw string
166+
ExtraFields map[string]apijson.Field
167+
}
168+
169+
func (r *ConfigNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
170+
return apijson.UnmarshalRoot(data, r)
171+
}
172+
173+
func (r configNewResponseEnvelopeJSON) RawJSON() string {
174+
return r.raw
175+
}
176+
177+
type ConfigDeleteParams struct {
178+
// Account ID
179+
AccountID param.Field[string] `path:"account_id,required"`
180+
}
181+
182+
type ConfigDeleteResponseEnvelope struct {
183+
Errors []string `json:"errors,required"`
184+
Messages []string `json:"messages,required"`
185+
Result ConfigDeleteResponse `json:"result,required"`
186+
Success bool `json:"success,required"`
187+
JSON configDeleteResponseEnvelopeJSON `json:"-"`
188+
}
189+
190+
// configDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
191+
// [ConfigDeleteResponseEnvelope]
192+
type configDeleteResponseEnvelopeJSON struct {
193+
Errors apijson.Field
194+
Messages apijson.Field
195+
Result apijson.Field
196+
Success apijson.Field
197+
raw string
198+
ExtraFields map[string]apijson.Field
199+
}
200+
201+
func (r *ConfigDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
202+
return apijson.UnmarshalRoot(data, r)
203+
}
204+
205+
func (r configDeleteResponseEnvelopeJSON) RawJSON() string {
206+
return r.raw
207+
}
208+
209+
type ConfigGetParams struct {
210+
// Account ID
211+
AccountID param.Field[string] `path:"account_id,required"`
212+
}
213+
214+
type ConfigGetResponseEnvelope struct {
215+
Errors []string `json:"errors,required"`
216+
Messages []string `json:"messages,required"`
217+
Result ConfigGetResponse `json:"result,required"`
218+
Success bool `json:"success,required"`
219+
JSON configGetResponseEnvelopeJSON `json:"-"`
220+
}
221+
222+
// configGetResponseEnvelopeJSON contains the JSON metadata for the struct
223+
// [ConfigGetResponseEnvelope]
224+
type configGetResponseEnvelopeJSON struct {
225+
Errors apijson.Field
226+
Messages apijson.Field
227+
Result apijson.Field
228+
Success apijson.Field
229+
raw string
230+
ExtraFields map[string]apijson.Field
231+
}
232+
233+
func (r *ConfigGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
234+
return apijson.UnmarshalRoot(data, r)
235+
}
236+
237+
func (r configGetResponseEnvelopeJSON) RawJSON() string {
238+
return r.raw
239+
}

‎port_scans/config_test.go

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package port_scans_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+
"github.com/cloudflare/cloudflare-go/v4/port_scans"
15+
)
16+
17+
func TestConfigNew(t *testing.T) {
18+
baseURL := "http://localhost:4010"
19+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
20+
baseURL = envURL
21+
}
22+
if !testutil.CheckTestServer(t, baseURL) {
23+
return
24+
}
25+
client := cloudflare.NewClient(
26+
option.WithBaseURL(baseURL),
27+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
28+
option.WithAPIEmail("user@example.com"),
29+
)
30+
_, err := client.PortScans.Config.New(context.TODO(), port_scans.ConfigNewParams{
31+
AccountID: cloudflare.F("account_id"),
32+
Frequency: cloudflare.F(1.000000),
33+
IPs: cloudflare.F([]string{"1.1.1.1"}),
34+
})
35+
if err != nil {
36+
var apierr *cloudflare.Error
37+
if errors.As(err, &apierr) {
38+
t.Log(string(apierr.DumpRequest(true)))
39+
}
40+
t.Fatalf("err should be nil: %s", err.Error())
41+
}
42+
}
43+
44+
func TestConfigDelete(t *testing.T) {
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.PortScans.Config.Delete(context.TODO(), port_scans.ConfigDeleteParams{
58+
AccountID: cloudflare.F("account_id"),
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+
}
68+
69+
func TestConfigGet(t *testing.T) {
70+
baseURL := "http://localhost:4010"
71+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
72+
baseURL = envURL
73+
}
74+
if !testutil.CheckTestServer(t, baseURL) {
75+
return
76+
}
77+
client := cloudflare.NewClient(
78+
option.WithBaseURL(baseURL),
79+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
80+
option.WithAPIEmail("user@example.com"),
81+
)
82+
_, err := client.PortScans.Config.Get(context.TODO(), port_scans.ConfigGetParams{
83+
AccountID: cloudflare.F("account_id"),
84+
})
85+
if err != nil {
86+
var apierr *cloudflare.Error
87+
if errors.As(err, &apierr) {
88+
t.Log(string(apierr.DumpRequest(true)))
89+
}
90+
t.Fatalf("err should be nil: %s", err.Error())
91+
}
92+
}

‎port_scans/portscan.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package port_scans
4+
5+
import (
6+
"github.com/cloudflare/cloudflare-go/v4/option"
7+
)
8+
9+
// PortScanService contains methods and other services that help with interacting
10+
// with the cloudflare API.
11+
//
12+
// Note, unlike clients, this service does not read variables from the environment
13+
// automatically. You should not instantiate this service directly, and instead use
14+
// the [NewPortScanService] method instead.
15+
type PortScanService struct {
16+
Options []option.RequestOption
17+
Config *ConfigService
18+
Results *ResultService
19+
}
20+
21+
// NewPortScanService generates a new service that applies the given options to
22+
// each request. These options are applied after the parent client's options (if
23+
// there is one), and before any request-specific options.
24+
func NewPortScanService(opts ...option.RequestOption) (r *PortScanService) {
25+
r = &PortScanService{}
26+
r.Options = opts
27+
r.Config = NewConfigService(opts...)
28+
r.Results = NewResultService(opts...)
29+
return
30+
}

‎port_scans/result.go

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package port_scans
4+
5+
import (
6+
"context"
7+
"errors"
8+
"fmt"
9+
"net/http"
10+
11+
"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
12+
"github.com/cloudflare/cloudflare-go/v4/internal/param"
13+
"github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
14+
"github.com/cloudflare/cloudflare-go/v4/option"
15+
)
16+
17+
// ResultService contains methods and other services that help with interacting
18+
// with the cloudflare API.
19+
//
20+
// Note, unlike clients, this service does not read variables from the environment
21+
// automatically. You should not instantiate this service directly, and instead use
22+
// the [NewResultService] method instead.
23+
type ResultService struct {
24+
Options []option.RequestOption
25+
}
26+
27+
// NewResultService generates a new service that applies the given options to each
28+
// request. These options are applied after the parent client's options (if there
29+
// is one), and before any request-specific options.
30+
func NewResultService(opts ...option.RequestOption) (r *ResultService) {
31+
r = &ResultService{}
32+
r.Options = opts
33+
return
34+
}
35+
36+
// Get the Latest Scan Result
37+
func (r *ResultService) List(ctx context.Context, query ResultListParams, opts ...option.RequestOption) (res *ResultListResponse, err error) {
38+
var env ResultListResponseEnvelope
39+
opts = append(r.Options[:], opts...)
40+
if query.AccountID.Value == "" {
41+
err = errors.New("missing required account_id parameter")
42+
return
43+
}
44+
path := fmt.Sprintf("%s/scans/results", query.AccountID)
45+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
46+
if err != nil {
47+
return
48+
}
49+
res = &env.Result
50+
return
51+
}
52+
53+
type ResultListResponse struct {
54+
Number1_1_1_1 []ResultListResponse1_1_1_1 `json:"1.1.1.1,required"`
55+
JSON resultListResponseJSON `json:"-"`
56+
}
57+
58+
// resultListResponseJSON contains the JSON metadata for the struct
59+
// [ResultListResponse]
60+
type resultListResponseJSON struct {
61+
Number1_1_1_1 apijson.Field
62+
raw string
63+
ExtraFields map[string]apijson.Field
64+
}
65+
66+
func (r *ResultListResponse) UnmarshalJSON(data []byte) (err error) {
67+
return apijson.UnmarshalRoot(data, r)
68+
}
69+
70+
func (r resultListResponseJSON) RawJSON() string {
71+
return r.raw
72+
}
73+
74+
type ResultListResponse1_1_1_1 struct {
75+
Number float64 `json:"number,required"`
76+
Proto string `json:"proto,required"`
77+
Status string `json:"status,required"`
78+
JSON resultListResponse1_1_1_1JSON `json:"-"`
79+
}
80+
81+
// resultListResponse1_1_1_1JSON contains the JSON metadata for the struct
82+
// [ResultListResponse1_1_1_1]
83+
type resultListResponse1_1_1_1JSON struct {
84+
Number apijson.Field
85+
Proto apijson.Field
86+
Status apijson.Field
87+
raw string
88+
ExtraFields map[string]apijson.Field
89+
}
90+
91+
func (r *ResultListResponse1_1_1_1) UnmarshalJSON(data []byte) (err error) {
92+
return apijson.UnmarshalRoot(data, r)
93+
}
94+
95+
func (r resultListResponse1_1_1_1JSON) RawJSON() string {
96+
return r.raw
97+
}
98+
99+
type ResultListParams struct {
100+
// Account ID
101+
AccountID param.Field[string] `path:"account_id,required"`
102+
}
103+
104+
type ResultListResponseEnvelope struct {
105+
Errors []string `json:"errors,required"`
106+
Messages []string `json:"messages,required"`
107+
Result ResultListResponse `json:"result,required"`
108+
Success bool `json:"success,required"`
109+
JSON resultListResponseEnvelopeJSON `json:"-"`
110+
}
111+
112+
// resultListResponseEnvelopeJSON contains the JSON metadata for the struct
113+
// [ResultListResponseEnvelope]
114+
type resultListResponseEnvelopeJSON struct {
115+
Errors apijson.Field
116+
Messages apijson.Field
117+
Result apijson.Field
118+
Success apijson.Field
119+
raw string
120+
ExtraFields map[string]apijson.Field
121+
}
122+
123+
func (r *ResultListResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
124+
return apijson.UnmarshalRoot(data, r)
125+
}
126+
127+
func (r resultListResponseEnvelopeJSON) RawJSON() string {
128+
return r.raw
129+
}

‎port_scans/result_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package port_scans_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+
"github.com/cloudflare/cloudflare-go/v4/port_scans"
15+
)
16+
17+
func TestResultList(t *testing.T) {
18+
baseURL := "http://localhost:4010"
19+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
20+
baseURL = envURL
21+
}
22+
if !testutil.CheckTestServer(t, baseURL) {
23+
return
24+
}
25+
client := cloudflare.NewClient(
26+
option.WithBaseURL(baseURL),
27+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
28+
option.WithAPIEmail("user@example.com"),
29+
)
30+
_, err := client.PortScans.Results.List(context.TODO(), port_scans.ResultListParams{
31+
AccountID: cloudflare.F("account_id"),
32+
})
33+
if err != nil {
34+
var apierr *cloudflare.Error
35+
if errors.As(err, &apierr) {
36+
t.Log(string(apierr.DumpRequest(true)))
37+
}
38+
t.Fatalf("err should be nil: %s", err.Error())
39+
}
40+
}

0 commit comments

Comments
 (0)
Please sign in to comment.