Skip to content

Commit 418ff50

Browse files
test: Use common directory structure for OPA rules
1 parent 6edc3ba commit 418ff50

11 files changed

Lines changed: 46 additions & 51 deletions

tests/templates/kuttl/opa-authorization/trino_rules/actual_permissions.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/actual_permissions.rego

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package trino
22

3-
import data.util
4-
53
# This file contains functions to determine the actual permissions
64
# defined in the Trino policies for the given user and requested
75
# resource.
@@ -41,7 +39,7 @@ default match_any_group(_) := false
4139

4240
match_any_group(group_pattern) if {
4341
some group in groups
44-
util.match_entire(group_pattern, group)
42+
match_entire(group_pattern, group)
4543
}
4644

4745
default match_user_group(_) := false
@@ -50,7 +48,7 @@ match_user_group(rule) if {
5048
user_pattern := object.get(rule, "user", ".*")
5149
group_pattern := object.get(rule, "group", ".*")
5250

53-
util.match_entire(user_pattern, identity.user)
51+
match_entire(user_pattern, identity.user)
5452
match_any_group(group_pattern)
5553
}
5654

@@ -60,7 +58,7 @@ match_original_user_group(rule) if {
6058
user_pattern := object.get(rule, "original_user", ".*")
6159
group_pattern := object.get(rule, "original_group", ".*")
6260

63-
util.match_entire(user_pattern, identity.user)
61+
match_entire(user_pattern, identity.user)
6462
match_any_group(group_pattern)
6563
}
6664

@@ -72,7 +70,7 @@ first_matching_authorization_rule(grantee_name) := rule if {
7270

7371
new_user_pattern := object.get(rule, "new_user", ".*")
7472

75-
util.match_entire(new_user_pattern, grantee_name)
73+
match_entire(new_user_pattern, grantee_name)
7674
]
7775
rule := object.union(
7876
{"allow": true},
@@ -92,7 +90,7 @@ first_matching_catalog_rule(catalog_name) := rule if {
9290

9391
catalog_pattern := object.get(rule, "catalog", ".*")
9492

95-
util.match_entire(catalog_pattern, catalog_name)
93+
match_entire(catalog_pattern, catalog_name)
9694
]
9795
rule := rules[0]
9896
}
@@ -119,8 +117,8 @@ first_matching_catalog_session_properties_rule(
119117
catalog_pattern := object.get(rule, "catalog", ".*")
120118
property_pattern := object.get(rule, "property", ".*")
121119

122-
util.match_entire(catalog_pattern, catalog_name)
123-
util.match_entire(property_pattern, property_name)
120+
match_entire(catalog_pattern, catalog_name)
121+
match_entire(property_pattern, property_name)
124122
]
125123
rule := rules[0]
126124
}
@@ -150,7 +148,7 @@ catalog_visibility(catalog_name) if {
150148

151149
catalog_pattern := object.get(rule, "catalog", ".*")
152150

153-
util.match_entire(catalog_pattern, catalog_name)
151+
match_entire(catalog_pattern, catalog_name)
154152

155153
rule.owner == true
156154
}
@@ -172,7 +170,7 @@ catalog_visibility(catalog_name) if {
172170

173171
catalog_pattern := object.get(rule, "catalog", ".*")
174172

175-
util.match_entire(catalog_pattern, catalog_name)
173+
match_entire(catalog_pattern, catalog_name)
176174

177175
count(rule.privileges) != 0
178176
}
@@ -186,7 +184,7 @@ catalog_visibility(catalog_name) if {
186184

187185
catalog_pattern := object.get(rule, "catalog", ".*")
188186

189-
util.match_entire(catalog_pattern, catalog_name)
187+
match_entire(catalog_pattern, catalog_name)
190188

191189
rule.allow == true
192190
}
@@ -205,9 +203,9 @@ first_matching_function_rule(
205203
schema_pattern := object.get(rule, "schema", ".*")
206204
function_pattern := object.get(rule, "function", ".*")
207205

208-
util.match_entire(catalog_pattern, catalog_name)
209-
util.match_entire(schema_pattern, schema_name)
210-
util.match_entire(function_pattern, function_name)
206+
match_entire(catalog_pattern, catalog_name)
207+
match_entire(schema_pattern, schema_name)
208+
match_entire(function_pattern, function_name)
211209
]
212210
rule := rules[0]
213211
}
@@ -251,7 +249,7 @@ first_matching_impersonation_rule(user) := rule if {
251249
unsubstituted_new_user_pattern,
252250
)
253251

254-
util.match_entire(new_user_pattern, user)
252+
match_entire(new_user_pattern, user)
255253
]
256254
rule := object.union(
257255
{"allow": true},
@@ -289,9 +287,9 @@ first_matching_procedure_rule(
289287
schema_pattern := object.get(rule, "schema", ".*")
290288
procedure_pattern := object.get(rule, "procedure", ".*")
291289

292-
util.match_entire(catalog_pattern, catalog_name)
293-
util.match_entire(schema_pattern, schema_name)
294-
util.match_entire(procedure_pattern, function_name)
290+
match_entire(catalog_pattern, catalog_name)
291+
match_entire(schema_pattern, schema_name)
292+
match_entire(procedure_pattern, function_name)
295293
]
296294
rule := rules[0]
297295
}
@@ -331,7 +329,7 @@ first_matching_query_owned_by_rule(user) := rule if {
331329

332330
query_owner_pattern := object.get(rule, "queryOwner", ".*")
333331

334-
util.match_entire(query_owner_pattern, user)
332+
match_entire(query_owner_pattern, user)
335333
]
336334
rule := rules[0]
337335
}
@@ -358,8 +356,8 @@ first_matching_schema_rule(catalog_name, schema_name) := rule if {
358356
catalog_pattern := object.get(rule, "catalog", ".*")
359357
schema_pattern := object.get(rule, "schema", ".*")
360358

361-
util.match_entire(catalog_pattern, catalog_name)
362-
util.match_entire(schema_pattern, schema_name)
359+
match_entire(catalog_pattern, catalog_name)
360+
match_entire(schema_pattern, schema_name)
363361
]
364362
rule := rules[0]
365363
}
@@ -397,8 +395,8 @@ schema_visibility(catalog_name, schema_name) if {
397395
catalog_pattern := object.get(rule, "catalog", ".*")
398396
schema_pattern := object.get(rule, "schema", ".*")
399397

400-
util.match_entire(catalog_pattern, catalog_name)
401-
util.match_entire(schema_pattern, schema_name)
398+
match_entire(catalog_pattern, catalog_name)
399+
match_entire(schema_pattern, schema_name)
402400

403401
count(rule.privileges) != 0
404402
}
@@ -432,9 +430,9 @@ first_matching_table_rule(
432430
schema_pattern := object.get(rule, "schema", ".*")
433431
table_pattern := object.get(rule, "table", ".*")
434432

435-
util.match_entire(catalog_pattern, catalog_name)
436-
util.match_entire(schema_pattern, schema_name)
437-
util.match_entire(table_pattern, table_name)
433+
match_entire(catalog_pattern, catalog_name)
434+
match_entire(schema_pattern, schema_name)
435+
match_entire(table_pattern, table_name)
438436
]
439437
rule := object.union(
440438
{
@@ -545,7 +543,7 @@ first_matching_system_session_properties_rule(property_name) := rule if {
545543

546544
property_name_pattern := object.get(rule, "property", ".*")
547545

548-
util.match_entire(property_name_pattern, property_name)
546+
match_entire(property_name_pattern, property_name)
549547
]
550548
rule := rules[0]
551549
}

tests/templates/kuttl/opa-authorization/trino_rules/actual_permissions_test.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/actual_permissions_test.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package actual_permissions_test
1+
package trino_test
22

33
import data.trino
44

tests/templates/kuttl/opa-authorization/trino_rules/policies.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/policies.rego

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package trino
22

3-
import data.util
4-
53
# The final policies are a combination of policies offered by Stackable,
64
# policies provided externally, and default policies.
75
# Stackable's policies form the beginnings of the rule lists, i.e. they

tests/templates/kuttl/opa-authorization/trino_rules/policies_test.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/policies_test.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package policies_test
1+
package trino_test
22

33
import data.trino
44

tests/templates/kuttl/opa-authorization/trino_rules/requested_permissions.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/requested_permissions.rego

File renamed without changes.

tests/templates/kuttl/opa-authorization/trino_rules/requested_permissions_test.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/requested_permissions_test.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package requested_permissions_test
1+
package trino_test
22

33
import data.trino
44

tests/templates/kuttl/opa-authorization/trino_rules/util.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/util.rego

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# METADATA
2-
# description: Utility package which extends the built-in functions
3-
package util
1+
package trino
42

53
# METADATA
64
# description: |
@@ -11,6 +9,7 @@ package util
119
#
1210
# Returns:
1311
# result (boolean)
12+
# scope: document
1413
match_entire(pattern, value) if {
1514
pattern == `.*`
1615
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package trino_test
2+
3+
import data.trino
4+
5+
test_match_entire if {
6+
trino.match_entire(`.*`, "a")
7+
trino.match_entire(`a`, "a")
8+
trino.match_entire(`^a`, "a")
9+
trino.match_entire(`a$`, "a")
10+
trino.match_entire(`^a$`, "a")
11+
not trino.match_entire(`a`, "abc")
12+
not trino.match_entire(`b`, "abc")
13+
not trino.match_entire(`c`, "abc")
14+
}

tests/templates/kuttl/opa-authorization/trino_rules/verification.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/verification.rego

File renamed without changes.

tests/templates/kuttl/opa-authorization/trino_rules/verification_test.rego renamed to tests/templates/kuttl/opa-authorization/trino_rules/trino/verification_test.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package verification_test
1+
package trino_test
22

33
import data.trino
44

0 commit comments

Comments
 (0)