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

Browse files
committedMar 13, 2025
feat(vpc_flows): add token support (#3962)
1 parent 1bdc68f commit 74b7996

File tree

6 files changed

+182
-4
lines changed

6 files changed

+182
-4
lines changed
 

‎.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1547
1+
configured_endpoints: 1548
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-cc9be7885f16989f56e5e015644178eb17b82304fc31f62ed14b7e9a93cab891.yml

‎api.md

+8
Original file line numberDiff line numberDiff line change
@@ -3721,6 +3721,14 @@ Methods:
37213721

37223722
# MagicNetworkMonitoring
37233723

3724+
## VpcFlows
3725+
3726+
### Tokens
3727+
3728+
Methods:
3729+
3730+
- <code title="post /accounts/{account_id}/mnm/vpc-flows/token">client.MagicNetworkMonitoring.VpcFlows.Tokens.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/magic_network_monitoring#VpcFlowTokenService.New">New</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/magic_network_monitoring">magic_network_monitoring</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/magic_network_monitoring#VpcFlowTokenNewParams">VpcFlowTokenNewParams</a>) (<a href="https://pkg.go.dev/builtin#string">string</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
3731+
37243732
## Configs
37253733

37263734
Response Types:

‎magic_network_monitoring/magicnetworkmonitoring.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
// automatically. You should not instantiate this service directly, and instead use
1414
// the [NewMagicNetworkMonitoringService] method instead.
1515
type MagicNetworkMonitoringService struct {
16-
Options []option.RequestOption
17-
Configs *ConfigService
18-
Rules *RuleService
16+
Options []option.RequestOption
17+
VpcFlows *VpcFlowService
18+
Configs *ConfigService
19+
Rules *RuleService
1920
}
2021

2122
// NewMagicNetworkMonitoringService generates a new service that applies the given
@@ -24,6 +25,7 @@ type MagicNetworkMonitoringService struct {
2425
func NewMagicNetworkMonitoringService(opts ...option.RequestOption) (r *MagicNetworkMonitoringService) {
2526
r = &MagicNetworkMonitoringService{}
2627
r.Options = opts
28+
r.VpcFlows = NewVpcFlowService(opts...)
2729
r.Configs = NewConfigService(opts...)
2830
r.Rules = NewRuleService(opts...)
2931
return

‎magic_network_monitoring/vpcflow.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package magic_network_monitoring
4+
5+
import (
6+
"github.com/cloudflare/cloudflare-go/v4/option"
7+
)
8+
9+
// VpcFlowService 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 [NewVpcFlowService] method instead.
15+
type VpcFlowService struct {
16+
Options []option.RequestOption
17+
Tokens *VpcFlowTokenService
18+
}
19+
20+
// NewVpcFlowService generates a new service that applies the given options to each
21+
// request. These options are applied after the parent client's options (if there
22+
// is one), and before any request-specific options.
23+
func NewVpcFlowService(opts ...option.RequestOption) (r *VpcFlowService) {
24+
r = &VpcFlowService{}
25+
r.Options = opts
26+
r.Tokens = NewVpcFlowTokenService(opts...)
27+
return
28+
}
+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package magic_network_monitoring
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+
"github.com/cloudflare/cloudflare-go/v4/shared"
16+
)
17+
18+
// VpcFlowTokenService contains methods and other services that help with
19+
// interacting with the cloudflare API.
20+
//
21+
// Note, unlike clients, this service does not read variables from the environment
22+
// automatically. You should not instantiate this service directly, and instead use
23+
// the [NewVpcFlowTokenService] method instead.
24+
type VpcFlowTokenService struct {
25+
Options []option.RequestOption
26+
}
27+
28+
// NewVpcFlowTokenService generates a new service that applies the given options to
29+
// each request. These options are applied after the parent client's options (if
30+
// there is one), and before any request-specific options.
31+
func NewVpcFlowTokenService(opts ...option.RequestOption) (r *VpcFlowTokenService) {
32+
r = &VpcFlowTokenService{}
33+
r.Options = opts
34+
return
35+
}
36+
37+
// Generate authentication token for VPC flow logs export.
38+
func (r *VpcFlowTokenService) New(ctx context.Context, body VpcFlowTokenNewParams, opts ...option.RequestOption) (res *string, err error) {
39+
var env VpcFlowTokenNewResponseEnvelope
40+
opts = append(r.Options[:], opts...)
41+
if body.AccountID.Value == "" {
42+
err = errors.New("missing required account_id parameter")
43+
return
44+
}
45+
path := fmt.Sprintf("accounts/%s/mnm/vpc-flows/token", body.AccountID)
46+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &env, opts...)
47+
if err != nil {
48+
return
49+
}
50+
res = &env.Result
51+
return
52+
}
53+
54+
type VpcFlowTokenNewParams struct {
55+
AccountID param.Field[string] `path:"account_id,required"`
56+
}
57+
58+
type VpcFlowTokenNewResponseEnvelope struct {
59+
Errors []shared.ResponseInfo `json:"errors,required"`
60+
Messages []shared.ResponseInfo `json:"messages,required"`
61+
// Authentication token to be used for VPC Flows export authentication.
62+
Result string `json:"result,required"`
63+
// Whether the API call was successful
64+
Success VpcFlowTokenNewResponseEnvelopeSuccess `json:"success,required"`
65+
JSON vpcFlowTokenNewResponseEnvelopeJSON `json:"-"`
66+
}
67+
68+
// vpcFlowTokenNewResponseEnvelopeJSON contains the JSON metadata for the struct
69+
// [VpcFlowTokenNewResponseEnvelope]
70+
type vpcFlowTokenNewResponseEnvelopeJSON struct {
71+
Errors apijson.Field
72+
Messages apijson.Field
73+
Result apijson.Field
74+
Success apijson.Field
75+
raw string
76+
ExtraFields map[string]apijson.Field
77+
}
78+
79+
func (r *VpcFlowTokenNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
80+
return apijson.UnmarshalRoot(data, r)
81+
}
82+
83+
func (r vpcFlowTokenNewResponseEnvelopeJSON) RawJSON() string {
84+
return r.raw
85+
}
86+
87+
// Whether the API call was successful
88+
type VpcFlowTokenNewResponseEnvelopeSuccess bool
89+
90+
const (
91+
VpcFlowTokenNewResponseEnvelopeSuccessTrue VpcFlowTokenNewResponseEnvelopeSuccess = true
92+
)
93+
94+
func (r VpcFlowTokenNewResponseEnvelopeSuccess) IsKnown() bool {
95+
switch r {
96+
case VpcFlowTokenNewResponseEnvelopeSuccessTrue:
97+
return true
98+
}
99+
return false
100+
}
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 magic_network_monitoring_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/magic_network_monitoring"
14+
"github.com/cloudflare/cloudflare-go/v4/option"
15+
)
16+
17+
func TestVpcFlowTokenNew(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.MagicNetworkMonitoring.VpcFlows.Tokens.New(context.TODO(), magic_network_monitoring.VpcFlowTokenNewParams{
31+
AccountID: cloudflare.F("6f91088a406011ed95aed352566e8d4c"),
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.