Skip to content

Commit

Permalink
Run regal linter against WASM policy and fix errors
Browse files Browse the repository at this point in the history
Signed-off-by: Chris C <[email protected]>
  • Loading branch information
ctcarrier committed Jul 11, 2024
1 parent 091eae9 commit 98552e0
Showing 1 changed file with 23 additions and 50 deletions.
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
}




0 comments on commit 98552e0

Please sign in to comment.