1
- package lowlevel_fileupload //nolint:revive // underscore naming is intentional for this internal package
1
+ package lowlevel
2
2
3
3
import (
4
4
"bytes"
@@ -14,23 +14,23 @@ import (
14
14
"github.com/snyk/error-catalog-golang-public/snyk_errors"
15
15
)
16
16
17
- // Client defines the interface for file upload API operations.
18
- type Client interface {
17
+ // SealableClient defines the interface for file upload API operations.
18
+ type SealableClient interface {
19
19
CreateRevision (ctx context.Context , orgID OrgID ) (* UploadRevisionResponseBody , error )
20
20
UploadFiles (ctx context.Context , orgID OrgID , revisionID RevisionID , files []UploadFile ) error
21
21
SealRevision (ctx context.Context , orgID OrgID , revisionID RevisionID ) (* SealUploadRevisionResponseBody , error )
22
22
}
23
23
24
24
// This will force go to complain if the type doesn't satisfy the interface.
25
- var _ Client = (* HTTPClient )(nil )
25
+ var _ SealableClient = (* HTTPSealableClient )(nil )
26
26
27
27
// Config contains configuration for the file upload client.
28
28
type Config struct {
29
29
BaseURL string
30
30
}
31
31
32
- // HTTPClient implements the Client interface for file upload operations via HTTP API.
33
- type HTTPClient struct {
32
+ // HTTPSealableClient implements the SealableClient interface for file upload operations via HTTP API.
33
+ type HTTPSealableClient struct {
34
34
cfg Config
35
35
httpClient * http.Client
36
36
}
@@ -48,8 +48,8 @@ const FileCountLimit = 100 // arbitrary number, will need to be re-evaluated
48
48
const ContentType = "Content-Type"
49
49
50
50
// NewClient creates a new file upload client with the given configuration and options.
51
- func NewClient (cfg Config , opts ... Opt ) * HTTPClient {
52
- c := HTTPClient {cfg , http .DefaultClient }
51
+ func NewClient (cfg Config , opts ... Opt ) * HTTPSealableClient {
52
+ c := HTTPSealableClient {cfg , http .DefaultClient }
53
53
54
54
for _ , opt := range opts {
55
55
opt (& c )
@@ -59,7 +59,7 @@ func NewClient(cfg Config, opts ...Opt) *HTTPClient {
59
59
}
60
60
61
61
// CreateRevision creates a new upload revision for the specified organization.
62
- func (c * HTTPClient ) CreateRevision (ctx context.Context , orgID OrgID ) (* UploadRevisionResponseBody , error ) {
62
+ func (c * HTTPSealableClient ) CreateRevision (ctx context.Context , orgID OrgID ) (* UploadRevisionResponseBody , error ) {
63
63
if orgID == uuid .Nil {
64
64
return nil , ErrEmptyOrgID
65
65
}
@@ -103,7 +103,7 @@ func (c *HTTPClient) CreateRevision(ctx context.Context, orgID OrgID) (*UploadRe
103
103
}
104
104
105
105
// UploadFiles uploads the provided files to the specified revision. It will not close the file descriptors.
106
- func (c * HTTPClient ) UploadFiles (ctx context.Context , orgID OrgID , revisionID RevisionID , files []UploadFile ) error {
106
+ func (c * HTTPSealableClient ) UploadFiles (ctx context.Context , orgID OrgID , revisionID RevisionID , files []UploadFile ) error {
107
107
if orgID == uuid .Nil {
108
108
return ErrEmptyOrgID
109
109
}
@@ -165,7 +165,7 @@ func (c *HTTPClient) UploadFiles(ctx context.Context, orgID OrgID, revisionID Re
165
165
return nil
166
166
}
167
167
168
- func (c * HTTPClient ) streamFilesToPipe (pWriter * io.PipeWriter , mpartWriter * multipart.Writer , files []UploadFile ) {
168
+ func (c * HTTPSealableClient ) streamFilesToPipe (pWriter * io.PipeWriter , mpartWriter * multipart.Writer , files []UploadFile ) {
169
169
var streamError error
170
170
defer func () {
171
171
pWriter .CloseWithError (streamError )
@@ -189,7 +189,7 @@ func (c *HTTPClient) streamFilesToPipe(pWriter *io.PipeWriter, mpartWriter *mult
189
189
}
190
190
191
191
// SealRevision seals the specified upload revision, marking it as complete.
192
- func (c * HTTPClient ) SealRevision (ctx context.Context , orgID OrgID , revisionID RevisionID ) (* SealUploadRevisionResponseBody , error ) {
192
+ func (c * HTTPSealableClient ) SealRevision (ctx context.Context , orgID OrgID , revisionID RevisionID ) (* SealUploadRevisionResponseBody , error ) {
193
193
if orgID == uuid .Nil {
194
194
return nil , ErrEmptyOrgID
195
195
}
@@ -237,7 +237,7 @@ func (c *HTTPClient) SealRevision(ctx context.Context, orgID OrgID, revisionID R
237
237
return & respBody , nil
238
238
}
239
239
240
- func (c * HTTPClient ) handleUnexpectedStatusCodes (body io.ReadCloser , statusCode int , status , operation string ) error {
240
+ func (c * HTTPSealableClient ) handleUnexpectedStatusCodes (body io.ReadCloser , statusCode int , status , operation string ) error {
241
241
bts , err := io .ReadAll (body )
242
242
if err != nil {
243
243
return fmt .Errorf ("failed to read response body: %w" , err )
0 commit comments