Skip to content

Commit 10439d4

Browse files
committed
feat: add OPA SDK support with configuration and rules
1 parent c776047 commit 10439d4

File tree

3 files changed

+95
-10
lines changed

3 files changed

+95
-10
lines changed

pkg/config/config.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@ type OpaRule struct {
2222
Filename string `hcl:"filename"`
2323
Notation *NotationVerifierConfig `hcl:"notation,block"`
2424
}
25+
type OpaSdkRule struct {
26+
Path string `hcl:"path"`
27+
}
2528

2629
type Validator struct {
27-
Type string `hcl:"type,label"`
28-
Name string `hcl:"name,label"`
29-
OpaRule *OpaRule `hcl:"opa_rule,block"`
30-
Webhook *Webhook `hcl:"webhook,block"`
31-
ResolveToken bool `hcl:"resolve_token,optional"`
30+
Type string `hcl:"type,label"`
31+
Name string `hcl:"name,label"`
32+
OpaRule *OpaRule `hcl:"opa_rule,block"`
33+
OpaSdkRule *OpaSdkRule `hcl:"opa_sdk_rule,block"`
34+
Webhook *Webhook `hcl:"webhook,block"`
35+
ResolveToken bool `hcl:"resolve_token,optional"`
3236

3337
Notation *NotationVerifierConfig `hcl:"notation,block"`
3438
}
3539
type Mutator struct {
36-
Type string `hcl:"type,label"`
37-
Name string `hcl:"name,label"`
38-
OpaRule *OpaRule `hcl:"opa_rule,block"`
39-
Webhook *Webhook `hcl:"webhook,block"`
40-
ResolveToken bool `hcl:"resolve_token,optional"`
40+
Type string `hcl:"type,label"`
41+
Name string `hcl:"name,label"`
42+
OpaRule *OpaRule `hcl:"opa_rule,block"`
43+
OpaSdkRule *OpaSdkRule `hcl:"opa_sdk_rule,block"`
44+
Webhook *Webhook `hcl:"webhook,block"`
45+
ResolveToken bool `hcl:"resolve_token,optional"`
4146
}
4247

4348
type RequestContext struct {
@@ -111,6 +116,12 @@ type Config struct {
111116
Mutators []Mutator `hcl:"mutator,block"`
112117

113118
Telemetry *Telemetry `hcl:"telemetry,block"`
119+
120+
OpaSdk *OpaSdk `hcl:"opa_sdk,block"`
121+
}
122+
type OpaSdk struct {
123+
Id string `hcl:"id,label"`
124+
ConfigPath string `hcl:"config_path"`
114125
}
115126

116127
func DefaultConfig() *Config {

pkg/config/config_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,61 @@ func TestLoadConfig(t *testing.T) {
248248

249249
wantErr: false,
250250
},
251+
{
252+
name: "with opa sdk",
253+
args: args{name: "testdata/with_opa_sdk.hcl"},
254+
want: &Config{
255+
Port: port,
256+
Bind: bind,
257+
258+
Nomad: &NomadServer{
259+
Address: nomadAddr,
260+
},
261+
Validators: []Validator{
262+
{
263+
Type: "opa_sdk",
264+
Name: "some_validator",
265+
OpaSdkRule: &OpaSdkRule{
266+
Path: "/my/validation/policy",
267+
},
268+
},
269+
},
270+
Mutators: []Mutator{
271+
{
272+
Type: "opa_sdk",
273+
Name: "some_mutator",
274+
OpaSdkRule: &OpaSdkRule{
275+
Path: "/my/mutation/policy",
276+
},
277+
},
278+
},
279+
Telemetry: &Telemetry{
280+
Logging: &Logging{
281+
Level: "info",
282+
SlogLogging: &SlogLogging{
283+
Text: Ptr(true),
284+
TextOut: Ptr("stdout"),
285+
Json: Ptr(false),
286+
JsonOut: Ptr("stdout"),
287+
},
288+
OtelLogging: &OtelLogging{
289+
Enabled: Ptr(false),
290+
},
291+
},
292+
Metrics: &Metrics{
293+
Enabled: false,
294+
},
295+
Tracing: &Tracing{
296+
Enabled: false,
297+
},
298+
},
299+
OpaSdk: &OpaSdk{
300+
301+
Id: "example",
302+
ConfigPath: "/my/path/to/config.json",
303+
},
304+
},
305+
},
251306
}
252307
for _, tt := range tests {
253308
t.Run(tt.name, func(t *testing.T) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
opa_sdk "example" {
3+
config_path = "/my/path/to/config.json"
4+
}
5+
6+
validator "opa_sdk" "some_validator" {
7+
8+
opa_sdk_rule {
9+
path = "/my/validation/policy"
10+
}
11+
}
12+
13+
mutator "opa_sdk" "some_mutator" {
14+
15+
opa_sdk_rule {
16+
path = "/my/mutation/policy"
17+
}
18+
19+
}

0 commit comments

Comments
 (0)