|
| 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 | +} |
0 commit comments