Skip to content

Commit

Permalink
Merge pull request meshery#11309 from ctcarrier/ctcarrier/chore/fix-w…
Browse files Browse the repository at this point in the history
…asm-rego-lint

Run regal linter against WASM policy and fix errors
  • Loading branch information
MUzairS15 authored Jul 24, 2024
2 parents ff29e8d + 98552e0 commit eb2c987
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 eb2c987

Please sign in to comment.