Skip to content

Commit 5d9860b

Browse files
committedJan 7, 2025·
feat(addressing)!: reshuffle relationship in the namespace to align with the product (#3789)
1 parent 9ac9789 commit 5d9860b

7 files changed

+259
-289
lines changed
 

‎addressing/prefix.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import (
2424
// automatically. You should not instantiate this service directly, and instead use
2525
// the [NewPrefixService] method instead.
2626
type PrefixService struct {
27-
Options []option.RequestOption
28-
ServiceBindings *PrefixServiceBindingService
29-
BGP *PrefixBGPService
30-
Delegations *PrefixDelegationService
27+
Options []option.RequestOption
28+
ServiceBindings *PrefixServiceBindingService
29+
BGPPrefixes *PrefixBGPPrefixService
30+
AdvertisementStatus *PrefixAdvertisementStatusService
31+
Delegations *PrefixDelegationService
3132
}
3233

3334
// NewPrefixService generates a new service that applies the given options to each
@@ -37,7 +38,8 @@ func NewPrefixService(opts ...option.RequestOption) (r *PrefixService) {
3738
r = &PrefixService{}
3839
r.Options = opts
3940
r.ServiceBindings = NewPrefixServiceBindingService(opts...)
40-
r.BGP = NewPrefixBGPService(opts...)
41+
r.BGPPrefixes = NewPrefixBGPPrefixService(opts...)
42+
r.AdvertisementStatus = NewPrefixAdvertisementStatusService(opts...)
4143
r.Delegations = NewPrefixDelegationService(opts...)
4244
return
4345
}
+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package addressing
4+
5+
import (
6+
"context"
7+
"errors"
8+
"fmt"
9+
"net/http"
10+
"time"
11+
12+
"github.com/cloudflare/cloudflare-go/v3/internal/apijson"
13+
"github.com/cloudflare/cloudflare-go/v3/internal/param"
14+
"github.com/cloudflare/cloudflare-go/v3/internal/requestconfig"
15+
"github.com/cloudflare/cloudflare-go/v3/option"
16+
"github.com/cloudflare/cloudflare-go/v3/shared"
17+
)
18+
19+
// PrefixAdvertisementStatusService contains methods and other services that help
20+
// with interacting with the cloudflare API.
21+
//
22+
// Note, unlike clients, this service does not read variables from the environment
23+
// automatically. You should not instantiate this service directly, and instead use
24+
// the [NewPrefixAdvertisementStatusService] method instead.
25+
type PrefixAdvertisementStatusService struct {
26+
Options []option.RequestOption
27+
}
28+
29+
// NewPrefixAdvertisementStatusService generates a new service that applies the
30+
// given options to each request. These options are applied after the parent
31+
// client's options (if there is one), and before any request-specific options.
32+
func NewPrefixAdvertisementStatusService(opts ...option.RequestOption) (r *PrefixAdvertisementStatusService) {
33+
r = &PrefixAdvertisementStatusService{}
34+
r.Options = opts
35+
return
36+
}
37+
38+
// Advertise or withdraw BGP route for a prefix.
39+
func (r *PrefixAdvertisementStatusService) Edit(ctx context.Context, prefixID string, params PrefixAdvertisementStatusEditParams, opts ...option.RequestOption) (res *PrefixAdvertisementStatusEditResponse, err error) {
40+
var env PrefixAdvertisementStatusEditResponseEnvelope
41+
opts = append(r.Options[:], opts...)
42+
if params.AccountID.Value == "" {
43+
err = errors.New("missing required account_id parameter")
44+
return
45+
}
46+
if prefixID == "" {
47+
err = errors.New("missing required prefix_id parameter")
48+
return
49+
}
50+
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bgp/status", params.AccountID, prefixID)
51+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
52+
if err != nil {
53+
return
54+
}
55+
res = &env.Result
56+
return
57+
}
58+
59+
// List the current advertisement state for a prefix.
60+
func (r *PrefixAdvertisementStatusService) Get(ctx context.Context, prefixID string, query PrefixAdvertisementStatusGetParams, opts ...option.RequestOption) (res *PrefixAdvertisementStatusGetResponse, err error) {
61+
var env PrefixAdvertisementStatusGetResponseEnvelope
62+
opts = append(r.Options[:], opts...)
63+
if query.AccountID.Value == "" {
64+
err = errors.New("missing required account_id parameter")
65+
return
66+
}
67+
if prefixID == "" {
68+
err = errors.New("missing required prefix_id parameter")
69+
return
70+
}
71+
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bgp/status", query.AccountID, prefixID)
72+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
73+
if err != nil {
74+
return
75+
}
76+
res = &env.Result
77+
return
78+
}
79+
80+
type PrefixAdvertisementStatusEditResponse struct {
81+
// Enablement of prefix advertisement to the Internet.
82+
Advertised bool `json:"advertised"`
83+
// Last time the advertisement status was changed. This field is only not 'null' if
84+
// on demand is enabled.
85+
AdvertisedModifiedAt time.Time `json:"advertised_modified_at,nullable" format:"date-time"`
86+
JSON prefixAdvertisementStatusEditResponseJSON `json:"-"`
87+
}
88+
89+
// prefixAdvertisementStatusEditResponseJSON contains the JSON metadata for the
90+
// struct [PrefixAdvertisementStatusEditResponse]
91+
type prefixAdvertisementStatusEditResponseJSON struct {
92+
Advertised apijson.Field
93+
AdvertisedModifiedAt apijson.Field
94+
raw string
95+
ExtraFields map[string]apijson.Field
96+
}
97+
98+
func (r *PrefixAdvertisementStatusEditResponse) UnmarshalJSON(data []byte) (err error) {
99+
return apijson.UnmarshalRoot(data, r)
100+
}
101+
102+
func (r prefixAdvertisementStatusEditResponseJSON) RawJSON() string {
103+
return r.raw
104+
}
105+
106+
type PrefixAdvertisementStatusGetResponse struct {
107+
// Enablement of prefix advertisement to the Internet.
108+
Advertised bool `json:"advertised"`
109+
// Last time the advertisement status was changed. This field is only not 'null' if
110+
// on demand is enabled.
111+
AdvertisedModifiedAt time.Time `json:"advertised_modified_at,nullable" format:"date-time"`
112+
JSON prefixAdvertisementStatusGetResponseJSON `json:"-"`
113+
}
114+
115+
// prefixAdvertisementStatusGetResponseJSON contains the JSON metadata for the
116+
// struct [PrefixAdvertisementStatusGetResponse]
117+
type prefixAdvertisementStatusGetResponseJSON struct {
118+
Advertised apijson.Field
119+
AdvertisedModifiedAt apijson.Field
120+
raw string
121+
ExtraFields map[string]apijson.Field
122+
}
123+
124+
func (r *PrefixAdvertisementStatusGetResponse) UnmarshalJSON(data []byte) (err error) {
125+
return apijson.UnmarshalRoot(data, r)
126+
}
127+
128+
func (r prefixAdvertisementStatusGetResponseJSON) RawJSON() string {
129+
return r.raw
130+
}
131+
132+
type PrefixAdvertisementStatusEditParams struct {
133+
// Identifier
134+
AccountID param.Field[string] `path:"account_id,required"`
135+
// Enablement of prefix advertisement to the Internet.
136+
Advertised param.Field[bool] `json:"advertised,required"`
137+
}
138+
139+
func (r PrefixAdvertisementStatusEditParams) MarshalJSON() (data []byte, err error) {
140+
return apijson.MarshalRoot(r)
141+
}
142+
143+
type PrefixAdvertisementStatusEditResponseEnvelope struct {
144+
Errors []shared.ResponseInfo `json:"errors,required"`
145+
Messages []shared.ResponseInfo `json:"messages,required"`
146+
// Whether the API call was successful
147+
Success PrefixAdvertisementStatusEditResponseEnvelopeSuccess `json:"success,required"`
148+
Result PrefixAdvertisementStatusEditResponse `json:"result"`
149+
JSON prefixAdvertisementStatusEditResponseEnvelopeJSON `json:"-"`
150+
}
151+
152+
// prefixAdvertisementStatusEditResponseEnvelopeJSON contains the JSON metadata for
153+
// the struct [PrefixAdvertisementStatusEditResponseEnvelope]
154+
type prefixAdvertisementStatusEditResponseEnvelopeJSON struct {
155+
Errors apijson.Field
156+
Messages apijson.Field
157+
Success apijson.Field
158+
Result apijson.Field
159+
raw string
160+
ExtraFields map[string]apijson.Field
161+
}
162+
163+
func (r *PrefixAdvertisementStatusEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
164+
return apijson.UnmarshalRoot(data, r)
165+
}
166+
167+
func (r prefixAdvertisementStatusEditResponseEnvelopeJSON) RawJSON() string {
168+
return r.raw
169+
}
170+
171+
// Whether the API call was successful
172+
type PrefixAdvertisementStatusEditResponseEnvelopeSuccess bool
173+
174+
const (
175+
PrefixAdvertisementStatusEditResponseEnvelopeSuccessTrue PrefixAdvertisementStatusEditResponseEnvelopeSuccess = true
176+
)
177+
178+
func (r PrefixAdvertisementStatusEditResponseEnvelopeSuccess) IsKnown() bool {
179+
switch r {
180+
case PrefixAdvertisementStatusEditResponseEnvelopeSuccessTrue:
181+
return true
182+
}
183+
return false
184+
}
185+
186+
type PrefixAdvertisementStatusGetParams struct {
187+
// Identifier
188+
AccountID param.Field[string] `path:"account_id,required"`
189+
}
190+
191+
type PrefixAdvertisementStatusGetResponseEnvelope struct {
192+
Errors []shared.ResponseInfo `json:"errors,required"`
193+
Messages []shared.ResponseInfo `json:"messages,required"`
194+
// Whether the API call was successful
195+
Success PrefixAdvertisementStatusGetResponseEnvelopeSuccess `json:"success,required"`
196+
Result PrefixAdvertisementStatusGetResponse `json:"result"`
197+
JSON prefixAdvertisementStatusGetResponseEnvelopeJSON `json:"-"`
198+
}
199+
200+
// prefixAdvertisementStatusGetResponseEnvelopeJSON contains the JSON metadata for
201+
// the struct [PrefixAdvertisementStatusGetResponseEnvelope]
202+
type prefixAdvertisementStatusGetResponseEnvelopeJSON struct {
203+
Errors apijson.Field
204+
Messages apijson.Field
205+
Success apijson.Field
206+
Result apijson.Field
207+
raw string
208+
ExtraFields map[string]apijson.Field
209+
}
210+
211+
func (r *PrefixAdvertisementStatusGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
212+
return apijson.UnmarshalRoot(data, r)
213+
}
214+
215+
func (r prefixAdvertisementStatusGetResponseEnvelopeJSON) RawJSON() string {
216+
return r.raw
217+
}
218+
219+
// Whether the API call was successful
220+
type PrefixAdvertisementStatusGetResponseEnvelopeSuccess bool
221+
222+
const (
223+
PrefixAdvertisementStatusGetResponseEnvelopeSuccessTrue PrefixAdvertisementStatusGetResponseEnvelopeSuccess = true
224+
)
225+
226+
func (r PrefixAdvertisementStatusGetResponseEnvelopeSuccess) IsKnown() bool {
227+
switch r {
228+
case PrefixAdvertisementStatusGetResponseEnvelopeSuccessTrue:
229+
return true
230+
}
231+
return false
232+
}

‎addressing/prefixbgpstatus_test.go ‎addressing/prefixadvertisementstatus_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/cloudflare/cloudflare-go/v3/option"
1515
)
1616

17-
func TestPrefixBGPStatusEdit(t *testing.T) {
17+
func TestPrefixAdvertisementStatusEdit(t *testing.T) {
1818
baseURL := "http://localhost:4010"
1919
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
2020
baseURL = envURL
@@ -27,10 +27,10 @@ func TestPrefixBGPStatusEdit(t *testing.T) {
2727
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
2828
option.WithAPIEmail("user@example.com"),
2929
)
30-
_, err := client.Addressing.Prefixes.BGP.Statuses.Edit(
30+
_, err := client.Addressing.Prefixes.AdvertisementStatus.Edit(
3131
context.TODO(),
3232
"023e105f4ecef8ad9ca31a8372d0c353",
33-
addressing.PrefixBGPStatusEditParams{
33+
addressing.PrefixAdvertisementStatusEditParams{
3434
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
3535
Advertised: cloudflare.F(true),
3636
},
@@ -44,7 +44,7 @@ func TestPrefixBGPStatusEdit(t *testing.T) {
4444
}
4545
}
4646

47-
func TestPrefixBGPStatusGet(t *testing.T) {
47+
func TestPrefixAdvertisementStatusGet(t *testing.T) {
4848
baseURL := "http://localhost:4010"
4949
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
5050
baseURL = envURL
@@ -57,10 +57,10 @@ func TestPrefixBGPStatusGet(t *testing.T) {
5757
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
5858
option.WithAPIEmail("user@example.com"),
5959
)
60-
_, err := client.Addressing.Prefixes.BGP.Statuses.Get(
60+
_, err := client.Addressing.Prefixes.AdvertisementStatus.Get(
6161
context.TODO(),
6262
"023e105f4ecef8ad9ca31a8372d0c353",
63-
addressing.PrefixBGPStatusGetParams{
63+
addressing.PrefixAdvertisementStatusGetParams{
6464
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
6565
},
6666
)

‎addressing/prefixbgp.go

-30
This file was deleted.

‎addressing/prefixbgpprefix_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestPrefixBGPPrefixNewWithOptionalParams(t *testing.T) {
2727
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
2828
option.WithAPIEmail("user@example.com"),
2929
)
30-
_, err := client.Addressing.Prefixes.BGP.Prefixes.New(
30+
_, err := client.Addressing.Prefixes.BGPPrefixes.New(
3131
context.TODO(),
3232
"023e105f4ecef8ad9ca31a8372d0c353",
3333
addressing.PrefixBGPPrefixNewParams{
@@ -57,7 +57,7 @@ func TestPrefixBGPPrefixList(t *testing.T) {
5757
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
5858
option.WithAPIEmail("user@example.com"),
5959
)
60-
_, err := client.Addressing.Prefixes.BGP.Prefixes.List(
60+
_, err := client.Addressing.Prefixes.BGPPrefixes.List(
6161
context.TODO(),
6262
"023e105f4ecef8ad9ca31a8372d0c353",
6363
addressing.PrefixBGPPrefixListParams{
@@ -86,7 +86,7 @@ func TestPrefixBGPPrefixEditWithOptionalParams(t *testing.T) {
8686
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
8787
option.WithAPIEmail("user@example.com"),
8888
)
89-
_, err := client.Addressing.Prefixes.BGP.Prefixes.Edit(
89+
_, err := client.Addressing.Prefixes.BGPPrefixes.Edit(
9090
context.TODO(),
9191
"023e105f4ecef8ad9ca31a8372d0c353",
9292
"023e105f4ecef8ad9ca31a8372d0c353",
@@ -119,7 +119,7 @@ func TestPrefixBGPPrefixGet(t *testing.T) {
119119
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
120120
option.WithAPIEmail("user@example.com"),
121121
)
122-
_, err := client.Addressing.Prefixes.BGP.Prefixes.Get(
122+
_, err := client.Addressing.Prefixes.BGPPrefixes.Get(
123123
context.TODO(),
124124
"023e105f4ecef8ad9ca31a8372d0c353",
125125
"023e105f4ecef8ad9ca31a8372d0c353",

0 commit comments

Comments
 (0)
Please sign in to comment.