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

Browse files
committedMar 14, 2025·
feat(api): Update scans and scan results routes (#4031)
1 parent b8700b0 commit 6d04430

File tree

6 files changed

+247
-2
lines changed

6 files changed

+247
-2
lines changed
 

‎.stats.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1608
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-9129193d19a2c3346f2773a2a8bab4b29d953f6daa031be766c1986f5a87241e.yml
1+
configured_endpoints: 1610
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-82de145f779519a04c8c54da0d4844a3b45c71a69bdf1178a79597b969ca7cac.yml

‎api.md

+10
Original file line numberDiff line numberDiff line change
@@ -7663,17 +7663,27 @@ Methods:
76637663

76647664
### Results
76657665

7666+
Response Types:
7667+
7668+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanResultGetResponse">ScanResultGetResponse</a>
7669+
7670+
Methods:
7671+
7672+
- <code title="get /accounts/{account_id}/cloudforce-one/scans/results/{config_id}">client.CloudforceOne.Scans.Results.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanResultService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, configID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanResultGetParams">ScanResultGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanResultGetResponse">ScanResultGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
7673+
76667674
### Config
76677675

76687676
Response Types:
76697677

76707678
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigNewResponse">ScanConfigNewResponse</a>
76717679
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigListResponse">ScanConfigListResponse</a>
7680+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigDeleteResponse">ScanConfigDeleteResponse</a>
76727681

76737682
Methods:
76747683

76757684
- <code title="post /accounts/{account_id}/cloudforce-one/scans/config">client.CloudforceOne.Scans.Config.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigService.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/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigNewParams">ScanConfigNewParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigNewResponse">ScanConfigNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
76767685
- <code title="get /accounts/{account_id}/cloudforce-one/scans/config">client.CloudforceOne.Scans.Config.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigService.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/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigListParams">ScanConfigListParams</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/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigListResponse">ScanConfigListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
7686+
- <code title="delete /accounts/{account_id}/cloudforce-one/scans/config/{config_id}">client.CloudforceOne.Scans.Config.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, configID <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigDeleteParams">ScanConfigDeleteParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one">cloudforce_one</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/cloudforce_one#ScanConfigDeleteResponse">ScanConfigDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
76777687

76787688
## Requests
76797689

‎cloudforce_one/scanconfig.go

+55
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ func (r *ScanConfigService) ListAutoPaging(ctx context.Context, query ScanConfig
7979
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
8080
}
8181

82+
// Delete a Scan Config
83+
func (r *ScanConfigService) Delete(ctx context.Context, configID string, body ScanConfigDeleteParams, opts ...option.RequestOption) (res *ScanConfigDeleteResponse, err error) {
84+
var env ScanConfigDeleteResponseEnvelope
85+
opts = append(r.Options[:], opts...)
86+
if body.AccountID.Value == "" {
87+
err = errors.New("missing required account_id parameter")
88+
return
89+
}
90+
if configID == "" {
91+
err = errors.New("missing required config_id parameter")
92+
return
93+
}
94+
path := fmt.Sprintf("accounts/%s/cloudforce-one/scans/config/%s", body.AccountID, configID)
95+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
96+
if err != nil {
97+
return
98+
}
99+
res = &env.Result
100+
return
101+
}
102+
82103
type ScanConfigNewResponse struct {
83104
ID string `json:"id,required"`
84105
AccountID string `json:"account_id,required"`
@@ -137,6 +158,8 @@ func (r scanConfigListResponseJSON) RawJSON() string {
137158
return r.raw
138159
}
139160

161+
type ScanConfigDeleteResponse = interface{}
162+
140163
type ScanConfigNewParams struct {
141164
// Account ID
142165
AccountID param.Field[string] `path:"account_id,required"`
@@ -202,3 +225,35 @@ type ScanConfigListParams struct {
202225
// Account ID
203226
AccountID param.Field[string] `path:"account_id,required"`
204227
}
228+
229+
type ScanConfigDeleteParams struct {
230+
// Account ID
231+
AccountID param.Field[string] `path:"account_id,required"`
232+
}
233+
234+
type ScanConfigDeleteResponseEnvelope struct {
235+
Errors []string `json:"errors,required"`
236+
Messages []string `json:"messages,required"`
237+
Result ScanConfigDeleteResponse `json:"result,required"`
238+
Success bool `json:"success,required"`
239+
JSON scanConfigDeleteResponseEnvelopeJSON `json:"-"`
240+
}
241+
242+
// scanConfigDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
243+
// [ScanConfigDeleteResponseEnvelope]
244+
type scanConfigDeleteResponseEnvelopeJSON struct {
245+
Errors apijson.Field
246+
Messages apijson.Field
247+
Result apijson.Field
248+
Success apijson.Field
249+
raw string
250+
ExtraFields map[string]apijson.Field
251+
}
252+
253+
func (r *ScanConfigDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
254+
return apijson.UnmarshalRoot(data, r)
255+
}
256+
257+
func (r scanConfigDeleteResponseEnvelopeJSON) RawJSON() string {
258+
return r.raw
259+
}

‎cloudforce_one/scanconfig_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,32 @@ func TestScanConfigList(t *testing.T) {
6666
t.Fatalf("err should be nil: %s", err.Error())
6767
}
6868
}
69+
70+
func TestScanConfigDelete(t *testing.T) {
71+
baseURL := "http://localhost:4010"
72+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
73+
baseURL = envURL
74+
}
75+
if !testutil.CheckTestServer(t, baseURL) {
76+
return
77+
}
78+
client := cloudflare.NewClient(
79+
option.WithBaseURL(baseURL),
80+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
81+
option.WithAPIEmail("user@example.com"),
82+
)
83+
_, err := client.CloudforceOne.Scans.Config.Delete(
84+
context.TODO(),
85+
"config_id",
86+
cloudforce_one.ScanConfigDeleteParams{
87+
AccountID: cloudflare.F("account_id"),
88+
},
89+
)
90+
if err != nil {
91+
var apierr *cloudflare.Error
92+
if errors.As(err, &apierr) {
93+
t.Log(string(apierr.DumpRequest(true)))
94+
}
95+
t.Fatalf("err should be nil: %s", err.Error())
96+
}
97+
}

‎cloudforce_one/scanresult.go

+107
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
package cloudforce_one
44

55
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"
614
"github.com/cloudflare/cloudflare-go/v4/option"
715
)
816

@@ -24,3 +32,102 @@ func NewScanResultService(opts ...option.RequestOption) (r *ScanResultService) {
2432
r.Options = opts
2533
return
2634
}
35+
36+
// Get the Latest Scan Result
37+
func (r *ScanResultService) Get(ctx context.Context, configID string, query ScanResultGetParams, opts ...option.RequestOption) (res *ScanResultGetResponse, err error) {
38+
var env ScanResultGetResponseEnvelope
39+
opts = append(r.Options[:], opts...)
40+
if query.AccountID.Value == "" {
41+
err = errors.New("missing required account_id parameter")
42+
return
43+
}
44+
if configID == "" {
45+
err = errors.New("missing required config_id parameter")
46+
return
47+
}
48+
path := fmt.Sprintf("accounts/%s/cloudforce-one/scans/results/%s", query.AccountID, configID)
49+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
50+
if err != nil {
51+
return
52+
}
53+
res = &env.Result
54+
return
55+
}
56+
57+
type ScanResultGetResponse struct {
58+
OneOneOneOne []ScanResultGetResponse1_1_1_1 `json:"1.1.1.1,required"`
59+
JSON scanResultGetResponseJSON `json:"-"`
60+
}
61+
62+
// scanResultGetResponseJSON contains the JSON metadata for the struct
63+
// [ScanResultGetResponse]
64+
type scanResultGetResponseJSON struct {
65+
OneOneOneOne apijson.Field
66+
raw string
67+
ExtraFields map[string]apijson.Field
68+
}
69+
70+
func (r *ScanResultGetResponse) UnmarshalJSON(data []byte) (err error) {
71+
return apijson.UnmarshalRoot(data, r)
72+
}
73+
74+
func (r scanResultGetResponseJSON) RawJSON() string {
75+
return r.raw
76+
}
77+
78+
type ScanResultGetResponse1_1_1_1 struct {
79+
Number float64 `json:"number"`
80+
Proto string `json:"proto"`
81+
Status string `json:"status"`
82+
JSON scanResultGetResponse1_1_1_1JSON `json:"-"`
83+
}
84+
85+
// scanResultGetResponse1_1_1_1JSON contains the JSON metadata for the struct
86+
// [ScanResultGetResponse1_1_1_1]
87+
type scanResultGetResponse1_1_1_1JSON struct {
88+
Number apijson.Field
89+
Proto apijson.Field
90+
Status apijson.Field
91+
raw string
92+
ExtraFields map[string]apijson.Field
93+
}
94+
95+
func (r *ScanResultGetResponse1_1_1_1) UnmarshalJSON(data []byte) (err error) {
96+
return apijson.UnmarshalRoot(data, r)
97+
}
98+
99+
func (r scanResultGetResponse1_1_1_1JSON) RawJSON() string {
100+
return r.raw
101+
}
102+
103+
type ScanResultGetParams struct {
104+
// Account ID
105+
AccountID param.Field[string] `path:"account_id,required"`
106+
}
107+
108+
type ScanResultGetResponseEnvelope struct {
109+
Errors []string `json:"errors,required"`
110+
Messages []string `json:"messages,required"`
111+
Result ScanResultGetResponse `json:"result,required"`
112+
Success bool `json:"success,required"`
113+
JSON scanResultGetResponseEnvelopeJSON `json:"-"`
114+
}
115+
116+
// scanResultGetResponseEnvelopeJSON contains the JSON metadata for the struct
117+
// [ScanResultGetResponseEnvelope]
118+
type scanResultGetResponseEnvelopeJSON struct {
119+
Errors apijson.Field
120+
Messages apijson.Field
121+
Result apijson.Field
122+
Success apijson.Field
123+
raw string
124+
ExtraFields map[string]apijson.Field
125+
}
126+
127+
func (r *ScanResultGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
128+
return apijson.UnmarshalRoot(data, r)
129+
}
130+
131+
func (r scanResultGetResponseEnvelopeJSON) RawJSON() string {
132+
return r.raw
133+
}

‎cloudforce_one/scanresult_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package cloudforce_one_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/cloudforce_one"
13+
"github.com/cloudflare/cloudflare-go/v4/internal/testutil"
14+
"github.com/cloudflare/cloudflare-go/v4/option"
15+
)
16+
17+
func TestScanResultGet(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.CloudforceOne.Scans.Results.Get(
31+
context.TODO(),
32+
"config_id",
33+
cloudforce_one.ScanResultGetParams{
34+
AccountID: cloudflare.F("account_id"),
35+
},
36+
)
37+
if err != nil {
38+
var apierr *cloudflare.Error
39+
if errors.As(err, &apierr) {
40+
t.Log(string(apierr.DumpRequest(true)))
41+
}
42+
t.Fatalf("err should be nil: %s", err.Error())
43+
}
44+
}

0 commit comments

Comments
 (0)
Please sign in to comment.