diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c4b25c..a097f45 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ on: env: DESTDIR: ./bin - GO_VERSION: 1.16.7 + GO_VERSION: 1.18.5 jobs: validate: @@ -20,6 +20,7 @@ jobs: fail-fast: false matrix: target: + - lint - validate-vendor steps: - diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..930e66a --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,35 @@ +run: + timeout: 10m + modules-download-mode: vendor + +linters: + enable: + - gofmt + - govet + - deadcode + - depguard + - goimports + - ineffassign + - misspell + - unused + - varcheck + - revive + - staticcheck + - typecheck + - structcheck + disable-all: true + +linters-settings: + depguard: + list-type: blacklist + include-go-root: true + packages: + # The io/ioutil package has been deprecated. + # https://go.dev/doc/go1.16#ioutil + - io/ioutil + +issues: + exclude-rules: + - linters: + - revive + text: "stutters" diff --git a/Dockerfile b/Dockerfile index 85845fd..a428272 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ ARG GO_VERSION=1.18.5 ARG XX_VERSION=1.1.2 ARG OSXCROSS_VERSION=11.3-r7-alpine +ARG GOLANGCI_LINT_VERSION=v1.47.3 ARG PKG=github.com/docker/docker-credential-helpers @@ -48,6 +49,14 @@ RUN --mount=type=bind,target=.,rw <", "abcd1234"}, + {ServerURL: validServerAddress, Username: "foo", Secret: "bar"}, + {ServerURL: validServerAddress2, Username: "", Secret: "abcd1234"}, } for _, v := range valid { @@ -119,7 +118,7 @@ func TestStore(t *testing.T) { } invalid := []credentials.Credentials{ - {invalidServerAddress, "foo", "bar"}, + {ServerURL: invalidServerAddress, Username: "foo", Secret: "bar"}, } for _, v := range invalid { @@ -142,8 +141,8 @@ func ExampleGet() { func TestGet(t *testing.T) { valid := []credentials.Credentials{ - {validServerAddress, "foo", "bar"}, - {validServerAddress2, "", "abcd1234"}, + {ServerURL: validServerAddress, Username: "foo", Secret: "bar"}, + {ServerURL: validServerAddress2, Username: "", Secret: "abcd1234"}, } for _, v := range valid { diff --git a/docker-bake.hcl b/docker-bake.hcl index 80ecf32..4cc91ae 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -22,15 +22,23 @@ group "default" { } group "validate" { - targets = ["vendor-validate"] + targets = ["lint", "vendor-validate"] +} + +target "lint" { + inherits = ["_common"] + target = "lint" + output = ["type=cacheonly"] } target "vendor-validate" { + inherits = ["_common"] target = "vendor-validate" output = ["type=cacheonly"] } target "vendor" { + inherits = ["_common"] target = "vendor-update" output = ["."] } diff --git a/pass/pass.go b/pass/pass.go index 5750a78..6cce15d 100644 --- a/pass/pass.go +++ b/pass/pass.go @@ -9,7 +9,7 @@ import ( "encoding/base64" "errors" "fmt" - "io/ioutil" + "io/fs" "os" "os/exec" "path" @@ -20,7 +20,7 @@ import ( ) // PASS_FOLDER contains the directory where credentials are stored -const PASS_FOLDER = "docker-credential-helpers" //nolint: golint +const PASS_FOLDER = "docker-credential-helpers" //nolint:revive // Pass handles secrets using Linux secret-service as a store. type Pass struct{} @@ -116,16 +116,22 @@ func getPassDir() string { func listPassDir(args ...string) ([]os.FileInfo, error) { passDir := getPassDir() p := path.Join(append([]string{passDir, PASS_FOLDER}, args...)...) - contents, err := ioutil.ReadDir(p) + entries, err := os.ReadDir(p) if err != nil { if os.IsNotExist(err) { return []os.FileInfo{}, nil } - return nil, err } - - return contents, nil + infos := make([]fs.FileInfo, 0, len(entries)) + for _, entry := range entries { + info, err := entry.Info() + if err != nil { + return nil, err + } + infos = append(infos, info) + } + return infos, nil } // Get returns the username and secret to use for a given registry server URL.