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