-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hi there Spacelift friends ππ This PR introduces [Regal](https://github.com/styrainc/regal) (as I know some of you are familiar with from before!) for linting the Rego found in this repo. A few issues reported have been fixed as part of the PR: * [custom-has-key-construct](https://docs.styra.com/regal/rules/idiomatic/custom-has-key-construct) * [custom-in-construct](https://docs.styra.com/regal/rules/idiomatic/custom-in-construct) * [prefer-set-or-object-rule](https://docs.styra.com/regal/rules/idiomatic/prefer-set-or-object-rule) * [non-raw-regex-pattern](https://docs.styra.com/regal/rules/idiomatic/non-raw-regex-pattern) * [unconditional-assignment](https://docs.styra.com/regal/rules/style/unconditional-assignment) * [use-assignment-operator](https://docs.styra.com/regal/rules/style/use-assignment-operator) * [use-in-operator](https://docs.styra.com/regal/rules/idiomatic/use-in-operator) * [use-some-for-output-vars](https://docs.styra.com/regal/rules/idiomatic/use-some-for-output-vars) A few rules have been ignored for now using the provided `.regal/config.yaml` file. Some of those would be easy to fix later, but I'll leave that decision to you. In addition to the Regal rules, I've also made sure the project "builds" using OPA [strict mode](https://www.openpolicyagent.org/docs/latest/policy-language/#strict-mode) (`opa check --strict`). The violations related to that have also been fixed fixed: * Assignment shadowing `input` * Unused assignment Finally, I've added a Regal step to the project's CI workflow, so that new code is linted as part of that process. I've also removed the formatter check job, as that is included in Regal (the [opa-fmt](https://docs.styra.com/regal/rules/style/opa-fmt) rule). Signed-off-by: Anders Eknert <[email protected]>
- Loading branch information
1 parent
00835cd
commit 9779ba5
Showing
70 changed files
with
264 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,26 +7,17 @@ on: | |
pull_request: | ||
|
||
jobs: | ||
formatting-check: | ||
name: Formatting Check | ||
regal-check: | ||
name: Regal Check | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install OPA | ||
uses: open-policy-agent/setup-opa@v2 | ||
- uses: actions/checkout@v3 | ||
- name: Setup Regal | ||
uses: StyraInc/[email protected] | ||
with: | ||
version: 0.51.0 | ||
|
||
- name: Check formatting | ||
run: | | ||
output="$(opa fmt --diff .)" | ||
if [ -n "$output" ]; then | ||
echo "$output" | ||
exit 1 | ||
fi | ||
version: v0.11.0 | ||
- run: regal lint --format=github . | ||
|
||
syntax-check: | ||
name: Syntax Check | ||
|
@@ -46,7 +37,7 @@ jobs: | |
# KLUDGE: plan/check-sanitized-value.rego needs to be ignored because it uses the custom sanitized() function | ||
policies=$(find . -type f -regex '.*\.rego$' | grep -v _test.rego | grep -v plan/check-sanitized-value.rego) | ||
for policy in $policies; do | ||
opa check $policy | ||
opa check --strict $policy | ||
done | ||
unit-tests: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
rules: | ||
idiomatic: | ||
no-defined-entrypoint: | ||
level: ignore | ||
style: | ||
external-reference: | ||
level: ignore | ||
line-length: | ||
level: ignore | ||
prefer-some-in-iteration: | ||
level: ignore | ||
todo-comment: | ||
level: ignore | ||
testing: | ||
test-outside-test-package: | ||
level: ignore | ||
|
||
capabilities: | ||
from: | ||
# Feel free to submit a PR to have "spacelift" added as an engine! | ||
engine: opa | ||
version: v0.51.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
package spacelift | ||
|
||
import future.keywords.in | ||
|
||
# This example access policy gives everyone in the "Engineering" GitHub team | ||
# read access to the stack. | ||
# | ||
# You can read more about access policies here: | ||
# https://docs.spacelift.io/concepts/policy/stack-access-policy | ||
|
||
read { | ||
input.session.teams[_] == "Engineering" | ||
"Engineering" in input.session.teams | ||
} | ||
|
||
# Learn more about sampling policy evaluations here: | ||
# https://docs.spacelift.io/concepts/policy#sampling-policy-inputs | ||
sample = true | ||
sample := true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.