@@ -150,7 +150,7 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
150150// policyConf.ConsolidateManifests = false will generate a policy templates slice
151151// that each template includes a single manifest specified in policyConf.
152152// An error is returned if one or more manifests cannot be read or are invalid.
153- func getPolicyTemplates (policyConf * types.PolicyConfig ) ([]map [string ]map [ string ] interface {}, error ) {
153+ func getPolicyTemplates (policyConf * types.PolicyConfig ) ([]map [string ]interface {}, error ) {
154154 manifestGroups , err := getManifests (policyConf )
155155 if err != nil {
156156 return nil , err
@@ -165,7 +165,7 @@ func getPolicyTemplates(policyConf *types.PolicyConfig) ([]map[string]map[string
165165 }
166166
167167 objectTemplates := make ([]map [string ]interface {}, 0 , objectTemplatesLength )
168- policyTemplates := make ([]map [string ]map [ string ] interface {}, 0 , policyTemplatesLength )
168+ policyTemplates := make ([]map [string ]interface {}, 0 , policyTemplatesLength )
169169
170170 for i , manifestGroup := range manifestGroups {
171171 complianceType := policyConf .Manifests [i ].ComplianceType
@@ -182,7 +182,8 @@ func getPolicyTemplates(policyConf *types.PolicyConfig) ([]map[string]map[string
182182 }
183183
184184 if isPolicyTypeManifest {
185- policyTemplate := map [string ]map [string ]interface {}{"objectDefinition" : manifest }
185+ policyTemplate := map [string ]interface {}{"objectDefinition" : manifest }
186+
186187 policyTemplates = append (policyTemplates , policyTemplate )
187188
188189 continue
@@ -275,14 +276,15 @@ func isPolicyTypeManifest(manifest map[string]interface{}) (bool, error) {
275276// setNamespaceSelector sets the namespace selector, if set, on the input policy template.
276277func setNamespaceSelector (
277278 policyConf * types.ConfigurationPolicyOptions ,
278- policyTemplate map [string ]map [ string ] interface {},
279+ policyTemplate map [string ]interface {},
279280) {
280281 selector := policyConf .NamespaceSelector
281282 if selector .Exclude != nil ||
282283 selector .Include != nil ||
283284 selector .MatchLabels != nil ||
284285 selector .MatchExpressions != nil {
285- spec := policyTemplate ["objectDefinition" ]["spec" ].(map [string ]interface {})
286+ objDef := policyTemplate ["objectDefinition" ].(map [string ]interface {})
287+ spec := objDef ["spec" ].(map [string ]interface {})
286288 spec ["namespaceSelector" ] = selector
287289 }
288290}
@@ -317,16 +319,16 @@ func buildPolicyTemplate(
317319 policyNum int ,
318320 objectTemplates []map [string ]interface {},
319321 configPolicyOptionsOverrides * types.ConfigurationPolicyOptions ,
320- ) map [string ]map [ string ] interface {} {
322+ ) map [string ]interface {} {
321323 var name string
322324 if policyNum > 1 {
323325 name = fmt .Sprintf ("%s%d" , policyConf .Name , policyNum )
324326 } else {
325327 name = policyConf .Name
326328 }
327329
328- policyTemplate := map [string ]map [ string ] interface {}{
329- "objectDefinition" : {
330+ policyTemplate := map [string ]interface {}{
331+ "objectDefinition" : map [ string ] interface {} {
330332 "apiVersion" : policyAPIVersion ,
331333 "kind" : configPolicyKind ,
332334 "metadata" : map [string ]interface {}{
@@ -344,11 +346,13 @@ func buildPolicyTemplate(
344346 setNamespaceSelector (& policyConf .ConfigurationPolicyOptions , policyTemplate )
345347
346348 if len (policyConf .ConfigurationPolicyAnnotations ) > 0 {
347- metadata := policyTemplate ["objectDefinition" ]["metadata" ].(map [string ]interface {})
349+ objDef := policyTemplate ["objectDefinition" ].(map [string ]interface {})
350+ metadata := objDef ["metadata" ].(map [string ]interface {})
348351 metadata ["annotations" ] = policyConf .ConfigurationPolicyAnnotations
349352 }
350353
351- configSpec := policyTemplate ["objectDefinition" ]["spec" ].(map [string ]interface {})
354+ objDef := policyTemplate ["objectDefinition" ].(map [string ]interface {})
355+ configSpec := objDef ["spec" ].(map [string ]interface {})
352356
353357 // Set EvaluationInterval with manifest overrides
354358 evaluationInterval := configPolicyOptionsOverrides .EvaluationInterval
@@ -389,10 +393,8 @@ func buildPolicyTemplate(
389393
390394// handleExpanders will go through all the enabled expanders and generate additional
391395// policy templates to include in the policy.
392- func handleExpanders (
393- manifests []map [string ]interface {}, policyConf types.PolicyConfig ,
394- ) []map [string ]map [string ]interface {} {
395- policyTemplates := []map [string ]map [string ]interface {}{}
396+ func handleExpanders (manifests []map [string ]interface {}, policyConf types.PolicyConfig ) []map [string ]interface {} {
397+ policyTemplates := []map [string ]interface {}{}
396398
397399 for _ , expander := range expanders .GetExpanders () {
398400 for _ , m := range manifests {
@@ -499,11 +501,12 @@ func verifyManifestPath(baseDirectory string, manifestPath string) error {
499501}
500502
501503// Check policy-templates to see if all the remediation actions match, if so return the root policy remediation action
502- func getRootRemediationAction (policyTemplates []map [string ]map [ string ] interface {}) string {
504+ func getRootRemediationAction (policyTemplates []map [string ]interface {}) string {
503505 var action string
504506
505507 for _ , value := range policyTemplates {
506- if spec , ok := value ["objectDefinition" ]["spec" ].(map [string ]interface {}); ok {
508+ objDef := value ["objectDefinition" ].(map [string ]interface {})
509+ if spec , ok := objDef ["spec" ].(map [string ]interface {}); ok {
507510 if _ , ok = spec ["remediationAction" ].(string ); ok {
508511 if action == "" {
509512 action = spec ["remediationAction" ].(string )
0 commit comments