forked from meshery/meshery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run regal linter against WASM policy and fix errors
Signed-off-by: Chris C <[email protected]>
- Loading branch information
Showing
1 changed file
with
23 additions
and
50 deletions.
There are no files selected for viewing
73 changes: 23 additions & 50 deletions
73
...cies/namespace_discovery_relationship_policy/namespace_discovery_relationship_policy.rego
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,62 +1,35 @@ | ||
# https://play.openpolicyagent.org/p/wFNhyGsIej | ||
package hierarchical_policy | ||
|
||
available_namespaces[namespace_key] { | ||
service := input.services[_]; | ||
namespace_key = service.namespace | ||
} | ||
import rego.v1 | ||
|
||
available_namespaces[namespace_key] { | ||
service := input.services[_]; | ||
service.type == "Namespace"; | ||
namespace_key = service.name | ||
available_namespaces contains service.namespace if { | ||
some service in input.services | ||
} | ||
|
||
parent_child_mapping = { namespace_map: ns | | ||
some namespace_map | ||
available_namespaces[namespace_map] | ||
service := input.services[key] | ||
service.namespace | ||
service.namespace == namespace_map | ||
ns := {ns_serv: comp_id | | ||
some ns_serv | ||
x := input.services[ns_serv] | ||
x.namespace == namespace_map | ||
comp_id := x.traits.meshmap.id | ||
} | ||
available_namespaces contains service.name if { | ||
some service in input.services | ||
service.type == "Namespace" | ||
} | ||
|
||
namespaces_to_create[namespaces2] { | ||
some namespace | ||
available_namespaces[namespace] | ||
print(namespace) | ||
ns_creation_status = is_present(check_namespace_present_status(namespace)) | ||
print(ns_creation_status) | ||
ns_creation_status != true | ||
namespaces2 = namespace | ||
parent_child_mapping[namespace_map] := ns if { | ||
some namespace_map in available_namespaces | ||
some key, service in input.services | ||
service.namespace == namespace_map | ||
ns := {ns_serv: comp_id | | ||
some ns_serv, x in input.services | ||
x.namespace == namespace_map | ||
comp_id := x.traits.meshmap.id | ||
} | ||
} | ||
|
||
# incase of present: {"present": true}, in absent, returns empty set | ||
check_namespace_present_status(ns) = is_present { | ||
is_present := {"present": is | | ||
some svc | ||
s := input.services[svc] | ||
s.type == "Namespace" | ||
s.name == ns | ||
is = true | ||
} | ||
namespaces_to_create contains namespace if { | ||
some namespace in available_namespaces | ||
not namespace_present(namespace, input.services) | ||
} | ||
|
||
# Is present function wraps the result of check_namespace_present_status to true or false | ||
is_present(obj) { | ||
obj.present == true | ||
} | ||
|
||
is_present(obj) = pre { | ||
not obj.present | ||
pre = false | ||
# incase of present: {"present": true}, in absent, returns empty set | ||
namespace_present(ns, all_services) if { | ||
some s in all_services | ||
s.type == "Namespace" | ||
s.name == ns | ||
} | ||
|
||
|
||
|
||
|