Skip to content

Commit 2d0f886

Browse files
feat(addressing_load): add deprecation to LOA api (#4209)
* feat(addressing_loa): add deprecation to LOA api
1 parent 496a17a commit 2d0f886

File tree

3 files changed

+256
-0
lines changed

3 files changed

+256
-0
lines changed

addressing/loadocument.go

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
package addressing
44

55
import (
6+
"bytes"
67
"context"
78
"errors"
89
"fmt"
10+
"mime/multipart"
911
"net/http"
1012
"slices"
13+
"time"
1114

15+
"github.com/cloudflare/cloudflare-go/v6/internal/apiform"
16+
"github.com/cloudflare/cloudflare-go/v6/internal/apijson"
1217
"github.com/cloudflare/cloudflare-go/v6/internal/param"
1318
"github.com/cloudflare/cloudflare-go/v6/internal/requestconfig"
1419
"github.com/cloudflare/cloudflare-go/v6/option"
@@ -33,6 +38,25 @@ func NewLOADocumentService(opts ...option.RequestOption) (r *LOADocumentService)
3338
return
3439
}
3540

41+
// Submit LOA document (pdf format) under the account.
42+
//
43+
// Deprecated: This is API is deprecated and will be removed in a future release.
44+
func (r *LOADocumentService) New(ctx context.Context, params LOADocumentNewParams, opts ...option.RequestOption) (res *LOADocumentNewResponse, err error) {
45+
var env LOADocumentNewResponseEnvelope
46+
opts = slices.Concat(r.Options, opts)
47+
if params.AccountID.Value == "" {
48+
err = errors.New("missing required account_id parameter")
49+
return
50+
}
51+
path := fmt.Sprintf("accounts/%s/addressing/loa_documents", params.AccountID)
52+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
53+
if err != nil {
54+
return
55+
}
56+
res = &env.Result
57+
return
58+
}
59+
3660
// Download specified LOA document under the account.
3761
func (r *LOADocumentService) Get(ctx context.Context, loaDocumentID string, query LOADocumentGetParams, opts ...option.RequestOption) (res *http.Response, err error) {
3862
opts = slices.Concat(r.Options, opts)
@@ -50,6 +74,206 @@ func (r *LOADocumentService) Get(ctx context.Context, loaDocumentID string, quer
5074
return
5175
}
5276

77+
type LOADocumentNewResponse struct {
78+
// Identifier for the uploaded LOA document.
79+
ID string `json:"id,nullable"`
80+
// Identifier of a Cloudflare account.
81+
AccountID string `json:"account_id"`
82+
Created time.Time `json:"created" format:"date-time"`
83+
// Name of LOA document. Max file size 10MB, and supported filetype is pdf.
84+
Filename string `json:"filename"`
85+
// File size of the uploaded LOA document.
86+
SizeBytes int64 `json:"size_bytes"`
87+
// Whether the LOA has been verified by Cloudflare staff.
88+
Verified bool `json:"verified"`
89+
// Timestamp of the moment the LOA was marked as validated.
90+
VerifiedAt time.Time `json:"verified_at,nullable" format:"date-time"`
91+
JSON loaDocumentNewResponseJSON `json:"-"`
92+
}
93+
94+
// loaDocumentNewResponseJSON contains the JSON metadata for the struct
95+
// [LOADocumentNewResponse]
96+
type loaDocumentNewResponseJSON struct {
97+
ID apijson.Field
98+
AccountID apijson.Field
99+
Created apijson.Field
100+
Filename apijson.Field
101+
SizeBytes apijson.Field
102+
Verified apijson.Field
103+
VerifiedAt apijson.Field
104+
raw string
105+
ExtraFields map[string]apijson.Field
106+
}
107+
108+
func (r *LOADocumentNewResponse) UnmarshalJSON(data []byte) (err error) {
109+
return apijson.UnmarshalRoot(data, r)
110+
}
111+
112+
func (r loaDocumentNewResponseJSON) RawJSON() string {
113+
return r.raw
114+
}
115+
116+
type LOADocumentNewParams struct {
117+
// Identifier of a Cloudflare account.
118+
AccountID param.Field[string] `path:"account_id,required"`
119+
// LOA document to upload.
120+
LOADocument param.Field[string] `json:"loa_document,required"`
121+
}
122+
123+
func (r LOADocumentNewParams) MarshalMultipart() (data []byte, contentType string, err error) {
124+
buf := bytes.NewBuffer(nil)
125+
writer := multipart.NewWriter(buf)
126+
err = apiform.MarshalRoot(r, writer)
127+
if err != nil {
128+
writer.Close()
129+
return nil, "", err
130+
}
131+
err = writer.Close()
132+
if err != nil {
133+
return nil, "", err
134+
}
135+
return buf.Bytes(), writer.FormDataContentType(), nil
136+
}
137+
138+
type LOADocumentNewResponseEnvelope struct {
139+
Errors []LOADocumentNewResponseEnvelopeErrors `json:"errors,required"`
140+
Messages []LOADocumentNewResponseEnvelopeMessages `json:"messages,required"`
141+
// Whether the API call was successful.
142+
Success LOADocumentNewResponseEnvelopeSuccess `json:"success,required"`
143+
Result LOADocumentNewResponse `json:"result"`
144+
JSON loaDocumentNewResponseEnvelopeJSON `json:"-"`
145+
}
146+
147+
// loaDocumentNewResponseEnvelopeJSON contains the JSON metadata for the struct
148+
// [LOADocumentNewResponseEnvelope]
149+
type loaDocumentNewResponseEnvelopeJSON struct {
150+
Errors apijson.Field
151+
Messages apijson.Field
152+
Success apijson.Field
153+
Result apijson.Field
154+
raw string
155+
ExtraFields map[string]apijson.Field
156+
}
157+
158+
func (r *LOADocumentNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
159+
return apijson.UnmarshalRoot(data, r)
160+
}
161+
162+
func (r loaDocumentNewResponseEnvelopeJSON) RawJSON() string {
163+
return r.raw
164+
}
165+
166+
type LOADocumentNewResponseEnvelopeErrors struct {
167+
Code int64 `json:"code,required"`
168+
Message string `json:"message,required"`
169+
DocumentationURL string `json:"documentation_url"`
170+
Source LOADocumentNewResponseEnvelopeErrorsSource `json:"source"`
171+
JSON loaDocumentNewResponseEnvelopeErrorsJSON `json:"-"`
172+
}
173+
174+
// loaDocumentNewResponseEnvelopeErrorsJSON contains the JSON metadata for the
175+
// struct [LOADocumentNewResponseEnvelopeErrors]
176+
type loaDocumentNewResponseEnvelopeErrorsJSON struct {
177+
Code apijson.Field
178+
Message apijson.Field
179+
DocumentationURL apijson.Field
180+
Source apijson.Field
181+
raw string
182+
ExtraFields map[string]apijson.Field
183+
}
184+
185+
func (r *LOADocumentNewResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) {
186+
return apijson.UnmarshalRoot(data, r)
187+
}
188+
189+
func (r loaDocumentNewResponseEnvelopeErrorsJSON) RawJSON() string {
190+
return r.raw
191+
}
192+
193+
type LOADocumentNewResponseEnvelopeErrorsSource struct {
194+
Pointer string `json:"pointer"`
195+
JSON loaDocumentNewResponseEnvelopeErrorsSourceJSON `json:"-"`
196+
}
197+
198+
// loaDocumentNewResponseEnvelopeErrorsSourceJSON contains the JSON metadata for
199+
// the struct [LOADocumentNewResponseEnvelopeErrorsSource]
200+
type loaDocumentNewResponseEnvelopeErrorsSourceJSON struct {
201+
Pointer apijson.Field
202+
raw string
203+
ExtraFields map[string]apijson.Field
204+
}
205+
206+
func (r *LOADocumentNewResponseEnvelopeErrorsSource) UnmarshalJSON(data []byte) (err error) {
207+
return apijson.UnmarshalRoot(data, r)
208+
}
209+
210+
func (r loaDocumentNewResponseEnvelopeErrorsSourceJSON) RawJSON() string {
211+
return r.raw
212+
}
213+
214+
type LOADocumentNewResponseEnvelopeMessages struct {
215+
Code int64 `json:"code,required"`
216+
Message string `json:"message,required"`
217+
DocumentationURL string `json:"documentation_url"`
218+
Source LOADocumentNewResponseEnvelopeMessagesSource `json:"source"`
219+
JSON loaDocumentNewResponseEnvelopeMessagesJSON `json:"-"`
220+
}
221+
222+
// loaDocumentNewResponseEnvelopeMessagesJSON contains the JSON metadata for the
223+
// struct [LOADocumentNewResponseEnvelopeMessages]
224+
type loaDocumentNewResponseEnvelopeMessagesJSON struct {
225+
Code apijson.Field
226+
Message apijson.Field
227+
DocumentationURL apijson.Field
228+
Source apijson.Field
229+
raw string
230+
ExtraFields map[string]apijson.Field
231+
}
232+
233+
func (r *LOADocumentNewResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) {
234+
return apijson.UnmarshalRoot(data, r)
235+
}
236+
237+
func (r loaDocumentNewResponseEnvelopeMessagesJSON) RawJSON() string {
238+
return r.raw
239+
}
240+
241+
type LOADocumentNewResponseEnvelopeMessagesSource struct {
242+
Pointer string `json:"pointer"`
243+
JSON loaDocumentNewResponseEnvelopeMessagesSourceJSON `json:"-"`
244+
}
245+
246+
// loaDocumentNewResponseEnvelopeMessagesSourceJSON contains the JSON metadata for
247+
// the struct [LOADocumentNewResponseEnvelopeMessagesSource]
248+
type loaDocumentNewResponseEnvelopeMessagesSourceJSON struct {
249+
Pointer apijson.Field
250+
raw string
251+
ExtraFields map[string]apijson.Field
252+
}
253+
254+
func (r *LOADocumentNewResponseEnvelopeMessagesSource) UnmarshalJSON(data []byte) (err error) {
255+
return apijson.UnmarshalRoot(data, r)
256+
}
257+
258+
func (r loaDocumentNewResponseEnvelopeMessagesSourceJSON) RawJSON() string {
259+
return r.raw
260+
}
261+
262+
// Whether the API call was successful.
263+
type LOADocumentNewResponseEnvelopeSuccess bool
264+
265+
const (
266+
LOADocumentNewResponseEnvelopeSuccessTrue LOADocumentNewResponseEnvelopeSuccess = true
267+
)
268+
269+
func (r LOADocumentNewResponseEnvelopeSuccess) IsKnown() bool {
270+
switch r {
271+
case LOADocumentNewResponseEnvelopeSuccessTrue:
272+
return true
273+
}
274+
return false
275+
}
276+
53277
type LOADocumentGetParams struct {
54278
// Identifier of a Cloudflare account.
55279
AccountID param.Field[string] `path:"account_id,required"`

addressing/loadocument_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,42 @@ import (
99
"io"
1010
"net/http"
1111
"net/http/httptest"
12+
"os"
1213
"testing"
1314

1415
"github.com/cloudflare/cloudflare-go/v6"
1516
"github.com/cloudflare/cloudflare-go/v6/addressing"
17+
"github.com/cloudflare/cloudflare-go/v6/internal/testutil"
1618
"github.com/cloudflare/cloudflare-go/v6/option"
1719
)
1820

21+
func TestLOADocumentNew(t *testing.T) {
22+
t.Skip("TODO: investigate broken test")
23+
baseURL := "http://localhost:4010"
24+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
25+
baseURL = envURL
26+
}
27+
if !testutil.CheckTestServer(t, baseURL) {
28+
return
29+
}
30+
client := cloudflare.NewClient(
31+
option.WithBaseURL(baseURL),
32+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
33+
option.WithAPIEmail("user@example.com"),
34+
)
35+
_, err := client.Addressing.LOADocuments.New(context.TODO(), addressing.LOADocumentNewParams{
36+
AccountID: cloudflare.F("258def64c72dae45f3e4c8516e2111f2"),
37+
LOADocument: cloudflare.F("@document.pdf"),
38+
})
39+
if err != nil {
40+
var apierr *cloudflare.Error
41+
if errors.As(err, &apierr) {
42+
t.Log(string(apierr.DumpRequest(true)))
43+
}
44+
t.Fatalf("err should be nil: %s", err.Error())
45+
}
46+
}
47+
1948
func TestLOADocumentGet(t *testing.T) {
2049
t.Skip("TODO: address broken spotlight error - https://github.com/cloudflare/cloudflare-typescript/actions/runs/9456639475/job/26048931174?pr=498#step:5:489")
2150
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

addressing/prefix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ type PrefixNewParams struct {
390390
DelegateLOACreation param.Field[bool] `json:"delegate_loa_creation"`
391391
// Description of the prefix.
392392
Description param.Field[string] `json:"description"`
393+
// Identifier for the uploaded LOA document.
394+
// Deprecated: The LOA API is deprecated and will be removed in a future release.
395+
LOADocumentID param.Field[string] `json:"loa_document_id"`
393396
}
394397

395398
func (r PrefixNewParams) MarshalJSON() (data []byte, err error) {

0 commit comments

Comments
 (0)