diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fb94b4e9b..c0f678d1a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ Submitting pull requests - Run the pre-commit checks that are appropriate for the kind of change. (See below for details.) - Submit your pull request. - We require all pull requests to follow the [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) format. - - Use [closing keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) to link the PR to the original issue. + - Use [closing keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) to link the PR to the original issue. - At least one approval from a maintainer is required to merge the pull request. @@ -33,7 +33,7 @@ Submitting pull requests - Add tests to cover the functionality you are adding or modifying. - Add new documentation or update existing content to ensure that the documentation stays consistent with the change you are introducing. See [below](#submitting-pull-requests-for-documentation-changes) for tips on writing documentation. - Avoid introducing new dependencies if possible. All dependencies must have an appropriate open source licence (Apache-2.0, BSD, MIT). -- Make sure your code is `gofmt`ed. Run `make lint` and fix any warnings produced by the linter. +- Make sure your code is `gofmt`ed. Run `make lint` and fix any warnings produced by the linter. - Sign-off your commits to provide a [DCO](https://developercertificate.org). You can do this by adding the `-s` flag to your `git commit` command. ```sh git commit -s -m 'bug: Fix for bug X' @@ -53,7 +53,7 @@ Submitting pull requests Developing Cerbos ----------------- -Cerbos is developed using the [Go programming language](https://golang.org). We currently require Go 1.19.x for development. +Cerbos is developed using the [Go programming language](https://golang.org). We currently require Go 1.20.x for development. The `Makefile` automatically installs required build tools using the versions defined in `tools/go.mod`. Run `make clean-tools` to clear the cache and force the installation of new versions. @@ -61,7 +61,7 @@ Useful `make` targets: - `make build`: Compile, test and build the Cerbos binaries and container. Binaries will be output to the `dist` directory. The container name would be `ghcr.io/cerbos/cerbos:-prerelease`. - `make pre-commit`: Run tests, lint, and generate code and documentation. Run this before submitting a PR to make sure your code is ready to submit. -- `make dev-server`: Start a Cerbos server +- `make dev-server`: Start a Cerbos server - `make docs`: Generate docs and preview in browser. diff --git a/Makefile b/Makefile index 949987eed..b927f9c2a 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ confdocs: .PHONY: deps deps: - @ go mod tidy -compat=1.19 + @ go mod tidy -compat=1.20 .PHONY: test-all test-all: test-race test-integration diff --git a/go.mod b/go.mod index aee155f6e..6363dd424 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cerbos/cerbos -go 1.19 +go 1.20 require ( contrib.go.opencensus.io/exporter/prometheus v0.4.2 diff --git a/hack/tools/protoc-gen-jsonschema/go.mod b/hack/tools/protoc-gen-jsonschema/go.mod index c5913e8ee..27b154294 100644 --- a/hack/tools/protoc-gen-jsonschema/go.mod +++ b/hack/tools/protoc-gen-jsonschema/go.mod @@ -1,6 +1,6 @@ module github.com/cerbos/cerbos/hack/tools/protoc-gen-jsonschema -go 1.19 +go 1.20 require ( github.com/envoyproxy/protoc-gen-validate v1.0.2 diff --git a/hack/tools/testsplit/go.mod b/hack/tools/testsplit/go.mod index cf5c14704..6d31a1bdd 100644 --- a/hack/tools/testsplit/go.mod +++ b/hack/tools/testsplit/go.mod @@ -1,6 +1,6 @@ module github.com/cerbos/cerbos/hack/tools/testsplit -go 1.19 +go 1.20 require ( github.com/alecthomas/kong v0.8.0 diff --git a/internal/storage/git/store.go b/internal/storage/git/store.go index c81dac33a..abc89b7ca 100644 --- a/internal/storage/git/store.go +++ b/internal/storage/git/store.go @@ -445,12 +445,11 @@ func (s *Store) normalizePath(path string) (string, util.IndexedFileType) { } if s.subDir != "." { - relativePath := strings.TrimPrefix(path, s.subDir+"/") - if path == relativePath { // not in policies directory + var ok bool + path, ok = strings.CutPrefix(path, s.subDir+"/") + if !ok { // not in policies directory return path, util.FileTypeNotIndexed } - - path = relativePath } fileType := util.FileType(path) diff --git a/internal/util/filesystem.go b/internal/util/filesystem.go index bd3ae90ee..a3a58d564 100644 --- a/internal/util/filesystem.go +++ b/internal/util/filesystem.go @@ -224,10 +224,10 @@ func FileType(path string) IndexedFileType { // and a flag to indicate whether the path was actually contained in that directory. // The path must be "/"-separated and relative to the root policies directory. func RelativeSchemaPath(path string) (string, bool) { - schemaPath := strings.TrimPrefix(path, SchemasDirectory+"/") - if schemaPath == path { - return "", false + schemaPath, ok := strings.CutPrefix(path, SchemasDirectory+"/") + if !ok { + schemaPath = "" } - return schemaPath, true + return schemaPath, ok } diff --git a/tools/go.mod b/tools/go.mod index b1c76c114..0ed2857fd 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -1,6 +1,6 @@ module github.com/cerbos/cerbos/tools -go 1.19 +go 1.20 require ( github.com/bojand/ghz v0.117.0