#!  Copyright 2024 Google LLC
#!
#!  Licensed under the Apache License, Version 2.0 (the "License");
#!  you may not use this file except in compliance with the License.
#!  You may obtain a copy of the License at
#!
#!       http://www.apache.org/licenses/LICENSE-2.0
#!
#!  Unless required by applicable law or agreed to in writing, software
#!  distributed under the License is distributed on an "AS IS" BASIS,
#!  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#!  See the License for the specific language governing permissions and
#!  limitations under the License.

#@ load("@ytt:data", "data")
#@ load("@ytt:template", "template")

#@ load("/policies.lib.star", "build_policy")
#@ load("/policies.lib.yaml", "generate_policy")
#@ load("/policies-dryrun.lib.yaml", "generate_policy_dryrun")
#@ load("/config.lib.star", "services")

#@ policies = []

#@ if data.values.service != "":
  #@ services = []
  #@ services.append(data.values.service)
#@ end

#@ for service in services:
  #@ for value in data.values[service]:
    #@ policy = build_policy(value)
    #@ if policy.to_generate() == True:
      #@ policies.append(value)
    #@ end
  #@ end
#@ end

#@ for value in policies:
---
  #@ policy = build_policy(value)
  #@ if data.values.dryrun == True:
    #@ template.replace(generate_policy_dryrun(policy))
  #@ else:
    #@ template.replace(generate_policy(policy))
  #@ end
#@ end