Skip to content

Commit

Permalink
feat(api): move pcaps under magic transit (#3043)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Sep 10, 2024
1 parent 987719c commit 863d93b
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 356 deletions.
78 changes: 39 additions & 39 deletions api.md

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import (
"github.com/cloudflare/cloudflare-go/v2/page_shield"
"github.com/cloudflare/cloudflare-go/v2/pagerules"
"github.com/cloudflare/cloudflare-go/v2/pages"
"github.com/cloudflare/cloudflare-go/v2/pcaps"
"github.com/cloudflare/cloudflare-go/v2/plans"
"github.com/cloudflare/cloudflare-go/v2/queues"
"github.com/cloudflare/cloudflare-go/v2/r2"
Expand Down Expand Up @@ -157,7 +156,6 @@ type Client struct {
MagicNetworkMonitoring *magic_network_monitoring.MagicNetworkMonitoringService
MTLSCertificates *mtls_certificates.MTLSCertificateService
Pages *pages.PageService
PCAPs *pcaps.PCAPService
Registrar *registrar.RegistrarService
RequestTracers *request_tracers.RequestTracerService
Rules *rules.RuleService
Expand Down Expand Up @@ -268,7 +266,6 @@ func NewClient(opts ...option.RequestOption) (r *Client) {
r.MagicNetworkMonitoring = magic_network_monitoring.NewMagicNetworkMonitoringService(opts...)
r.MTLSCertificates = mtls_certificates.NewMTLSCertificateService(opts...)
r.Pages = pages.NewPageService(opts...)
r.PCAPs = pcaps.NewPCAPService(opts...)
r.Registrar = registrar.NewRegistrarService(opts...)
r.RequestTracers = request_tracers.NewRequestTracerService(opts...)
r.Rules = rules.NewRuleService(opts...)
Expand Down
2 changes: 2 additions & 0 deletions magic_transit/magictransit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type MagicTransitService struct {
Routes *RouteService
Sites *SiteService
Connectors *ConnectorService
PCAPs *PCAPService
}

// NewMagicTransitService generates a new service that applies the given options to
Expand All @@ -38,6 +39,7 @@ func NewMagicTransitService(opts ...option.RequestOption) (r *MagicTransitServic
r.Routes = NewRouteService(opts...)
r.Sites = NewSiteService(opts...)
r.Connectors = NewConnectorService(opts...)
r.PCAPs = NewPCAPService(opts...)
return
}

Expand Down
67 changes: 35 additions & 32 deletions pcaps/pcap.go → magic_transit/pcap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package pcaps
package magic_transit

import (
"context"
Expand All @@ -26,8 +26,8 @@ import (
// the [NewPCAPService] method instead.
type PCAPService struct {
Options []option.RequestOption
Ownership *OwnershipService
Download *DownloadService
Ownership *PCAPOwnershipService
Download *PCAPDownloadService
}

// NewPCAPService generates a new service that applies the given options to each
Expand All @@ -36,8 +36,8 @@ type PCAPService struct {
func NewPCAPService(opts ...option.RequestOption) (r *PCAPService) {
r = &PCAPService{}
r.Options = opts
r.Ownership = NewOwnershipService(opts...)
r.Download = NewDownloadService(opts...)
r.Ownership = NewPCAPOwnershipService(opts...)
r.Download = NewPCAPDownloadService(opts...)
return
}

Expand Down Expand Up @@ -146,11 +146,11 @@ func (r pcapJSON) RawJSON() string {
return r.raw
}

func (r PCAP) implementsPCAPsPCAPNewResponse() {}
func (r PCAP) implementsMagicTransitPCAPNewResponse() {}

func (r PCAP) implementsPCAPsPCAPListResponse() {}
func (r PCAP) implementsMagicTransitPCAPListResponse() {}

func (r PCAP) implementsPCAPsPCAPGetResponse() {}
func (r PCAP) implementsMagicTransitPCAPGetResponse() {}

// The status of the packet capture request.
type PCAPStatus string
Expand Down Expand Up @@ -323,16 +323,16 @@ func (r *PCAPNewResponse) UnmarshalJSON(data []byte) (err error) {
// AsUnion returns a [PCAPNewResponseUnion] interface which you can cast to the
// specific types for more type safety.
//
// Possible runtime types of the union are [pcaps.PCAP],
// [pcaps.PCAPNewResponseMagicVisibilityPCAPsResponseFull].
// Possible runtime types of the union are [magic_transit.PCAP],
// [magic_transit.PCAPNewResponseMagicVisibilityPCAPsResponseFull].
func (r PCAPNewResponse) AsUnion() PCAPNewResponseUnion {
return r.union
}

// Union satisfied by [pcaps.PCAP] or
// [pcaps.PCAPNewResponseMagicVisibilityPCAPsResponseFull].
// Union satisfied by [magic_transit.PCAP] or
// [magic_transit.PCAPNewResponseMagicVisibilityPCAPsResponseFull].
type PCAPNewResponseUnion interface {
implementsPCAPsPCAPNewResponse()
implementsMagicTransitPCAPNewResponse()
}

func init() {
Expand Down Expand Up @@ -407,7 +407,7 @@ func (r pcapNewResponseMagicVisibilityPCAPsResponseFullJSON) RawJSON() string {
return r.raw
}

func (r PCAPNewResponseMagicVisibilityPCAPsResponseFull) implementsPCAPsPCAPNewResponse() {}
func (r PCAPNewResponseMagicVisibilityPCAPsResponseFull) implementsMagicTransitPCAPNewResponse() {}

// The status of the packet capture request.
type PCAPNewResponseMagicVisibilityPCAPsResponseFullStatus string
Expand Down Expand Up @@ -583,16 +583,16 @@ func (r *PCAPListResponse) UnmarshalJSON(data []byte) (err error) {
// AsUnion returns a [PCAPListResponseUnion] interface which you can cast to the
// specific types for more type safety.
//
// Possible runtime types of the union are [pcaps.PCAP],
// [pcaps.PCAPListResponseMagicVisibilityPCAPsResponseFull].
// Possible runtime types of the union are [magic_transit.PCAP],
// [magic_transit.PCAPListResponseMagicVisibilityPCAPsResponseFull].
func (r PCAPListResponse) AsUnion() PCAPListResponseUnion {
return r.union
}

// Union satisfied by [pcaps.PCAP] or
// [pcaps.PCAPListResponseMagicVisibilityPCAPsResponseFull].
// Union satisfied by [magic_transit.PCAP] or
// [magic_transit.PCAPListResponseMagicVisibilityPCAPsResponseFull].
type PCAPListResponseUnion interface {
implementsPCAPsPCAPListResponse()
implementsMagicTransitPCAPListResponse()
}

func init() {
Expand Down Expand Up @@ -667,7 +667,7 @@ func (r pcapListResponseMagicVisibilityPCAPsResponseFullJSON) RawJSON() string {
return r.raw
}

func (r PCAPListResponseMagicVisibilityPCAPsResponseFull) implementsPCAPsPCAPListResponse() {}
func (r PCAPListResponseMagicVisibilityPCAPsResponseFull) implementsMagicTransitPCAPListResponse() {}

// The status of the packet capture request.
type PCAPListResponseMagicVisibilityPCAPsResponseFullStatus string
Expand Down Expand Up @@ -842,16 +842,16 @@ func (r *PCAPGetResponse) UnmarshalJSON(data []byte) (err error) {
// AsUnion returns a [PCAPGetResponseUnion] interface which you can cast to the
// specific types for more type safety.
//
// Possible runtime types of the union are [pcaps.PCAP],
// [pcaps.PCAPGetResponseMagicVisibilityPCAPsResponseFull].
// Possible runtime types of the union are [magic_transit.PCAP],
// [magic_transit.PCAPGetResponseMagicVisibilityPCAPsResponseFull].
func (r PCAPGetResponse) AsUnion() PCAPGetResponseUnion {
return r.union
}

// Union satisfied by [pcaps.PCAP] or
// [pcaps.PCAPGetResponseMagicVisibilityPCAPsResponseFull].
// Union satisfied by [magic_transit.PCAP] or
// [magic_transit.PCAPGetResponseMagicVisibilityPCAPsResponseFull].
type PCAPGetResponseUnion interface {
implementsPCAPsPCAPGetResponse()
implementsMagicTransitPCAPGetResponse()
}

func init() {
Expand Down Expand Up @@ -926,7 +926,7 @@ func (r pcapGetResponseMagicVisibilityPCAPsResponseFullJSON) RawJSON() string {
return r.raw
}

func (r PCAPGetResponseMagicVisibilityPCAPsResponseFull) implementsPCAPsPCAPGetResponse() {}
func (r PCAPGetResponseMagicVisibilityPCAPsResponseFull) implementsMagicTransitPCAPGetResponse() {}

// The status of the packet capture request.
type PCAPGetResponseMagicVisibilityPCAPsResponseFullStatus string
Expand Down Expand Up @@ -1073,12 +1073,13 @@ func (r PCAPNewParamsBody) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

func (r PCAPNewParamsBody) implementsPCAPsPCAPNewParamsBodyUnion() {}
func (r PCAPNewParamsBody) implementsMagicTransitPCAPNewParamsBodyUnion() {}

// Satisfied by [pcaps.PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimple],
// [pcaps.PCAPNewParamsBodyMagicVisibilityPCAPsRequestFull], [PCAPNewParamsBody].
// Satisfied by [magic_transit.PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimple],
// [magic_transit.PCAPNewParamsBodyMagicVisibilityPCAPsRequestFull],
// [PCAPNewParamsBody].
type PCAPNewParamsBodyUnion interface {
implementsPCAPsPCAPNewParamsBodyUnion()
implementsMagicTransitPCAPNewParamsBodyUnion()
}

type PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimple struct {
Expand All @@ -1099,7 +1100,8 @@ func (r PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimple) MarshalJSON() (data
return apijson.MarshalRoot(r)
}

func (r PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimple) implementsPCAPsPCAPNewParamsBodyUnion() {}
func (r PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimple) implementsMagicTransitPCAPNewParamsBodyUnion() {
}

// The system used to collect packet captures.
type PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimpleSystem string
Expand Down Expand Up @@ -1160,7 +1162,8 @@ func (r PCAPNewParamsBodyMagicVisibilityPCAPsRequestFull) MarshalJSON() (data []
return apijson.MarshalRoot(r)
}

func (r PCAPNewParamsBodyMagicVisibilityPCAPsRequestFull) implementsPCAPsPCAPNewParamsBodyUnion() {}
func (r PCAPNewParamsBodyMagicVisibilityPCAPsRequestFull) implementsMagicTransitPCAPNewParamsBodyUnion() {
}

// The system used to collect packet captures.
type PCAPNewParamsBodyMagicVisibilityPCAPsRequestFullSystem string
Expand Down
20 changes: 10 additions & 10 deletions pcaps/pcap_test.go → magic_transit/pcap_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package pcaps_test
package magic_transit_test

import (
"context"
Expand All @@ -10,8 +10,8 @@ import (

"github.com/cloudflare/cloudflare-go/v2"
"github.com/cloudflare/cloudflare-go/v2/internal/testutil"
"github.com/cloudflare/cloudflare-go/v2/magic_transit"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/cloudflare/cloudflare-go/v2/pcaps"
)

func TestPCAPNewWithOptionalParams(t *testing.T) {
Expand All @@ -27,14 +27,14 @@ func TestPCAPNewWithOptionalParams(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.PCAPs.New(context.TODO(), pcaps.PCAPNewParams{
_, err := client.MagicTransit.PCAPs.New(context.TODO(), magic_transit.PCAPNewParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Body: pcaps.PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimple{
Body: magic_transit.PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimple{
PacketLimit: cloudflare.F(10000.000000),
System: cloudflare.F(pcaps.PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimpleSystemMagicTransit),
System: cloudflare.F(magic_transit.PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimpleSystemMagicTransit),
TimeLimit: cloudflare.F(300.000000),
Type: cloudflare.F(pcaps.PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimpleTypeSimple),
FilterV1: cloudflare.F(pcaps.PCAPFilterParam{
Type: cloudflare.F(magic_transit.PCAPNewParamsBodyMagicVisibilityPCAPsRequestSimpleTypeSimple),
FilterV1: cloudflare.F(magic_transit.PCAPFilterParam{
DestinationAddress: cloudflare.F("1.2.3.4"),
DestinationPort: cloudflare.F(80.000000),
Protocol: cloudflare.F(6.000000),
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestPCAPList(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.PCAPs.List(context.TODO(), pcaps.PCAPListParams{
_, err := client.MagicTransit.PCAPs.List(context.TODO(), magic_transit.PCAPListParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
})
if err != nil {
Expand All @@ -90,10 +90,10 @@ func TestPCAPGet(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.PCAPs.Get(
_, err := client.MagicTransit.PCAPs.Get(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
pcaps.PCAPGetParams{
magic_transit.PCAPGetParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
},
)
Expand Down
20 changes: 10 additions & 10 deletions pcaps/download.go → magic_transit/pcapdownload.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package pcaps
package magic_transit

import (
"context"
Expand All @@ -13,27 +13,27 @@ import (
"github.com/cloudflare/cloudflare-go/v2/option"
)

// DownloadService contains methods and other services that help with interacting
// with the cloudflare API.
// PCAPDownloadService contains methods and other services that help with
// interacting with the cloudflare API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewDownloadService] method instead.
type DownloadService struct {
// the [NewPCAPDownloadService] method instead.
type PCAPDownloadService struct {
Options []option.RequestOption
}

// NewDownloadService generates a new service that applies the given options to
// NewPCAPDownloadService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewDownloadService(opts ...option.RequestOption) (r *DownloadService) {
r = &DownloadService{}
func NewPCAPDownloadService(opts ...option.RequestOption) (r *PCAPDownloadService) {
r = &PCAPDownloadService{}
r.Options = opts
return
}

// Download PCAP information into a file. Response is a binary PCAP file.
func (r *DownloadService) Get(ctx context.Context, pcapID string, query DownloadGetParams, opts ...option.RequestOption) (res *http.Response, err error) {
func (r *PCAPDownloadService) Get(ctx context.Context, pcapID string, query PCAPDownloadGetParams, opts ...option.RequestOption) (res *http.Response, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("Accept", "application/vnd.tcpdump.pcap")}, opts...)
if query.AccountID.Value == "" {
Expand All @@ -49,7 +49,7 @@ func (r *DownloadService) Get(ctx context.Context, pcapID string, query Download
return
}

type DownloadGetParams struct {
type PCAPDownloadGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
10 changes: 5 additions & 5 deletions pcaps/download_test.go → magic_transit/pcapdownload_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package pcaps_test
package magic_transit_test

import (
"bytes"
Expand All @@ -12,11 +12,11 @@ import (
"testing"

"github.com/cloudflare/cloudflare-go/v2"
"github.com/cloudflare/cloudflare-go/v2/magic_transit"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/cloudflare/cloudflare-go/v2/pcaps"
)

func TestDownloadGet(t *testing.T) {
func TestPCAPDownloadGet(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("abc"))
Expand All @@ -28,10 +28,10 @@ func TestDownloadGet(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
resp, err := client.PCAPs.Download.Get(
resp, err := client.MagicTransit.PCAPs.Download.Get(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
pcaps.DownloadGetParams{
magic_transit.PCAPDownloadGetParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
},
)
Expand Down
Loading

0 comments on commit 863d93b

Please sign in to comment.