1
- package lowlevel
1
+ package uploadrevision
2
2
3
3
import (
4
4
"bytes"
@@ -16,17 +16,17 @@ import (
16
16
17
17
// SealableClient defines the interface for file upload API operations.
18
18
type SealableClient interface {
19
- CreateRevision (ctx context.Context , orgID OrgID ) (* UploadRevisionResponseBody , error )
19
+ CreateRevision (ctx context.Context , orgID OrgID ) (* ResponseBody , error )
20
20
UploadFiles (ctx context.Context , orgID OrgID , revisionID RevisionID , files []UploadFile ) error
21
- SealRevision (ctx context.Context , orgID OrgID , revisionID RevisionID ) (* SealUploadRevisionResponseBody , error )
21
+ SealRevision (ctx context.Context , orgID OrgID , revisionID RevisionID ) (* SealResponseBody , error )
22
22
23
23
GetLimits () Limits
24
24
}
25
25
26
26
// This will force go to complain if the type doesn't satisfy the interface.
27
27
var _ SealableClient = (* HTTPSealableClient )(nil )
28
28
29
- // Config contains configuration for the file upload client.
29
+ // Config contains the configuration for the file upload client.
30
30
type Config struct {
31
31
BaseURL string
32
32
}
@@ -37,8 +37,8 @@ type HTTPSealableClient struct {
37
37
httpClient * http.Client
38
38
}
39
39
40
- // APIVersion specifies the API version to use for requests.
41
- const APIVersion = "2024-10-15"
40
+ // apiVersion specifies the API version to use for requests.
41
+ const apiVersion = "2024-10-15"
42
42
43
43
const (
44
44
fileSizeLimit = 50_000_000 // arbitrary number, chosen to support max size of SBOMs
@@ -63,14 +63,14 @@ func NewClient(cfg Config, opts ...Opt) *HTTPSealableClient {
63
63
}
64
64
65
65
// CreateRevision creates a new upload revision for the specified organization.
66
- func (c * HTTPSealableClient ) CreateRevision (ctx context.Context , orgID OrgID ) (* UploadRevisionResponseBody , error ) {
66
+ func (c * HTTPSealableClient ) CreateRevision (ctx context.Context , orgID OrgID ) (* ResponseBody , error ) {
67
67
if orgID == uuid .Nil {
68
68
return nil , ErrEmptyOrgID
69
69
}
70
70
71
- body := UploadRevisionRequestBody {
72
- Data : UploadRevisionRequestData {
73
- Attributes : UploadRevisionRequestAttributes {
71
+ body := RequestBody {
72
+ Data : RequestData {
73
+ Attributes : RequestAttributes {
74
74
RevisionType : RevisionTypeSnapshot ,
75
75
},
76
76
Type : ResourceTypeUploadRevision ,
@@ -81,7 +81,7 @@ func (c *HTTPSealableClient) CreateRevision(ctx context.Context, orgID OrgID) (*
81
81
return nil , fmt .Errorf ("failed to encode request body: %w" , err )
82
82
}
83
83
84
- url := fmt .Sprintf ("%s/hidden/orgs/%s/upload_revisions?version=%s" , c .cfg .BaseURL , orgID , APIVersion )
84
+ url := fmt .Sprintf ("%s/hidden/orgs/%s/upload_revisions?version=%s" , c .cfg .BaseURL , orgID , apiVersion )
85
85
req , err := http .NewRequestWithContext (ctx , http .MethodPost , url , buff )
86
86
if err != nil {
87
87
return nil , fmt .Errorf ("failed to create revision request: %w" , err )
@@ -98,7 +98,7 @@ func (c *HTTPSealableClient) CreateRevision(ctx context.Context, orgID OrgID) (*
98
98
return nil , handleUnexpectedStatusCodes (res .Body , res .StatusCode , res .Status , "create upload revision" )
99
99
}
100
100
101
- var respBody UploadRevisionResponseBody
101
+ var respBody ResponseBody
102
102
if err := json .NewDecoder (res .Body ).Decode (& respBody ); err != nil {
103
103
return nil , fmt .Errorf ("failed to decode upload revision response: %w" , err )
104
104
}
@@ -128,7 +128,7 @@ func (c *HTTPSealableClient) UploadFiles(ctx context.Context, orgID OrgID, revis
128
128
129
129
go streamFilesToPipe (pipeWriter , mpartWriter , files )
130
130
131
- url := fmt .Sprintf ("%s/hidden/orgs/%s/upload_revisions/%s/files?version=%s" , c .cfg .BaseURL , orgID , revisionID , APIVersion )
131
+ url := fmt .Sprintf ("%s/hidden/orgs/%s/upload_revisions/%s/files?version=%s" , c .cfg .BaseURL , orgID , revisionID , apiVersion )
132
132
req , err := http .NewRequestWithContext (ctx , http .MethodPost , url , pipeReader )
133
133
if err != nil {
134
134
return fmt .Errorf ("failed to create upload files request: %w" , err )
@@ -202,7 +202,7 @@ func validateFiles(files []UploadFile) error {
202
202
}
203
203
204
204
// SealRevision seals the specified upload revision, marking it as complete.
205
- func (c * HTTPSealableClient ) SealRevision (ctx context.Context , orgID OrgID , revisionID RevisionID ) (* SealUploadRevisionResponseBody , error ) {
205
+ func (c * HTTPSealableClient ) SealRevision (ctx context.Context , orgID OrgID , revisionID RevisionID ) (* SealResponseBody , error ) {
206
206
if orgID == uuid .Nil {
207
207
return nil , ErrEmptyOrgID
208
208
}
@@ -211,10 +211,10 @@ func (c *HTTPSealableClient) SealRevision(ctx context.Context, orgID OrgID, revi
211
211
return nil , ErrEmptyRevisionID
212
212
}
213
213
214
- body := SealUploadRevisionRequestBody {
215
- Data : SealUploadRevisionRequestData {
214
+ body := SealRequestBody {
215
+ Data : SealRequestData {
216
216
ID : revisionID ,
217
- Attributes : SealUploadRevisionRequestAttributes {
217
+ Attributes : SealRequestAttributes {
218
218
Sealed : true ,
219
219
},
220
220
Type : ResourceTypeUploadRevision ,
@@ -225,7 +225,7 @@ func (c *HTTPSealableClient) SealRevision(ctx context.Context, orgID OrgID, revi
225
225
return nil , fmt .Errorf ("failed to encode request body: %w" , err )
226
226
}
227
227
228
- url := fmt .Sprintf ("%s/hidden/orgs/%s/upload_revisions/%s?version=%s" , c .cfg .BaseURL , orgID , revisionID , APIVersion )
228
+ url := fmt .Sprintf ("%s/hidden/orgs/%s/upload_revisions/%s?version=%s" , c .cfg .BaseURL , orgID , revisionID , apiVersion )
229
229
req , err := http .NewRequestWithContext (ctx , http .MethodPatch , url , buff )
230
230
if err != nil {
231
231
return nil , fmt .Errorf ("failed to create seal request: %w" , err )
@@ -242,7 +242,7 @@ func (c *HTTPSealableClient) SealRevision(ctx context.Context, orgID OrgID, revi
242
242
return nil , handleUnexpectedStatusCodes (res .Body , res .StatusCode , res .Status , "seal upload revision" )
243
243
}
244
244
245
- var respBody SealUploadRevisionResponseBody
245
+ var respBody SealResponseBody
246
246
if err := json .NewDecoder (res .Body ).Decode (& respBody ); err != nil {
247
247
return nil , fmt .Errorf ("failed to decode upload revision response: %w" , err )
248
248
}
0 commit comments