@@ -77,14 +77,14 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
7777 return nil , err
7878 }
7979
80- if len (* manifestFile ) == 0 {
80+ if len (manifestFile ) == 0 {
8181 continue
8282 }
8383 // Allowing replace the original manifest metadata.name and/or metadata.namespace if it is a single
8484 // yaml structure in the manifest path
85- if len (* manifestFile ) == 1 && len (manifest .Patches ) == 1 {
85+ if len (manifestFile ) == 1 && len (manifest .Patches ) == 1 {
8686 if patchMetadata , ok := manifest .Patches [0 ]["metadata" ].(map [string ]interface {}); ok {
87- if metadata , ok := ( * manifestFile ) [0 ]["metadata" ].(map [string ]interface {}); ok {
87+ if metadata , ok := manifestFile [0 ]["metadata" ].(map [string ]interface {}); ok {
8888 name , ok := patchMetadata ["name" ].(string )
8989 if ok && name != "" {
9090 metadata ["name" ] = name
@@ -93,16 +93,16 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
9393 if ok && namespace != "" {
9494 metadata ["namespace" ] = namespace
9595 }
96- ( * manifestFile ) [0 ]["metadata" ] = metadata
96+ manifestFile [0 ]["metadata" ] = metadata
9797 }
9898 }
9999 }
100100
101- manifestFiles = append (manifestFiles , * manifestFile ... )
101+ manifestFiles = append (manifestFiles , manifestFile ... )
102102 }
103103
104104 for _ , manifestPath := range manifestPaths {
105- var manifestFile * []map [string ]interface {}
105+ var manifestFile []map [string ]interface {}
106106 var err error
107107
108108 if hasKustomize [manifestPath ] {
@@ -115,11 +115,11 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
115115 return nil , err
116116 }
117117
118- if len (* manifestFile ) == 0 {
118+ if len (manifestFile ) == 0 {
119119 continue
120120 }
121121
122- manifestFiles = append (manifestFiles , * manifestFile ... )
122+ manifestFiles = append (manifestFiles , manifestFile ... )
123123 }
124124
125125 if len (manifest .Patches ) > 0 {
@@ -136,7 +136,7 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
136136 return nil , fmt .Errorf (errTemplate , manifest .Path , err )
137137 }
138138
139- manifestFiles = * patchedFiles
139+ manifestFiles = patchedFiles
140140 }
141141
142142 manifests = append (manifests , manifestFiles )
@@ -207,10 +207,10 @@ func getPolicyTemplates(policyConf *types.PolicyConfig) ([]map[string]map[string
207207 policyTemplate := buildPolicyTemplate (
208208 policyConf ,
209209 len (policyTemplates )+ 1 ,
210- & []map [string ]interface {}{objTemplate },
211- policyConf .Manifests [i ].ConfigurationPolicyOptions ,
210+ []map [string ]interface {}{objTemplate },
211+ & policyConf .Manifests [i ].ConfigurationPolicyOptions ,
212212 )
213- policyTemplates = append (policyTemplates , * policyTemplate )
213+ policyTemplates = append (policyTemplates , policyTemplate )
214214 }
215215 }
216216 }
@@ -227,15 +227,15 @@ func getPolicyTemplates(policyConf *types.PolicyConfig) ([]map[string]map[string
227227 policyTemplate := buildPolicyTemplate (
228228 policyConf ,
229229 1 ,
230- & objectTemplates ,
231- policyConf .ConfigurationPolicyOptions ,
230+ objectTemplates ,
231+ & policyConf .ConfigurationPolicyOptions ,
232232 )
233- policyTemplates = append (policyTemplates , * policyTemplate )
233+ policyTemplates = append (policyTemplates , policyTemplate )
234234 }
235235
236236 // check the enabled expanders and add additional policy templates
237237 for _ , manifestGroup := range manifestGroups {
238- expandedPolicyTemplates := handleExpanders (manifestGroup , policyConf )
238+ expandedPolicyTemplates := handleExpanders (manifestGroup , * policyConf )
239239 policyTemplates = append (policyTemplates , expandedPolicyTemplates ... )
240240 }
241241
@@ -263,7 +263,7 @@ func isPolicyTypeManifest(manifest map[string]interface{}) (bool, error) {
263263
264264// setNamespaceSelector sets the namespace selector, if set, on the input policy template.
265265func setNamespaceSelector (
266- policyConf types.ConfigurationPolicyOptions ,
266+ policyConf * types.ConfigurationPolicyOptions ,
267267 policyTemplate map [string ]map [string ]interface {},
268268) {
269269 selector := policyConf .NamespaceSelector
@@ -277,7 +277,7 @@ func setNamespaceSelector(
277277}
278278
279279// processKustomizeDir runs a provided directory through Kustomize in order to generate the manifests within it.
280- func processKustomizeDir (path string ) (* []map [string ]interface {}, error ) {
280+ func processKustomizeDir (path string ) ([]map [string ]interface {}, error ) {
281281 k := krusty .MakeKustomizer (krusty .MakeDefaultOptions ())
282282
283283 resourceMap , err := k .Run (filesys .MakeFsOnDisk (), path )
@@ -304,9 +304,9 @@ func processKustomizeDir(path string) (*[]map[string]interface{}, error) {
304304func buildPolicyTemplate (
305305 policyConf * types.PolicyConfig ,
306306 policyNum int ,
307- objectTemplates * []map [string ]interface {},
308- configPolicyOptionsOverrides types.ConfigurationPolicyOptions ,
309- ) * map [string ]map [string ]interface {} {
307+ objectTemplates []map [string ]interface {},
308+ configPolicyOptionsOverrides * types.ConfigurationPolicyOptions ,
309+ ) map [string ]map [string ]interface {} {
310310 var name string
311311 if policyNum > 1 {
312312 name = fmt .Sprintf ("%s%d" , policyConf .Name , policyNum )
@@ -322,15 +322,15 @@ func buildPolicyTemplate(
322322 "name" : name ,
323323 },
324324 "spec" : map [string ]interface {}{
325- "object-templates" : * objectTemplates ,
325+ "object-templates" : objectTemplates ,
326326 "remediationAction" : policyConf .RemediationAction ,
327327 "severity" : policyConf .Severity ,
328328 },
329329 },
330330 }
331331
332332 // Set NamespaceSelector with policy configuration
333- setNamespaceSelector (policyConf .ConfigurationPolicyOptions , policyTemplate )
333+ setNamespaceSelector (& policyConf .ConfigurationPolicyOptions , policyTemplate )
334334
335335 if len (policyConf .ConfigurationPolicyAnnotations ) > 0 {
336336 metadata := policyTemplate ["objectDefinition" ]["metadata" ].(map [string ]interface {})
@@ -373,19 +373,19 @@ func buildPolicyTemplate(
373373 configSpec ["severity" ] = configPolicyOptionsOverrides .Severity
374374 }
375375
376- return & policyTemplate
376+ return policyTemplate
377377}
378378
379379// handleExpanders will go through all the enabled expanders and generate additional
380380// policy templates to include in the policy.
381381func handleExpanders (
382- manifests []map [string ]interface {}, policyConf * types.PolicyConfig ,
382+ manifests []map [string ]interface {}, policyConf types.PolicyConfig ,
383383) []map [string ]map [string ]interface {} {
384384 policyTemplates := []map [string ]map [string ]interface {}{}
385385
386386 for _ , expander := range expanders .GetExpanders () {
387387 for _ , m := range manifests {
388- if expander .Enabled (policyConf ) && expander .CanHandle (m ) {
388+ if expander .Enabled (& policyConf ) && expander .CanHandle (m ) {
389389 expandedPolicyTemplates := expander .Expand (m , policyConf .Severity )
390390 policyTemplates = append (policyTemplates , expandedPolicyTemplates ... )
391391 }
@@ -399,7 +399,7 @@ func handleExpanders(
399399// a slice in order to account for multiple YAML documents in the same file.
400400// If the file cannot be decoded or each document is not a map, an error will
401401// be returned.
402- func unmarshalManifestFile (manifestPath string ) (* []map [string ]interface {}, error ) {
402+ func unmarshalManifestFile (manifestPath string ) ([]map [string ]interface {}, error ) {
403403 // #nosec G304
404404 manifestBytes , err := ioutil .ReadFile (manifestPath )
405405 if err != nil {
@@ -417,7 +417,7 @@ func unmarshalManifestFile(manifestPath string) (*[]map[string]interface{}, erro
417417// unmarshalManifestBytes unmarshals the input bytes slice of an object manifest/definition file
418418// into a slice of maps in order to account for multiple YAML documents in the bytes slice. If each
419419// document is not a map, an error will be returned.
420- func unmarshalManifestBytes (manifestBytes []byte ) (* []map [string ]interface {}, error ) {
420+ func unmarshalManifestBytes (manifestBytes []byte ) ([]map [string ]interface {}, error ) {
421421 yamlDocs := []map [string ]interface {}{}
422422 d := yaml .NewDecoder (bytes .NewReader (manifestBytes ))
423423
@@ -445,7 +445,7 @@ func unmarshalManifestBytes(manifestBytes []byte) (*[]map[string]interface{}, er
445445 }
446446 }
447447
448- return & yamlDocs , nil
448+ return yamlDocs , nil
449449}
450450
451451// verifyManifestPath verifies that the manifest path is in the directory tree under baseDirectory.
0 commit comments