Skip to content

Commit

Permalink
feat(addressing)!: reshuffle relationship in the namespace to align w…
Browse files Browse the repository at this point in the history
…ith the product (#3789)
  • Loading branch information
stainless-app[bot] committed Jan 7, 2025
1 parent 9ac9789 commit 5d9860b
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 289 deletions.
12 changes: 7 additions & 5 deletions addressing/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
// automatically. You should not instantiate this service directly, and instead use
// the [NewPrefixService] method instead.
type PrefixService struct {
Options []option.RequestOption
ServiceBindings *PrefixServiceBindingService
BGP *PrefixBGPService
Delegations *PrefixDelegationService
Options []option.RequestOption
ServiceBindings *PrefixServiceBindingService
BGPPrefixes *PrefixBGPPrefixService
AdvertisementStatus *PrefixAdvertisementStatusService
Delegations *PrefixDelegationService
}

// NewPrefixService generates a new service that applies the given options to each
Expand All @@ -37,7 +38,8 @@ func NewPrefixService(opts ...option.RequestOption) (r *PrefixService) {
r = &PrefixService{}
r.Options = opts
r.ServiceBindings = NewPrefixServiceBindingService(opts...)
r.BGP = NewPrefixBGPService(opts...)
r.BGPPrefixes = NewPrefixBGPPrefixService(opts...)
r.AdvertisementStatus = NewPrefixAdvertisementStatusService(opts...)
r.Delegations = NewPrefixDelegationService(opts...)
return
}
Expand Down
232 changes: 232 additions & 0 deletions addressing/prefixadvertisementstatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package addressing

import (
"context"
"errors"
"fmt"
"net/http"
"time"

"github.com/cloudflare/cloudflare-go/v3/internal/apijson"
"github.com/cloudflare/cloudflare-go/v3/internal/param"
"github.com/cloudflare/cloudflare-go/v3/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v3/option"
"github.com/cloudflare/cloudflare-go/v3/shared"
)

// PrefixAdvertisementStatusService 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 [NewPrefixAdvertisementStatusService] method instead.
type PrefixAdvertisementStatusService struct {
Options []option.RequestOption
}

// NewPrefixAdvertisementStatusService 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 NewPrefixAdvertisementStatusService(opts ...option.RequestOption) (r *PrefixAdvertisementStatusService) {
r = &PrefixAdvertisementStatusService{}
r.Options = opts
return
}

// Advertise or withdraw BGP route for a prefix.
func (r *PrefixAdvertisementStatusService) Edit(ctx context.Context, prefixID string, params PrefixAdvertisementStatusEditParams, opts ...option.RequestOption) (res *PrefixAdvertisementStatusEditResponse, err error) {
var env PrefixAdvertisementStatusEditResponseEnvelope
opts = append(r.Options[:], opts...)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
if prefixID == "" {
err = errors.New("missing required prefix_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bgp/status", params.AccountID, prefixID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

// List the current advertisement state for a prefix.
func (r *PrefixAdvertisementStatusService) Get(ctx context.Context, prefixID string, query PrefixAdvertisementStatusGetParams, opts ...option.RequestOption) (res *PrefixAdvertisementStatusGetResponse, err error) {
var env PrefixAdvertisementStatusGetResponseEnvelope
opts = append(r.Options[:], opts...)
if query.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
if prefixID == "" {
err = errors.New("missing required prefix_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bgp/status", query.AccountID, prefixID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

type PrefixAdvertisementStatusEditResponse struct {
// Enablement of prefix advertisement to the Internet.
Advertised bool `json:"advertised"`
// Last time the advertisement status was changed. This field is only not 'null' if
// on demand is enabled.
AdvertisedModifiedAt time.Time `json:"advertised_modified_at,nullable" format:"date-time"`
JSON prefixAdvertisementStatusEditResponseJSON `json:"-"`
}

// prefixAdvertisementStatusEditResponseJSON contains the JSON metadata for the
// struct [PrefixAdvertisementStatusEditResponse]
type prefixAdvertisementStatusEditResponseJSON struct {
Advertised apijson.Field
AdvertisedModifiedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

func (r prefixAdvertisementStatusEditResponseJSON) RawJSON() string {
return r.raw
}

type PrefixAdvertisementStatusGetResponse struct {
// Enablement of prefix advertisement to the Internet.
Advertised bool `json:"advertised"`
// Last time the advertisement status was changed. This field is only not 'null' if
// on demand is enabled.
AdvertisedModifiedAt time.Time `json:"advertised_modified_at,nullable" format:"date-time"`
JSON prefixAdvertisementStatusGetResponseJSON `json:"-"`
}

// prefixAdvertisementStatusGetResponseJSON contains the JSON metadata for the
// struct [PrefixAdvertisementStatusGetResponse]
type prefixAdvertisementStatusGetResponseJSON struct {
Advertised apijson.Field
AdvertisedModifiedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

func (r prefixAdvertisementStatusGetResponseJSON) RawJSON() string {
return r.raw
}

type PrefixAdvertisementStatusEditParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
// Enablement of prefix advertisement to the Internet.
Advertised param.Field[bool] `json:"advertised,required"`
}

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

type PrefixAdvertisementStatusEditResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixAdvertisementStatusEditResponseEnvelopeSuccess `json:"success,required"`
Result PrefixAdvertisementStatusEditResponse `json:"result"`
JSON prefixAdvertisementStatusEditResponseEnvelopeJSON `json:"-"`
}

// prefixAdvertisementStatusEditResponseEnvelopeJSON contains the JSON metadata for
// the struct [PrefixAdvertisementStatusEditResponseEnvelope]
type prefixAdvertisementStatusEditResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

func (r prefixAdvertisementStatusEditResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type PrefixAdvertisementStatusEditResponseEnvelopeSuccess bool

const (
PrefixAdvertisementStatusEditResponseEnvelopeSuccessTrue PrefixAdvertisementStatusEditResponseEnvelopeSuccess = true
)

func (r PrefixAdvertisementStatusEditResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case PrefixAdvertisementStatusEditResponseEnvelopeSuccessTrue:
return true
}
return false
}

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

type PrefixAdvertisementStatusGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixAdvertisementStatusGetResponseEnvelopeSuccess `json:"success,required"`
Result PrefixAdvertisementStatusGetResponse `json:"result"`
JSON prefixAdvertisementStatusGetResponseEnvelopeJSON `json:"-"`
}

// prefixAdvertisementStatusGetResponseEnvelopeJSON contains the JSON metadata for
// the struct [PrefixAdvertisementStatusGetResponseEnvelope]
type prefixAdvertisementStatusGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

func (r prefixAdvertisementStatusGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type PrefixAdvertisementStatusGetResponseEnvelopeSuccess bool

const (
PrefixAdvertisementStatusGetResponseEnvelopeSuccessTrue PrefixAdvertisementStatusGetResponseEnvelopeSuccess = true
)

func (r PrefixAdvertisementStatusGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case PrefixAdvertisementStatusGetResponseEnvelopeSuccessTrue:
return true
}
return false
}
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 TestPrefixBGPStatusEdit(t *testing.T) {
func TestPrefixAdvertisementStatusEdit(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 TestPrefixBGPStatusEdit(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.Addressing.Prefixes.BGP.Statuses.Edit(
_, err := client.Addressing.Prefixes.AdvertisementStatus.Edit(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
addressing.PrefixBGPStatusEditParams{
addressing.PrefixAdvertisementStatusEditParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Advertised: cloudflare.F(true),
},
Expand All @@ -44,7 +44,7 @@ func TestPrefixBGPStatusEdit(t *testing.T) {
}
}

func TestPrefixBGPStatusGet(t *testing.T) {
func TestPrefixAdvertisementStatusGet(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
Expand All @@ -57,10 +57,10 @@ func TestPrefixBGPStatusGet(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.Addressing.Prefixes.BGP.Statuses.Get(
_, err := client.Addressing.Prefixes.AdvertisementStatus.Get(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
addressing.PrefixBGPStatusGetParams{
addressing.PrefixAdvertisementStatusGetParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
},
)
Expand Down
30 changes: 0 additions & 30 deletions addressing/prefixbgp.go

This file was deleted.

8 changes: 4 additions & 4 deletions addressing/prefixbgpprefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestPrefixBGPPrefixNewWithOptionalParams(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.Addressing.Prefixes.BGP.Prefixes.New(
_, err := client.Addressing.Prefixes.BGPPrefixes.New(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
addressing.PrefixBGPPrefixNewParams{
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestPrefixBGPPrefixList(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.Addressing.Prefixes.BGP.Prefixes.List(
_, err := client.Addressing.Prefixes.BGPPrefixes.List(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
addressing.PrefixBGPPrefixListParams{
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestPrefixBGPPrefixEditWithOptionalParams(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.Addressing.Prefixes.BGP.Prefixes.Edit(
_, err := client.Addressing.Prefixes.BGPPrefixes.Edit(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
"023e105f4ecef8ad9ca31a8372d0c353",
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestPrefixBGPPrefixGet(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.Addressing.Prefixes.BGP.Prefixes.Get(
_, err := client.Addressing.Prefixes.BGPPrefixes.Get(
context.TODO(),
"023e105f4ecef8ad9ca31a8372d0c353",
"023e105f4ecef8ad9ca31a8372d0c353",
Expand Down
Loading

0 comments on commit 5d9860b

Please sign in to comment.