Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ orbs:
parameters:
cosign-version:
type: string
default: '2.4.2'
default: '2.5.0'

executors:
node:
docker:
- image: node:22-slim
golangci-lint:
docker:
- image: golangci/golangci-lint:v1.63
- image: golangci/golangci-lint:v2.1
golang-previous:
docker:
- image: golang:1.23
Expand Down
32 changes: 26 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
version: "2"
linters:
disable-all: true
default: none
enable:
- bidichk
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- decorder
- dogsled
- dupl
Expand All @@ -14,13 +16,11 @@ linters:
- goconst
- gocyclo
- godox
- gofumpt
- goimports
- goprintffuncname
- gosimple
- govet
- grouper
- ineffassign
- intrange
- ireturn
- maintidx
- misspell
Expand All @@ -29,9 +29,29 @@ linters:
- prealloc
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- usetesting
- wsl
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
4 changes: 3 additions & 1 deletion client/archive.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, Sylabs Inc. All rights reserved.
// Copyright (c) 2022-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -39,6 +39,7 @@ func (ar *archiver) writeEntry(name string) (err error) {
if _, ok := ar.archived[name]; ok {
return nil
}

defer func() {
if err == nil {
ar.archived[name] = struct{}{}
Expand All @@ -56,6 +57,7 @@ func (ar *archiver) writeEntry(name string) (err error) {
if err != nil {
return err
}

h.Name = filepath.ToSlash(name)

// Check that we're writing a supported type, and make any necessary adjustments.
Expand Down
5 changes: 4 additions & 1 deletion client/build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -95,6 +95,7 @@
}

bo.workingDir = dir

Check warning on line 98 in client/build.go

View check run for this annotation

Codecov / codecov/patch

client/build.go#L98

Added line #L98 was not covered by tests
return nil
}
}
Expand Down Expand Up @@ -174,12 +175,14 @@
if err != nil {
return nil, fmt.Errorf("%w", err)
}

req.Header.Set("Content-Type", "application/json")

res, err := c.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("%w", err)
}

defer res.Body.Close()

if res.StatusCode/100 != 2 { // non-2xx status code
Expand Down
8 changes: 7 additions & 1 deletion client/build_context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023, Sylabs Inc. All rights reserved.
// Copyright (c) 2022-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -68,12 +68,14 @@ func (c *Client) getBuildContextUploadLocation(ctx context.Context, size int64,
if err != nil {
return nil, fmt.Errorf("%w", err)
}

req.Header.Set("Content-Type", "application/json")

res, err := c.buildContextHTTPClient.Do(req)
if err != nil {
return nil, fmt.Errorf("%w", err)
}

defer res.Body.Close()

if res.StatusCode/100 != 2 { // non-2xx status code
Expand All @@ -94,6 +96,7 @@ func (c *Client) putBuildContext(ctx context.Context, loc *url.URL, r io.Reader,
if err != nil {
return err
}

req.Header.Set("Content-Type", "application/octet-stream")
req.Header.Del("Authorization")

Expand All @@ -103,11 +106,13 @@ func (c *Client) putBuildContext(ctx context.Context, loc *url.URL, r io.Reader,
if err != nil {
return fmt.Errorf("%w", err)
}

defer res.Body.Close()

if res.StatusCode/100 != 2 {
return fmt.Errorf("%w", errorFromResponse(res))
}

return nil
}

Expand Down Expand Up @@ -139,6 +144,7 @@ func (c *Client) uploadBuildContext(ctx context.Context, rw io.ReadWriteSeeker,
if errors.Is(err, errContextAlreadyPresent) {
return digest, nil
}

return "", fmt.Errorf("failed to get build context upload location: %w", err)
}

Expand Down
6 changes: 3 additions & 3 deletions client/build_context_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, Sylabs Inc. All rights reserved.
// Copyright (c) 2022-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -51,6 +51,7 @@ func (m *mockUploadBuildContext) ServeHTTP(w http.ResponseWriter, r *http.Reques
Size int64 `json:"size"`
Digest string `json:"digest"`
}

if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
m.t.Fatalf("failed to decode request: %v", err)
}
Expand Down Expand Up @@ -218,6 +219,7 @@ func (m *mockDeleteBuildContext) ServeHTTP(w http.ResponseWriter, r *http.Reques
if err := jsonresp.WriteError(w, "", m.code); err != nil {
m.t.Fatalf("failed to write error: %v", err)
}

return
}

Expand Down Expand Up @@ -253,8 +255,6 @@ func TestClient_DeleteBuildContext(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 5 additions & 1 deletion client/build_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -36,6 +36,7 @@ func TestSubmit(t *testing.T) {

// Start a mock server
m := mockService{t: t}

s := httptest.NewServer(&m)
defer s.Close()

Expand All @@ -62,9 +63,11 @@ func TestSubmit(t *testing.T) {
if bi.ID() == "" {
t.Fatalf("invalid ID")
}

if bi.LibraryRef() == "" {
t.Errorf("empty Library ref")
}

if bi.LibraryURL() == "" {
t.Errorf("empty Library URL")
}
Expand All @@ -76,6 +79,7 @@ func TestSubmit(t *testing.T) {
func TestCancel(t *testing.T) {
// Start a mock server
m := mockService{t: t}

s := httptest.NewServer(&m)
defer s.Close()

Expand Down
4 changes: 3 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023, Sylabs Inc. All rights reserved.
// Copyright (c) 2019-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file
// distributed with the sources of this project regarding your rights to use or distribute this
// software.
Expand Down Expand Up @@ -126,6 +126,7 @@ func NewClient(opts ...Option) (*Client, error) {
if err != nil {
return nil, fmt.Errorf("%w", err)
}

c.baseURL = u

return &c, nil
Expand Down Expand Up @@ -153,6 +154,7 @@ func (c *Client) setRequestHeaders(h http.Header) {
if v := c.bearerToken; v != "" {
h.Set("Authorization", fmt.Sprintf("BEARER %s", v))
}

if v := c.userAgent; v != "" {
h.Set("User-Agent", v)
}
Expand Down
7 changes: 6 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2023, Sylabs Inc. All rights reserved.
// Copyright (c) 2018-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
Expand Down Expand Up @@ -153,6 +153,7 @@ func TestNewRequest(t *testing.T) {
if err != nil {
t.Errorf("failed to read body: %v", err)
}

if got, want := string(b), tt.body; got != want {
t.Errorf("got body %v, want %v", got, want)
}
Expand All @@ -161,10 +162,12 @@ func TestNewRequest(t *testing.T) {
if got, want := ok, (tt.wantBearerToken != ""); got != want {
t.Fatalf("presence of auth bearer %v, want %v", got, want)
}

if ok {
if got, want := len(authBearer), 1; got != want {
t.Fatalf("got %v auth bearer(s), want %v", got, want)
}

if got, want := authBearer[0], tt.wantBearerToken; got != want {
t.Errorf("got auth bearer %v, want %v", got, want)
}
Expand All @@ -174,10 +177,12 @@ func TestNewRequest(t *testing.T) {
if got, want := ok, (tt.wantUserAgent != ""); got != want {
t.Fatalf("presence of user agent %v, want %v", got, want)
}

if ok {
if got, want := len(userAgent), 1; got != want {
t.Fatalf("got %v user agent(s), want %v", got, want)
}

if got, want := userAgent[0], tt.wantUserAgent; got != want {
t.Errorf("got user agent %v, want %v", got, want)
}
Expand Down
3 changes: 2 additions & 1 deletion client/error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, Sylabs Inc. All rights reserved.
// Copyright (c) 2022-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file
// distributed with the sources of this project regarding your rights to use or distribute this
// software.
Expand Down Expand Up @@ -27,6 +27,7 @@ func (e *httpError) Error() string {
if e.err != nil {
return fmt.Sprintf("%v %v: %v", e.Code, http.StatusText(e.Code), e.err.Error())
}

return fmt.Sprintf("%v %v", e.Code, http.StatusText(e.Code))
}

Expand Down
4 changes: 3 additions & 1 deletion client/error_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, Sylabs Inc. All rights reserved.
// Copyright (c) 2022-2025, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file
// distributed with the sources of this project regarding your rights to use or distribute this
// software.
Expand Down Expand Up @@ -41,9 +41,11 @@ func TestHTTPError(t *testing.T) {
if got, want := err.Code, tt.code; got != want {
t.Errorf("got code %v, want %v", got, want)
}

if got, want := err.Unwrap(), tt.err; got != want {
t.Errorf("got unwrapped error %v, want %v", got, want)
}

if got, want := err.Error(), tt.wantMessage; got != want {
t.Errorf("got message %v, want %v", got, want)
}
Expand Down
Loading