diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 353a438..a28a1d2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,8 +23,8 @@ env: BUF_VERSION: "1.34.0" BUF_BETA_SUPPRESS_WARNINGS: 1 - GO_VERSION: "1.22" - GO_LANGCI_LINT_VERSION: "v1.56.2" + GO_VERSION: "1.23" + GO_LANGCI_LINT_VERSION: "v1.61.0" GO_TESTSUM_VERSION: "1.11.0" jobs: @@ -84,7 +84,7 @@ jobs: buf generate ${{ env.BUF_REPO }}:${{ steps.buf-latest.outputs.VERSION }} - name: Lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 with: version: ${{ env.GO_LANGCI_LINT_VERSION }} args: --timeout=30m diff --git a/.golangci.yaml b/.golangci.yaml index 77646c2..29bf2a5 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,20 +3,9 @@ # https://github.com/golangci/golangci/wiki/Configuration linters-settings: - depguard: - list-type: blacklist - packages: - # logging is allowed only by zerolog - - github.com/sirupsen/logrus - packages-with-error-message: - - github.com/sirupsen/logrus: "logging is allowed only by zerolog" - dupl: - threshold: 100 funlen: lines: 100 statements: 80 - gci: - local-prefixes: github.com/golangci/golangci-lint goconst: min-len: 2 min-occurrences: 2 @@ -28,28 +17,23 @@ linters-settings: - performance - style disabled-checks: - - dupImport # https://github.com/go-critic/go-critic/issues/845 + - dupImport # https://github.com/go-critic/go-critic/issues/845 - ifElseChain - octalLiteral - whyNoLint - wrapperFunc gocyclo: - min-complexity: 20 + min-complexity: 18 goimports: local-prefixes: github.com/golangci/golangci-lint - golint: - min-confidence: 0 - gomnd: - settings: - mnd: - # don't include the "operation" and "assign" - checks: - - argument - - case - - condition - - return + mnd: + checks: + - argument + - case + - condition + - return govet: - check-shadowing: true + shadow: true settings: printf: funcs: @@ -57,104 +41,111 @@ linters-settings: - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - maligned: - suggest-new: true + lll: + line-length: 140 misspell: locale: US nolintlint: - allow-unused: false # report any unused nolint directives - require-explanation: false # don't require an explanation for nolint directives - require-specific: false # don't require nolint directives to be specific about which linter is being skipped + allow-unused: false # report any unused nolint directives + require-explanation: false # don't require an explanation for nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped linters: # please, do not use `enable-all`: it's deprecated and will be removed soon. # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint - disable-all: true + disable-all: false enable: + - asasalint - asciicheck + - bidichk - bodyclose + - canonicalheader + - containedctx + - contextcheck + - copyloopvar + - cyclop + - decorder - dogsled - - errcheck - - exportloopref + - dupword + - durationcheck + - err113 + - errchkjson + - errname + - errorlint - exhaustive + - fatcontext + - forcetypeassert - funlen + - gocheckcompilerdirectives + - gochecknoinits + - gochecknoglobals - gochecknoinits + - gocognit - goconst - gocritic - gocyclo - godot - # - goerr113 # temporary disabled - gofmt - goimports + - gomoddirectives - goprintffuncname - gosec - - gosimple - - govet - - ineffassign + - gosmopolitan + - grouper + - importas + - inamedparam + - interfacebloat + - intrange + - lll + - makezero + - mirror - misspell + - mnd + - musttag - nakedret + - nestif + - nilerr + - nilnil - noctx - # - rowserrcheck # disable https://github.com/golangci/golangci-lint/issues/2649. - - staticcheck + - nolintlint + - nonamedreturns + - perfsprint + - prealloc + - predeclared + - reassign + - rowserrcheck - stylecheck - testpackage - - typecheck - unconvert - unparam - - unused + - usestdlibvars + - wastedassign + - whitespace + - wsl + - zerologlint - # don't enable: + # don't enable: # - depguard # - dupl + # - exhaustruct + # - gci + # - ginkgolinter # - gochecknoglobals # - gocognit # - godox - # - gomnd + # - gofumpt + # - ireturn # - lll - # - nestif + # - nlreturn # - nolintlint # conflict with 1.19 gofmt changes + # - protogetter # - prealloc # - revive # - wsl - # - whitespace + # - wrapcheck issues: - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` - exclude: - - declaration of "(err|ctx)" shadows declaration at - - shadow of imported from 'github.com/stretchr/testify/assert' package 'assert' - # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: - - path: _test\.go - linters: - - gomnd - # https://github.com/go-critic/go-critic/issues/926 - - text: "unnecessaryDefer:" - linters: - - gocritic - text: "unnamedResult:" linters: - - gocritic - - path: \.resolvers\.go - text: "typeDefFirst:" - linters: - - gocritic - - path: \.resolvers\.go - text: "paramTypeCombine:" - linters: - - gocritic - - path: \.resolvers\.go - text: "hugeParam:" - linters: - - gocritic - - text: "G404" - linters: - - gosec - -run: - timeout: 5m - skip-dirs: - - aserto/directory \ No newline at end of file + - gocritic diff --git a/go.mod b/go.mod index 1ce40d2..b723996 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,15 @@ module github.com/aserto-dev/go-authorizer -go 1.21 +go 1.22.10 + +toolchain go1.23.4 require ( - github.com/aserto-dev/errors v0.0.11 - github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 - google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 - google.golang.org/grpc v1.67.1 - google.golang.org/protobuf v1.35.1 + github.com/aserto-dev/errors v0.0.12 + github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 + google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 + google.golang.org/grpc v1.68.1 + google.golang.org/protobuf v1.36.0 ) require ( @@ -15,8 +17,8 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rs/zerolog v1.33.0 // indirect - golang.org/x/net v0.30.0 // indirect - golang.org/x/sys v0.26.0 // indirect - golang.org/x/text v0.19.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect + golang.org/x/net v0.33.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484 // indirect ) diff --git a/go.sum b/go.sum index dfb4822..63df9b0 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,15 @@ -github.com/aserto-dev/errors v0.0.11 h1:CXo+Uwmh09doG2HvL1SC8Fnne8f9VPrGyEQPtogAfyY= -github.com/aserto-dev/errors v0.0.11/go.mod h1:T1YQOtcxpgBriPTn5HXJkD/QukYz5YojYOIzGMo0ybM= +github.com/aserto-dev/errors v0.0.12 h1:wjLiAlLLNu5wWDtPO09G3z2ULMj9XZDsk3L7VqPfvtQ= +github.com/aserto-dev/errors v0.0.12/go.mod h1:iEg8Q7XftdSsBLA1ok4q5Bor6G0MzsmzF3Aa0y5fUT0= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 h1:ad0vkEBuk23VJzZR9nkLVG0YAoN9coASF1GusYX6AlU= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0/go.mod h1:igFoXX2ELCW06bol23DWPB5BEWfZISOzSP5K2sbLea0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 h1:TmHmbvxPmaegwhDubVz0lICL0J5Ka2vwTzhoePEXsGE= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0/go.mod h1:qztMSjm835F2bXf+5HKAPIS5qsmQDqZna/PgVt4rWtI= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= @@ -21,24 +23,24 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g= -google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= -google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= -google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 h1:CkkIfIt50+lT6NHAVoRYEyAvQGFM7xEwXUUywFvEb3Q= +google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576/go.mod h1:1R3kvZ1dtP3+4p4d3G8uJ8rFk/fWlScl38vanWACI08= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484 h1:Z7FRVJPSMaHQxD0uXU8WdgFh8PseLM8Q8NzhnpMrBhQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484/go.mod h1:lcTa1sDdWEIHMWlITnIczmw5w60CF9ffkb8Z+DVmmjA= +google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0= +google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw= +google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= +google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/makefile b/makefile index bef98ab..9874a99 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ SHELL := $(shell which bash) - + NO_COLOR := \033[0m OK_COLOR := \033[32;01m ERR_COLOR := \033[31;01m @@ -17,11 +17,9 @@ EXT_TMP_DIR := ${EXT_DIR}/tmp VAULT_VERSION := 1.8.12 SVU_VERSION := 1.12.0 -WIRE_VERSION := 0.6.0 BUF_VERSION := 1.34.0 GOTESTSUM_VERSION := 1.11.0 -GOLANGCI-LINT_VERSION := 1.56.2 -GORELEASER_VERSION := 1.24.0 +GOLANGCI-LINT_VERSION := 1.61.0 PROJECT := authorizer BUF_USER := $(shell vault kv get -field ASERTO_BUF_USER kv/buf.build) @@ -39,10 +37,6 @@ RELEASE_TAG := $$(svu) deps: info install-vault install-buf install-svu install-golangci-lint install-gotestsum @echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)" -build: - @echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)" - @${EXT_BIN_DIR}/goreleaser build --clean --snapshot --single-target - lint: @echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)" @${EXT_BIN_DIR}/golangci-lint run --config ${PWD}/.golangci.yaml @@ -93,7 +87,7 @@ install-vault: ${EXT_BIN_DIR} ${EXT_TMP_DIR} @curl -s -o ${EXT_TMP_DIR}/vault.zip https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_${GOOS}_${GOARCH}.zip @unzip -o ${EXT_TMP_DIR}/vault.zip vault -d ${EXT_BIN_DIR}/ &> /dev/null @chmod +x ${EXT_BIN_DIR}/vault - @${EXT_BIN_DIR}/vault --version + @${EXT_BIN_DIR}/vault --version .PHONY: install-buf install-buf: ${EXT_BIN_DIR} @@ -137,19 +131,6 @@ install-golangci-lint: ${EXT_TMP_DIR} ${EXT_BIN_DIR} @chmod +x ${EXT_BIN_DIR}/golangci-lint @${EXT_BIN_DIR}/golangci-lint --version -.PHONY: install-goreleaser -install-goreleaser: ${EXT_TMP_DIR} ${EXT_BIN_DIR} - @echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)" - @gh release download v${GORELEASER_VERSION} --repo https://github.com/goreleaser/goreleaser --pattern "goreleaser_$$(uname -s)_$$(uname -m).tar.gz" --output "${EXT_TMP_DIR}/goreleaser.tar.gz" --clobber - @tar -xvf ${EXT_TMP_DIR}/goreleaser.tar.gz --directory ${EXT_BIN_DIR} goreleaser &> /dev/null - @chmod +x ${EXT_BIN_DIR}/goreleaser - @${EXT_BIN_DIR}/goreleaser --version - -.PHONY: install-wire -install-wire: ${EXT_TMP_DIR} ${EXT_BIN_DIR} - @echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)" - @GOBIN=${PWD}/${EXT_BIN_DIR} go install github.com/google/wire/cmd/wire@v${WIRE_VERSION} - .PHONY: clean clean: @echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)" diff --git a/pkg/aerr/errors.go b/pkg/aerr/errors.go index b0495d4..7767793 100644 --- a/pkg/aerr/errors.go +++ b/pkg/aerr/errors.go @@ -32,7 +32,7 @@ var ( ErrInvalidDecision = newErr("E30011", codes.InvalidArgument, http.StatusBadRequest, "invalid decision") // Returned when a runtime failed to load. ErrBadRuntime = newErr("E30012", codes.Unavailable, http.StatusServiceUnavailable, "runtime loading failed") - // Returned if object object id is not found in the directory. + // Returned if object id is not found in the directory. ErrDirectoryObjectNotFound = newErr("E30013", codes.NotFound, http.StatusNotFound, "directory object not found") // Returned if the loaded policy is invalid. ErrInvalidPolicy = newErr("E30014", codes.Internal, http.StatusInternalServerError, "invalid policy")