Skip to content

Commit f3eb632

Browse files
Merge pull request #53 from snyk/chore/rename-fileupload-lowlevel-package
chore: rename fileupload lowlevel package to uploadrevision
2 parents 77eb403 + b5cdd40 commit f3eb632

File tree

10 files changed

+209
-207
lines changed

10 files changed

+209
-207
lines changed

internal/fileupload/lowlevel/types.go

Lines changed: 0 additions & 132 deletions
This file was deleted.

internal/fileupload/lowlevel/client.go renamed to internal/fileupload/uploadrevision/client.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package lowlevel
1+
package uploadrevision
22

33
import (
44
"bytes"
@@ -16,17 +16,17 @@ import (
1616

1717
// SealableClient defines the interface for file upload API operations.
1818
type SealableClient interface {
19-
CreateRevision(ctx context.Context, orgID OrgID) (*UploadRevisionResponseBody, error)
19+
CreateRevision(ctx context.Context, orgID OrgID) (*ResponseBody, error)
2020
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)
2222

2323
GetLimits() Limits
2424
}
2525

2626
// This will force go to complain if the type doesn't satisfy the interface.
2727
var _ SealableClient = (*HTTPSealableClient)(nil)
2828

29-
// Config contains configuration for the file upload client.
29+
// Config contains the configuration for the file upload client.
3030
type Config struct {
3131
BaseURL string
3232
}
@@ -37,8 +37,8 @@ type HTTPSealableClient struct {
3737
httpClient *http.Client
3838
}
3939

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"
4242

4343
const (
4444
fileSizeLimit = 50_000_000 // arbitrary number, chosen to support max size of SBOMs
@@ -63,14 +63,14 @@ func NewClient(cfg Config, opts ...Opt) *HTTPSealableClient {
6363
}
6464

6565
// 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) {
6767
if orgID == uuid.Nil {
6868
return nil, ErrEmptyOrgID
6969
}
7070

71-
body := UploadRevisionRequestBody{
72-
Data: UploadRevisionRequestData{
73-
Attributes: UploadRevisionRequestAttributes{
71+
body := RequestBody{
72+
Data: RequestData{
73+
Attributes: RequestAttributes{
7474
RevisionType: RevisionTypeSnapshot,
7575
},
7676
Type: ResourceTypeUploadRevision,
@@ -81,7 +81,7 @@ func (c *HTTPSealableClient) CreateRevision(ctx context.Context, orgID OrgID) (*
8181
return nil, fmt.Errorf("failed to encode request body: %w", err)
8282
}
8383

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)
8585
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, buff)
8686
if err != nil {
8787
return nil, fmt.Errorf("failed to create revision request: %w", err)
@@ -98,7 +98,7 @@ func (c *HTTPSealableClient) CreateRevision(ctx context.Context, orgID OrgID) (*
9898
return nil, handleUnexpectedStatusCodes(res.Body, res.StatusCode, res.Status, "create upload revision")
9999
}
100100

101-
var respBody UploadRevisionResponseBody
101+
var respBody ResponseBody
102102
if err := json.NewDecoder(res.Body).Decode(&respBody); err != nil {
103103
return nil, fmt.Errorf("failed to decode upload revision response: %w", err)
104104
}
@@ -128,7 +128,7 @@ func (c *HTTPSealableClient) UploadFiles(ctx context.Context, orgID OrgID, revis
128128

129129
go streamFilesToPipe(pipeWriter, mpartWriter, files)
130130

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)
132132
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, pipeReader)
133133
if err != nil {
134134
return fmt.Errorf("failed to create upload files request: %w", err)
@@ -202,7 +202,7 @@ func validateFiles(files []UploadFile) error {
202202
}
203203

204204
// 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) {
206206
if orgID == uuid.Nil {
207207
return nil, ErrEmptyOrgID
208208
}
@@ -211,10 +211,10 @@ func (c *HTTPSealableClient) SealRevision(ctx context.Context, orgID OrgID, revi
211211
return nil, ErrEmptyRevisionID
212212
}
213213

214-
body := SealUploadRevisionRequestBody{
215-
Data: SealUploadRevisionRequestData{
214+
body := SealRequestBody{
215+
Data: SealRequestData{
216216
ID: revisionID,
217-
Attributes: SealUploadRevisionRequestAttributes{
217+
Attributes: SealRequestAttributes{
218218
Sealed: true,
219219
},
220220
Type: ResourceTypeUploadRevision,
@@ -225,7 +225,7 @@ func (c *HTTPSealableClient) SealRevision(ctx context.Context, orgID OrgID, revi
225225
return nil, fmt.Errorf("failed to encode request body: %w", err)
226226
}
227227

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)
229229
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, url, buff)
230230
if err != nil {
231231
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
242242
return nil, handleUnexpectedStatusCodes(res.Body, res.StatusCode, res.Status, "seal upload revision")
243243
}
244244

245-
var respBody SealUploadRevisionResponseBody
245+
var respBody SealResponseBody
246246
if err := json.NewDecoder(res.Body).Decode(&respBody); err != nil {
247247
return nil, fmt.Errorf("failed to decode upload revision response: %w", err)
248248
}

0 commit comments

Comments
 (0)