Skip to content

Commit 691afe1

Browse files
authored
Replace some Styra references (#1904)
And a few other minor things: - Bump golangci-lint to latest and fix or ignore a few new things - Some tweaks in built-in markdown templating, and another unit test to verify functionality Signed-off-by: Anders Eknert <anders.eknert@apple.com>
1 parent 23614cc commit 691afe1

10 files changed

Lines changed: 83 additions & 40 deletions

File tree

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
- uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
6666
if: matrix.os.name == 'linux'
6767
with:
68-
version: v2.9.0
68+
version: v2.10.1
6969
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
7070
with:
7171
name: regal-${{ matrix.os.name }}

.golangci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ linters:
5151
- whyNoLint # not all nolint comments need explanations
5252
- hugeParam # investigate later, but some of these breaks API signatures
5353
- unnamedResult
54+
gosec:
55+
excludes:
56+
# taint analysis. not relevant as Regal assumes trusted user
57+
- G703
58+
- G704
59+
- G706
5460
govet:
5561
disable:
5662
- shadow

build/do.rq

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ fetch_eopa_caps if {
219219
# ],
220220
# ...
221221

222-
print("fetching tags for enterprise-opa repository")
222+
print("fetching tags for eopa repository")
223223

224224
eopa_tags_result := rq.run(
225225
[
226226
"git",
227227
"ls-remote",
228228
"--tags",
229-
"https://github.com/styrainc/enterprise-opa",
229+
"https://github.com/open-policy-agent/eopa",
230230
],
231231
{"stdout_spec": {
232232
"format": "raw",
@@ -283,7 +283,7 @@ fetch_eopa_caps if {
283283
not eopa_caps_tree[p]
284284

285285
# construct the URL to fetch the content from
286-
r := rq.template("https://raw.githubusercontent.com/StyraInc/enterprise-opa/main/capabilities/{{.tag}}.json", {"tag": t})
286+
r := rq.template("https://raw.githubusercontent.com/open-policy-agent/eopa/main/capabilities/{{.tag}}.json", {"tag": t})
287287
}
288288

289289
print(sprintf("fetching %d capabilities files missing locally", [count(missing_locally)]))

bundle/regal/lsp/clients/clients.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ gotest := 2
2424
# description: The Zed Editor, via zed-rego
2525
# related_resources:
2626
# - https://zed.dev/docs/languages/rego
27-
# - https://github.com/styrainc/zed-rego
27+
# - https://github.com/styraoss/zed-rego
2828
zed := 3
2929

3030
# METADATA

bundle/regal/lsp/template/template.rego

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ package regal.lsp.template
77
render_for_builtin(builtin) := content if {
88
category := _category(builtin)
99
builtin_safe := _to_safe_builtin(builtin)
10+
args := concat(", ", [arg.name | some arg in builtin_safe.decl.args])
1011

1112
content := replace(
1213
strings.render_template(_builtin_template, {
1314
"builtin": builtin_safe,
1415
"category": category,
1516
"link": _docs_link(builtin_safe, category),
16-
"snippet": _example_snippet(builtin_safe),
17+
"snippet": $"```rego\n{builtin_safe.decl.result.name} := {builtin_safe.name}({args})\n```",
1718
}),
1819
"<bt>", "`",
1920
)
@@ -22,7 +23,7 @@ render_for_builtin(builtin) := content if {
2223
_docs_link(builtin, category) := link if {
2324
builtin.categories != []
2425

25-
link := [substring(bc, 4, -1) |
26+
link := [trim_prefix(bc, "url=") |
2627
some bc in builtin.categories
2728
startswith(bc, "url=")
2829
][0]
@@ -56,15 +57,6 @@ _category(builtin) := builtin.categories[0] if {
5657
i != -1
5758
} else := builtin.name
5859

59-
_example_snippet(builtin) := snippet if {
60-
args := [arg.name | some arg in builtin.decl.args]
61-
snippet := sprintf("```rego\n%s := %s(%s)\n```", [
62-
builtin.decl.result.name,
63-
builtin.name,
64-
concat(", ", args),
65-
])
66-
}
67-
6860
# here to work around the **extremely** annoying behavior of strings.render_template
6961
# where missing keys are treated as fatal errors instead of giving template authors a
7062
# chance to handle this: https://github.com/open-policy-agent/opa/issues/7931
@@ -83,11 +75,9 @@ _to_safe_builtin(builtin) := safe if {
8375
}
8476

8577
merged := object.union(safe_attributes, builtin)
86-
safe := object.union(merged, {"decl": {"args": _safe_args(merged.decl.args)}})
78+
safe := object.union(merged, {"decl": {"args": [_to_safe_arg(i, arg) | some i, arg in merged.decl.args]}})
8779
}
8880

89-
_safe_args(args) := [_to_safe_arg(i, arg) | some i, arg in args]
90-
9181
_to_safe_arg(i, arg) := arg if {
9282
_safe_arg(arg)
9383
} else := object.union(

bundle/regal/lsp/template/template_test.rego

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,58 @@ package regal.lsp.template_test
22

33
import data.regal.lsp.template
44

5+
test_template_common_builtin_function if {
6+
builtin := {
7+
"categories": ["strings"],
8+
"decl": {
9+
"args": [
10+
{
11+
"description": "search string",
12+
"name": "search",
13+
"type": "string",
14+
},
15+
{
16+
"description": "base string",
17+
"name": "base",
18+
"type": "string",
19+
},
20+
],
21+
"result": {
22+
"description": "result of the prefix check",
23+
"name": "result",
24+
"type": "boolean",
25+
},
26+
"type": "function",
27+
},
28+
"description": "Returns true if the search string begins with the base string.",
29+
"name": "startswith",
30+
}
31+
rendered := template.render_for_builtin(builtin)
32+
33+
rendered == concat("\n", [
34+
`### [startswith](https://www.openpolicyagent.org/docs/policy-reference/#builtin-strings-startswith)`,
35+
"",
36+
"```rego",
37+
"result := startswith(search, base)",
38+
"```",
39+
"",
40+
"Returns true if the search string begins with the base string.",
41+
"",
42+
"#### Arguments",
43+
"",
44+
"- `search` string: search string",
45+
"- `base` string: base string",
46+
"",
47+
"Returns `result` of type `boolean`: result of the prefix check",
48+
"",
49+
])
50+
}
51+
552
test_template_eopa_builtin if {
653
builtin := {
754
"name": "neo4j.query",
855
"description": "Returns results for the given neo4j query.",
9-
"categories": ["url=https://docs.styra.com/enterprise-opa/reference/built-in-functions/neo4j"],
56+
"categories": ["url=https://github.com/open-policy-agent/eopa/blob/main/docs/eopa/reference/built-in-functions/neo4j.md"],
1057
"decl": {
1158
"args": [{
1259
"description": "query object",

docs/adopters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ Public open source projects integrating Regal for linting in their CI/CD pipelin
3535
Projects and products that integrate Regal into their offerings.
3636

3737
<!-- cspell:disable -->
38+
- [Code Rabbit](https://docs.coderabbit.ai/tools/regal)
3839
- [Dependency Management Data](https://gitlab.com/tanna.dev/dependency-management-data)
39-
- [Enterprise OPA](https://github.com/styrainc/enterprise-opa)
40+
- [EOPA](https://github.com/open-policy-agent/eopa)
4041
- [The Rego Playground](https://play.openpolicyagent.org)
4142
- [Trunk Check](https://trunk.io/)
4243
- [reviewdog/action-regal](https://github.com/reviewdog/action-regal)
@@ -74,7 +75,6 @@ Some companies and organizations using Regal.
7475
- [Red Hat](https://www.redhat.com)
7576
- [Spacelift](https://www.spacelift.io)
7677
- [Stacklok](https://stacklok.com)
77-
- [Styra](https://www.styra.com)
7878
- [UNIwise](https://uniwise.eu/)
7979
- [VodafoneZiggo](https://www.vodafoneziggo.nl)
8080
<!-- cspell:enable-->

docs/configuration/capabilities.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ capabilities:
4343
version: v0.58.0
4444
minus:
4545
builtins:
46-
# exclude rules that depend on the http.send built-in function
47-
- name: http.send
46+
# exclude rules that depend on the http.send built-in function
47+
- name: http.send
4848
plus:
4949
builtins:
50-
# make Regal aware of a custom "ldap.query" function
51-
- name: ldap.query
52-
type: function
53-
decl:
54-
args:
55-
- type: string
56-
result:
57-
type: object
50+
# make Regal aware of a custom "ldap.query" function
51+
- name: ldap.query
52+
type: function
53+
decl:
54+
args:
55+
- type: string
56+
result:
57+
type: object
5858
```
5959

6060
## Loading Capabilities from URLs
@@ -73,10 +73,10 @@ capabilities:
7373

7474
Regal includes capabilities files for the following engines:
7575

76-
| Engine | Website | Description |
77-
| ------ | --------------------------------------------------------------- | -------------------- |
78-
| `opa` | [OPA website](https://www.openpolicyagent.org/) | Open Policy Agent |
79-
| `eopa` | [Enterprise OPA website](https://www.styra.com/enterprise-opa/) | Styra Enterprise OPA |
80-
| `rq` | [rq website](https://git.sr.ht/~charles/rq) | Rego Query (`rq`) |
76+
| Engine | Website | Description |
77+
| ------ | ------------------------------------------------------------ | ----------------- |
78+
| `opa` | [OPA website](https://www.openpolicyagent.org/) | Open Policy Agent |
79+
| `eopa` | [EOPA repository](https://github.com/open-policy-agent/eopa) | EOPA |
80+
| `rq` | [rq website](https://git.sr.ht/~charles/rq) | Rego Query (`rq`) |
8181

8282
**`rq` support note**: `rq` scripts must include `package` statements to be compatible with Regal.

internal/lsp/semantictokens_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ func generateLargePolicy(numFunctions int) string {
161161
policy.WriteString("package regal.woo\n\n")
162162

163163
for i := range numFunctions {
164-
policy.WriteString(fmt.Sprintf(`test_function_%d(param1, param2) := result if {
164+
fmt.Fprintf(&policy, `test_function_%d(param1, param2) := result if {
165165
calc1 := param1 * %d
166166
calc2 := param2 + %d
167167
result := calc1 + calc2
168168
}
169169
170-
`, i, i+1, i+10))
170+
`, i, i+1, i+10)
171171
}
172172

173173
return policy.String()

pkg/roast/rast/rast_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestStructToValueTagWithTrailingComma(t *testing.T) {
6363
t.Parallel()
6464

6565
type testStruct struct {
66-
Field string `json:"field,"`
66+
Field string `json:"field,"` //nolint:staticcheck
6767
}
6868

6969
got := rast.StructToValue(testStruct{Field: "value"})

0 commit comments

Comments
 (0)