33package cloudforce_one
44
55import (
6+ "bytes"
7+ "context"
8+ "errors"
9+ "fmt"
10+ "io"
11+ "mime/multipart"
12+ "net/http"
13+
14+ "github.com/cloudflare/cloudflare-go/v4/internal/apiform"
15+ "github.com/cloudflare/cloudflare-go/v4/internal/apijson"
16+ "github.com/cloudflare/cloudflare-go/v4/internal/param"
17+ "github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
618 "github.com/cloudflare/cloudflare-go/v4/option"
719)
820
@@ -24,3 +36,94 @@ func NewBinaryStorageService(opts ...option.RequestOption) (r *BinaryStorageServ
2436 r .Options = opts
2537 return
2638}
39+
40+ // Posts a file to BinDB
41+ func (r * BinaryStorageService ) New (ctx context.Context , params BinaryStorageNewParams , opts ... option.RequestOption ) (res * BinaryStorageNewResponse , err error ) {
42+ opts = append (r .Options [:], opts ... )
43+ if params .AccountID .Value == "" {
44+ err = errors .New ("missing required account_id parameter" )
45+ return
46+ }
47+ path := fmt .Sprintf ("accounts/%s/cloudforce-one/binary" , params .AccountID )
48+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , params , & res , opts ... )
49+ return
50+ }
51+
52+ // Posts a file to BinDB
53+ func (r * BinaryStorageService ) Get (ctx context.Context , hash string , query BinaryStorageGetParams , opts ... option.RequestOption ) (err error ) {
54+ opts = append (r .Options [:], opts ... )
55+ opts = append ([]option.RequestOption {option .WithHeader ("Accept" , "" )}, opts ... )
56+ if query .AccountID .Value == "" {
57+ err = errors .New ("missing required account_id parameter" )
58+ return
59+ }
60+ if hash == "" {
61+ err = errors .New ("missing required hash parameter" )
62+ return
63+ }
64+ path := fmt .Sprintf ("accounts/%s/cloudforce-one/binary/%s" , query .AccountID , hash )
65+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , nil , nil , opts ... )
66+ return
67+ }
68+
69+ type BinaryStorageNewResponse struct {
70+ AccountIDs []string `json:"accountIds,required"`
71+ ContentType string `json:"content_type,required"`
72+ Filenames []string `json:"filenames,required"`
73+ FirstSeen float64 `json:"first_seen,required"`
74+ IsPrivate bool `json:"is_private,required"`
75+ Md5 string `json:"md5,required"`
76+ Sha1 string `json:"sha1,required"`
77+ Sha256 string `json:"sha256,required"`
78+ JSON binaryStorageNewResponseJSON `json:"-"`
79+ }
80+
81+ // binaryStorageNewResponseJSON contains the JSON metadata for the struct
82+ // [BinaryStorageNewResponse]
83+ type binaryStorageNewResponseJSON struct {
84+ AccountIDs apijson.Field
85+ ContentType apijson.Field
86+ Filenames apijson.Field
87+ FirstSeen apijson.Field
88+ IsPrivate apijson.Field
89+ Md5 apijson.Field
90+ Sha1 apijson.Field
91+ Sha256 apijson.Field
92+ raw string
93+ ExtraFields map [string ]apijson.Field
94+ }
95+
96+ func (r * BinaryStorageNewResponse ) UnmarshalJSON (data []byte ) (err error ) {
97+ return apijson .UnmarshalRoot (data , r )
98+ }
99+
100+ func (r binaryStorageNewResponseJSON ) RawJSON () string {
101+ return r .raw
102+ }
103+
104+ type BinaryStorageNewParams struct {
105+ // Account ID.
106+ AccountID param.Field [string ] `path:"account_id,required"`
107+ // The binary file content to upload.
108+ File param.Field [io.Reader ] `json:"file,required" format:"binary"`
109+ }
110+
111+ func (r BinaryStorageNewParams ) MarshalMultipart () (data []byte , contentType string , err error ) {
112+ buf := bytes .NewBuffer (nil )
113+ writer := multipart .NewWriter (buf )
114+ err = apiform .MarshalRoot (r , writer )
115+ if err != nil {
116+ writer .Close ()
117+ return nil , "" , err
118+ }
119+ err = writer .Close ()
120+ if err != nil {
121+ return nil , "" , err
122+ }
123+ return buf .Bytes (), writer .FormDataContentType (), nil
124+ }
125+
126+ type BinaryStorageGetParams struct {
127+ // Account ID.
128+ AccountID param.Field [string ] `path:"account_id,required"`
129+ }
0 commit comments