Skip to content

Commit

Permalink
feat(addressing)!: move service bindings to dedicated namespace (#3768)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Jan 1, 2025
1 parent b714ae7 commit 25d0c40
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 81 deletions.
8 changes: 5 additions & 3 deletions addressing/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
// automatically. You should not instantiate this service directly, and instead use
// the [NewPrefixService] method instead.
type PrefixService struct {
Options []option.RequestOption
BGP *PrefixBGPService
Delegations *PrefixDelegationService
Options []option.RequestOption
ServiceBindings *PrefixServiceBindingService
BGP *PrefixBGPService
Delegations *PrefixDelegationService
}

// NewPrefixService generates a new service that applies the given options to each
Expand All @@ -35,6 +36,7 @@ type PrefixService struct {
func NewPrefixService(opts ...option.RequestOption) (r *PrefixService) {
r = &PrefixService{}
r.Options = opts
r.ServiceBindings = NewPrefixServiceBindingService(opts...)
r.BGP = NewPrefixBGPService(opts...)
r.Delegations = NewPrefixDelegationService(opts...)
return
Expand Down
2 changes: 0 additions & 2 deletions addressing/prefixbgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
// the [NewPrefixBGPService] method instead.
type PrefixBGPService struct {
Options []option.RequestOption
Bindings *PrefixBGPBindingService
Prefixes *PrefixBGPPrefixService
Statuses *PrefixBGPStatusService
}
Expand All @@ -25,7 +24,6 @@ type PrefixBGPService struct {
func NewPrefixBGPService(opts ...option.RequestOption) (r *PrefixBGPService) {
r = &PrefixBGPService{}
r.Options = opts
r.Bindings = NewPrefixBGPBindingService(opts...)
r.Prefixes = NewPrefixBGPPrefixService(opts...)
r.Statuses = NewPrefixBGPStatusService(opts...)
return
Expand Down
112 changes: 56 additions & 56 deletions addressing/prefixbgpbinding.go → addressing/prefixservicebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ import (
"github.com/cloudflare/cloudflare-go/v3/shared"
)

// PrefixBGPBindingService contains methods and other services that help with
// PrefixServiceBindingService 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 [NewPrefixBGPBindingService] method instead.
type PrefixBGPBindingService struct {
// the [NewPrefixServiceBindingService] method instead.
type PrefixServiceBindingService struct {
Options []option.RequestOption
}

// NewPrefixBGPBindingService generates a new service that applies the given
// NewPrefixServiceBindingService 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 NewPrefixBGPBindingService(opts ...option.RequestOption) (r *PrefixBGPBindingService) {
r = &PrefixBGPBindingService{}
func NewPrefixServiceBindingService(opts ...option.RequestOption) (r *PrefixServiceBindingService) {
r = &PrefixServiceBindingService{}
r.Options = opts
return
}
Expand All @@ -39,8 +39,8 @@ func NewPrefixBGPBindingService(opts ...option.RequestOption) (r *PrefixBGPBindi
// service running on Cloudflare's network. **Note:** This API may only be used on
// prefixes currently configured with a Magic Transit service binding, and only
// allows creating service bindings for the Cloudflare CDN or Cloudflare Spectrum.
func (r *PrefixBGPBindingService) New(ctx context.Context, prefixID string, params PrefixBGPBindingNewParams, opts ...option.RequestOption) (res *ServiceBinding, err error) {
var env PrefixBGPBindingNewResponseEnvelope
func (r *PrefixServiceBindingService) New(ctx context.Context, prefixID string, params PrefixServiceBindingNewParams, opts ...option.RequestOption) (res *ServiceBinding, err error) {
var env PrefixServiceBindingNewResponseEnvelope
opts = append(r.Options[:], opts...)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
Expand All @@ -65,7 +65,7 @@ func (r *PrefixBGPBindingService) New(ctx context.Context, prefixID string, para
// `192.0.2.0/24` to Cloudflare Magic Transit and `192.0.2.1/32` to the Cloudflare
// CDN would route traffic for `192.0.2.1` to the CDN, and traffic for all other
// IPs in the prefix to Cloudflare Magic Transit.
func (r *PrefixBGPBindingService) List(ctx context.Context, prefixID string, query PrefixBGPBindingListParams, opts ...option.RequestOption) (res *pagination.SinglePage[ServiceBinding], err error) {
func (r *PrefixServiceBindingService) List(ctx context.Context, prefixID string, query PrefixServiceBindingListParams, opts ...option.RequestOption) (res *pagination.SinglePage[ServiceBinding], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
Expand Down Expand Up @@ -96,12 +96,12 @@ func (r *PrefixBGPBindingService) List(ctx context.Context, prefixID string, que
// `192.0.2.0/24` to Cloudflare Magic Transit and `192.0.2.1/32` to the Cloudflare
// CDN would route traffic for `192.0.2.1` to the CDN, and traffic for all other
// IPs in the prefix to Cloudflare Magic Transit.
func (r *PrefixBGPBindingService) ListAutoPaging(ctx context.Context, prefixID string, query PrefixBGPBindingListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[ServiceBinding] {
func (r *PrefixServiceBindingService) ListAutoPaging(ctx context.Context, prefixID string, query PrefixServiceBindingListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[ServiceBinding] {
return pagination.NewSinglePageAutoPager(r.List(ctx, prefixID, query, opts...))
}

// Delete a Service Binding
func (r *PrefixBGPBindingService) Delete(ctx context.Context, prefixID string, bindingID string, body PrefixBGPBindingDeleteParams, opts ...option.RequestOption) (res *PrefixBGPBindingDeleteResponse, err error) {
func (r *PrefixServiceBindingService) Delete(ctx context.Context, prefixID string, bindingID string, body PrefixServiceBindingDeleteParams, opts ...option.RequestOption) (res *PrefixServiceBindingDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
if body.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
Expand All @@ -121,8 +121,8 @@ func (r *PrefixBGPBindingService) Delete(ctx context.Context, prefixID string, b
}

// Fetch a single Service Binding
func (r *PrefixBGPBindingService) Get(ctx context.Context, prefixID string, bindingID string, query PrefixBGPBindingGetParams, opts ...option.RequestOption) (res *ServiceBinding, err error) {
var env PrefixBGPBindingGetResponseEnvelope
func (r *PrefixServiceBindingService) Get(ctx context.Context, prefixID string, bindingID string, query PrefixServiceBindingGetParams, opts ...option.RequestOption) (res *ServiceBinding, err error) {
var env PrefixServiceBindingGetResponseEnvelope
opts = append(r.Options[:], opts...)
if query.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
Expand Down Expand Up @@ -221,48 +221,48 @@ func (r ServiceBindingProvisioningState) IsKnown() bool {
return false
}

type PrefixBGPBindingDeleteResponse struct {
type PrefixServiceBindingDeleteResponse struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixBGPBindingDeleteResponseSuccess `json:"success,required"`
JSON prefixBGPBindingDeleteResponseJSON `json:"-"`
Success PrefixServiceBindingDeleteResponseSuccess `json:"success,required"`
JSON prefixServiceBindingDeleteResponseJSON `json:"-"`
}

// prefixBGPBindingDeleteResponseJSON contains the JSON metadata for the struct
// [PrefixBGPBindingDeleteResponse]
type prefixBGPBindingDeleteResponseJSON struct {
// prefixServiceBindingDeleteResponseJSON contains the JSON metadata for the struct
// [PrefixServiceBindingDeleteResponse]
type prefixServiceBindingDeleteResponseJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *PrefixBGPBindingDeleteResponse) UnmarshalJSON(data []byte) (err error) {
func (r *PrefixServiceBindingDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r prefixBGPBindingDeleteResponseJSON) RawJSON() string {
func (r prefixServiceBindingDeleteResponseJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type PrefixBGPBindingDeleteResponseSuccess bool
type PrefixServiceBindingDeleteResponseSuccess bool

const (
PrefixBGPBindingDeleteResponseSuccessTrue PrefixBGPBindingDeleteResponseSuccess = true
PrefixServiceBindingDeleteResponseSuccessTrue PrefixServiceBindingDeleteResponseSuccess = true
)

func (r PrefixBGPBindingDeleteResponseSuccess) IsKnown() bool {
func (r PrefixServiceBindingDeleteResponseSuccess) IsKnown() bool {
switch r {
case PrefixBGPBindingDeleteResponseSuccessTrue:
case PrefixServiceBindingDeleteResponseSuccessTrue:
return true
}
return false
}

type PrefixBGPBindingNewParams struct {
type PrefixServiceBindingNewParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
// IP Prefix in Classless Inter-Domain Routing format.
Expand All @@ -271,22 +271,22 @@ type PrefixBGPBindingNewParams struct {
ServiceID param.Field[string] `json:"service_id"`
}

func (r PrefixBGPBindingNewParams) MarshalJSON() (data []byte, err error) {
func (r PrefixServiceBindingNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type PrefixBGPBindingNewResponseEnvelope struct {
type PrefixServiceBindingNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixBGPBindingNewResponseEnvelopeSuccess `json:"success,required"`
Result ServiceBinding `json:"result"`
JSON prefixBGPBindingNewResponseEnvelopeJSON `json:"-"`
Success PrefixServiceBindingNewResponseEnvelopeSuccess `json:"success,required"`
Result ServiceBinding `json:"result"`
JSON prefixServiceBindingNewResponseEnvelopeJSON `json:"-"`
}

// prefixBGPBindingNewResponseEnvelopeJSON contains the JSON metadata for the
// struct [PrefixBGPBindingNewResponseEnvelope]
type prefixBGPBindingNewResponseEnvelopeJSON struct {
// prefixServiceBindingNewResponseEnvelopeJSON contains the JSON metadata for the
// struct [PrefixServiceBindingNewResponseEnvelope]
type prefixServiceBindingNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Expand All @@ -295,56 +295,56 @@ type prefixBGPBindingNewResponseEnvelopeJSON struct {
ExtraFields map[string]apijson.Field
}

func (r *PrefixBGPBindingNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
func (r *PrefixServiceBindingNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r prefixBGPBindingNewResponseEnvelopeJSON) RawJSON() string {
func (r prefixServiceBindingNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type PrefixBGPBindingNewResponseEnvelopeSuccess bool
type PrefixServiceBindingNewResponseEnvelopeSuccess bool

const (
PrefixBGPBindingNewResponseEnvelopeSuccessTrue PrefixBGPBindingNewResponseEnvelopeSuccess = true
PrefixServiceBindingNewResponseEnvelopeSuccessTrue PrefixServiceBindingNewResponseEnvelopeSuccess = true
)

func (r PrefixBGPBindingNewResponseEnvelopeSuccess) IsKnown() bool {
func (r PrefixServiceBindingNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case PrefixBGPBindingNewResponseEnvelopeSuccessTrue:
case PrefixServiceBindingNewResponseEnvelopeSuccessTrue:
return true
}
return false
}

type PrefixBGPBindingListParams struct {
type PrefixServiceBindingListParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}

type PrefixBGPBindingDeleteParams struct {
type PrefixServiceBindingDeleteParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}

type PrefixBGPBindingGetParams struct {
type PrefixServiceBindingGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}

type PrefixBGPBindingGetResponseEnvelope struct {
type PrefixServiceBindingGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixBGPBindingGetResponseEnvelopeSuccess `json:"success,required"`
Result ServiceBinding `json:"result"`
JSON prefixBGPBindingGetResponseEnvelopeJSON `json:"-"`
Success PrefixServiceBindingGetResponseEnvelopeSuccess `json:"success,required"`
Result ServiceBinding `json:"result"`
JSON prefixServiceBindingGetResponseEnvelopeJSON `json:"-"`
}

// prefixBGPBindingGetResponseEnvelopeJSON contains the JSON metadata for the
// struct [PrefixBGPBindingGetResponseEnvelope]
type prefixBGPBindingGetResponseEnvelopeJSON struct {
// prefixServiceBindingGetResponseEnvelopeJSON contains the JSON metadata for the
// struct [PrefixServiceBindingGetResponseEnvelope]
type prefixServiceBindingGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Expand All @@ -353,24 +353,24 @@ type prefixBGPBindingGetResponseEnvelopeJSON struct {
ExtraFields map[string]apijson.Field
}

func (r *PrefixBGPBindingGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
func (r *PrefixServiceBindingGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r prefixBGPBindingGetResponseEnvelopeJSON) RawJSON() string {
func (r prefixServiceBindingGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type PrefixBGPBindingGetResponseEnvelopeSuccess bool
type PrefixServiceBindingGetResponseEnvelopeSuccess bool

const (
PrefixBGPBindingGetResponseEnvelopeSuccessTrue PrefixBGPBindingGetResponseEnvelopeSuccess = true
PrefixServiceBindingGetResponseEnvelopeSuccessTrue PrefixServiceBindingGetResponseEnvelopeSuccess = true
)

func (r PrefixBGPBindingGetResponseEnvelopeSuccess) IsKnown() bool {
func (r PrefixServiceBindingGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case PrefixBGPBindingGetResponseEnvelopeSuccessTrue:
case PrefixServiceBindingGetResponseEnvelopeSuccessTrue:
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cloudflare/cloudflare-go/v3/option"
)

func TestPrefixBGPBindingNewWithOptionalParams(t *testing.T) {
func TestPrefixServiceBindingNewWithOptionalParams(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
Expand All @@ -27,10 +27,10 @@ func TestPrefixBGPBindingNewWithOptionalParams(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Addressing.Prefixes.BGP.Bindings.New(
_, err := client.Addressing.Prefixes.ServiceBindings.New(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
addressing.PrefixBGPBindingNewParams{
addressing.PrefixServiceBindingNewParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
CIDR: cloudflare.F("192.0.2.0/24"),
ServiceID: cloudflare.F("2db684ee7ca04e159946fd05b99e1bcd"),
Expand All @@ -45,7 +45,7 @@ func TestPrefixBGPBindingNewWithOptionalParams(t *testing.T) {
}
}

func TestPrefixBGPBindingList(t *testing.T) {
func TestPrefixServiceBindingList(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
Expand All @@ -58,10 +58,10 @@ func TestPrefixBGPBindingList(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Addressing.Prefixes.BGP.Bindings.List(
_, err := client.Addressing.Prefixes.ServiceBindings.List(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
addressing.PrefixBGPBindingListParams{
addressing.PrefixServiceBindingListParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
},
)
Expand All @@ -74,7 +74,7 @@ func TestPrefixBGPBindingList(t *testing.T) {
}
}

func TestPrefixBGPBindingDelete(t *testing.T) {
func TestPrefixServiceBindingDelete(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
Expand All @@ -87,11 +87,11 @@ func TestPrefixBGPBindingDelete(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Addressing.Prefixes.BGP.Bindings.Delete(
_, err := client.Addressing.Prefixes.ServiceBindings.Delete(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
"023e105f4ecef8ad9ca31a8372d0c353",
addressing.PrefixBGPBindingDeleteParams{
addressing.PrefixServiceBindingDeleteParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
},
)
Expand All @@ -104,7 +104,7 @@ func TestPrefixBGPBindingDelete(t *testing.T) {
}
}

func TestPrefixBGPBindingGet(t *testing.T) {
func TestPrefixServiceBindingGet(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
Expand All @@ -117,11 +117,11 @@ func TestPrefixBGPBindingGet(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Addressing.Prefixes.BGP.Bindings.Get(
_, err := client.Addressing.Prefixes.ServiceBindings.Get(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
"023e105f4ecef8ad9ca31a8372d0c353",
addressing.PrefixBGPBindingGetParams{
addressing.PrefixServiceBindingGetParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
},
)
Expand Down
Loading

0 comments on commit 25d0c40

Please sign in to comment.