Skip to content

Commit 0560845

Browse files
jan-lawcursoragent
authored andcommitted
style: fix lint issues
ref: https://redhat.atlassian.net/browse/ACM-35531 Signed-off-by: Janelle Law <jalaw@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2448361 commit 0560845

16 files changed

Lines changed: 484 additions & 485 deletions

cmd/PolicyGenerator/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func main() {
2626
fmt.Println("Usage: PolicyGenerator [flags] <policy-generator-config-file>...")
2727
pflag.PrintDefaults()
2828
}
29+
2930
pflag.Parse()
3031

3132
// Handle flags
@@ -87,8 +88,8 @@ func printUsageAndExit(errMsg string) {
8788
// arguments similar to fmt.Errorf(). If `debug` is set or it is given an empty message
8889
// string, it throws a panic to print the message along with the trace. Otherwise
8990
// it prints the formatted message to stderr and exits with error code 1.
90-
func errorAndExit(msg string, formatArgs ...interface{}) {
91-
printArgs := make([]interface{}, len(formatArgs))
91+
func errorAndExit(msg string, formatArgs ...any) {
92+
printArgs := make([]any, len(formatArgs))
9293
copy(printArgs, formatArgs)
9394
// Show trace if the debug flag is set
9495
if msg == "" || debug {

internal/expanders/expanders.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package expanders provides policy expanders for Gatekeeper and Kyverno.
2+
//
13
// Copyright Contributors to the Open Cluster Management project
24
package expanders
35

@@ -16,11 +18,11 @@ func GetExpanders() map[string]Expander {
1618
// Expander is the interface for all policy expander instances.
1719
type Expander interface {
1820
// CanHandle determines if the manifest is a policy that can be expanded.
19-
CanHandle(manifest map[string]interface{}) bool
21+
CanHandle(manifest map[string]any) bool
2022
// Enabled determines if the policy configuration allows a policy to be expanded.
2123
Enabled(policyConf *types.PolicyConfig) bool
2224
// Expand will generate additional policy templates for the policy for auditing purposes.
23-
Expand(manifest map[string]interface{}, severity string) []map[string]interface{}
25+
Expand(manifest map[string]any, severity string) []map[string]any
2426
}
2527

2628
// Common constants for the expanders.

internal/expanders/expanders_utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"github.com/google/go-cmp/cmp"
88
)
99

10-
func assertEqual(t *testing.T, a interface{}, b interface{}) {
10+
func assertEqual(t *testing.T, a any, b any) {
1111
t.Helper()
1212

1313
if a != b {
1414
t.Fatal(cmp.Diff(a, b))
1515
}
1616
}
1717

18-
func assertReflectEqual(t *testing.T, a interface{}, b interface{}) {
18+
func assertReflectEqual(t *testing.T, a any, b any) {
1919
t.Helper()
2020

2121
if !reflect.DeepEqual(a, b) {

internal/expanders/gatekeeper.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Copyright Contributors to the Open Cluster Management project
21
package expanders
32

43
import (
@@ -14,7 +13,7 @@ const (
1413
)
1514

1615
// CanHandle determines if the manifest is a Gatekeeper policy that can be expanded.
17-
func (g GatekeeperPolicyExpander) CanHandle(manifest map[string]interface{}) bool {
16+
func (g GatekeeperPolicyExpander) CanHandle(manifest map[string]any) bool {
1817
// Verify the APIVersion
1918
if a, _, _ := unstructured.NestedString(manifest, "apiVersion"); a != gatekeeperConstraintAPIVersion {
2019
return false
@@ -45,36 +44,36 @@ func (g GatekeeperPolicyExpander) Enabled(policyConf *types.PolicyConfig) bool {
4544
// for auditing purposes through Open Cluster Management. This should be run after the CanHandle
4645
// method.
4746
func (g GatekeeperPolicyExpander) Expand(
48-
manifest map[string]interface{}, severity string,
49-
) []map[string]interface{} {
50-
templates := []map[string]interface{}{}
47+
manifest map[string]any, severity string,
48+
) []map[string]any {
49+
templates := []map[string]any{}
5150
// These were previously validated in the CanHandle method.
5251
constraintName, _, _ := unstructured.NestedString(manifest, "metadata", "name")
5352
constraintKind, _, _ := unstructured.NestedString(manifest, "kind")
5453

5554
auditConfigPolicyName := "inform-gatekeeper-audit-" + constraintName
56-
auditConfigurationPolicy := map[string]interface{}{
57-
"objectDefinition": map[string]interface{}{
55+
auditConfigurationPolicy := map[string]any{
56+
"objectDefinition": map[string]any{
5857
"apiVersion": configPolicyAPIVersion,
5958
"kind": configPolicyKind,
60-
"metadata": map[string]interface{}{"name": auditConfigPolicyName},
61-
"spec": map[string]interface{}{
62-
"namespaceSelector": map[string]interface{}{
59+
"metadata": map[string]any{"name": auditConfigPolicyName},
60+
"spec": map[string]any{
61+
"namespaceSelector": map[string]any{
6362
"exclude": []string{"kube-*"},
6463
"include": []string{"*"},
6564
},
6665
"remediationAction": "inform",
6766
"severity": severity,
68-
"object-templates": []map[string]interface{}{
67+
"object-templates": []map[string]any{
6968
{
7069
"complianceType": "musthave",
71-
"objectDefinition": map[string]interface{}{
70+
"objectDefinition": map[string]any{
7271
"apiVersion": gatekeeperConstraintAPIVersion,
7372
"kind": constraintKind,
74-
"metadata": map[string]interface{}{
73+
"metadata": map[string]any{
7574
"name": constraintName,
7675
},
77-
"status": map[string]interface{}{
76+
"status": map[string]any{
7877
"totalViolations": 0,
7978
},
8079
},
@@ -86,25 +85,25 @@ func (g GatekeeperPolicyExpander) Expand(
8685
// Further improvements here could be made by having the user specify the Gatekeeper namespace and
8786
// targeting the events for the constraint kind to just that namespace.
8887
admissionConfigPolicyName := "inform-gatekeeper-admission-" + constraintName
89-
admissionConfigurationPolicy := map[string]interface{}{
90-
"objectDefinition": map[string]interface{}{
88+
admissionConfigurationPolicy := map[string]any{
89+
"objectDefinition": map[string]any{
9190
"apiVersion": configPolicyAPIVersion,
9291
"kind": configPolicyKind,
93-
"metadata": map[string]interface{}{"name": admissionConfigPolicyName},
94-
"spec": map[string]interface{}{
95-
"namespaceSelector": map[string]interface{}{
92+
"metadata": map[string]any{"name": admissionConfigPolicyName},
93+
"spec": map[string]any{
94+
"namespaceSelector": map[string]any{
9695
"exclude": []string{"kube-*"},
9796
"include": []string{"*"},
9897
},
9998
"remediationAction": "inform",
10099
"severity": severity,
101-
"object-templates": []map[string]interface{}{
100+
"object-templates": []map[string]any{
102101
{
103102
"complianceType": "mustnothave",
104-
"objectDefinition": map[string]interface{}{
103+
"objectDefinition": map[string]any{
105104
"apiVersion": "v1",
106105
"kind": "Event",
107-
"annotations": map[string]interface{}{
106+
"annotations": map[string]any{
108107
"constraint_action": "deny",
109108
"constraint_kind": constraintKind,
110109
"constraint_name": constraintName,

internal/expanders/gatekeeper_test.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// // Copyright Contributors to the Open Cluster Management project
21
package expanders
32

43
import (
@@ -22,10 +21,10 @@ func TestGatekeeperCanHandle(t *testing.T) {
2221
func(t *testing.T) {
2322
t.Parallel()
2423

25-
manifest := map[string]interface{}{
24+
manifest := map[string]any{
2625
"apiVersion": gatekeeperConstraintAPIVersion,
2726
"kind": test.kind,
28-
"metadata": map[string]interface{}{
27+
"metadata": map[string]any{
2928
"name": "my-awesome-constraint",
3029
},
3130
}
@@ -51,10 +50,10 @@ func TestGatekeeperCanHandleInvalid(t *testing.T) {
5150
func(t *testing.T) {
5251
t.Parallel()
5352

54-
manifest := map[string]interface{}{
53+
manifest := map[string]any{
5554
"apiVersion": test.apiVersion,
5655
"kind": test.kind,
57-
"metadata": map[string]interface{}{
56+
"metadata": map[string]any{
5857
"name": test.name,
5958
},
6059
}
@@ -84,37 +83,37 @@ func TestGatekeeperExpand(t *testing.T) {
8483
t.Parallel()
8584

8685
g := GatekeeperPolicyExpander{}
87-
manifest := map[string]interface{}{
86+
manifest := map[string]any{
8887
"apiVersion": gatekeeperConstraintAPIVersion,
8988
"kind": "MyConstraint",
90-
"metadata": map[string]interface{}{
89+
"metadata": map[string]any{
9190
"name": "my-awesome-constraint",
9291
},
9392
}
9493

95-
expected := []map[string]interface{}{
94+
expected := []map[string]any{
9695
{
97-
"objectDefinition": map[string]interface{}{
96+
"objectDefinition": map[string]any{
9897
"apiVersion": configPolicyAPIVersion,
9998
"kind": configPolicyKind,
100-
"metadata": map[string]interface{}{"name": "inform-gatekeeper-audit-my-awesome-constraint"},
101-
"spec": map[string]interface{}{
102-
"namespaceSelector": map[string]interface{}{
99+
"metadata": map[string]any{"name": "inform-gatekeeper-audit-my-awesome-constraint"},
100+
"spec": map[string]any{
101+
"namespaceSelector": map[string]any{
103102
"exclude": []string{"kube-*"},
104103
"include": []string{"*"},
105104
},
106105
"remediationAction": "inform",
107106
"severity": "medium",
108-
"object-templates": []map[string]interface{}{
107+
"object-templates": []map[string]any{
109108
{
110109
"complianceType": "musthave",
111-
"objectDefinition": map[string]interface{}{
110+
"objectDefinition": map[string]any{
112111
"apiVersion": gatekeeperConstraintAPIVersion,
113112
"kind": "MyConstraint",
114-
"metadata": map[string]interface{}{
113+
"metadata": map[string]any{
115114
"name": "my-awesome-constraint",
116115
},
117-
"status": map[string]interface{}{
116+
"status": map[string]any{
118117
"totalViolations": 0,
119118
},
120119
},
@@ -124,24 +123,24 @@ func TestGatekeeperExpand(t *testing.T) {
124123
},
125124
},
126125
{
127-
"objectDefinition": map[string]interface{}{
126+
"objectDefinition": map[string]any{
128127
"apiVersion": configPolicyAPIVersion,
129128
"kind": configPolicyKind,
130-
"metadata": map[string]interface{}{"name": "inform-gatekeeper-admission-my-awesome-constraint"},
131-
"spec": map[string]interface{}{
132-
"namespaceSelector": map[string]interface{}{
129+
"metadata": map[string]any{"name": "inform-gatekeeper-admission-my-awesome-constraint"},
130+
"spec": map[string]any{
131+
"namespaceSelector": map[string]any{
133132
"exclude": []string{"kube-*"},
134133
"include": []string{"*"},
135134
},
136135
"remediationAction": "inform",
137136
"severity": "medium",
138-
"object-templates": []map[string]interface{}{
137+
"object-templates": []map[string]any{
139138
{
140139
"complianceType": "mustnothave",
141-
"objectDefinition": map[string]interface{}{
140+
"objectDefinition": map[string]any{
142141
"apiVersion": "v1",
143142
"kind": "Event",
144-
"annotations": map[string]interface{}{
143+
"annotations": map[string]any{
145144
"constraint_action": "deny",
146145
"constraint_kind": "MyConstraint",
147146
"constraint_name": "my-awesome-constraint",

internal/expanders/kyverno.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Copyright Contributors to the Open Cluster Management project
21
package expanders
32

43
import (
@@ -42,7 +41,7 @@ func isValidKyvernoKind(apiVersion, kind string) bool {
4241
}
4342

4443
// CanHandle determines if the manifest is a Kyverno policy that can be expanded.
45-
func (k KyvernoPolicyExpander) CanHandle(manifest map[string]interface{}) bool {
44+
func (k KyvernoPolicyExpander) CanHandle(manifest map[string]any) bool {
4645
apiVersion, _, _ := unstructured.NestedString(manifest, "apiVersion")
4746
kind, _, _ := unstructured.NestedString(manifest, "kind")
4847

@@ -65,32 +64,32 @@ func (k KyvernoPolicyExpander) Enabled(policyConf *types.PolicyConfig) bool {
6564
// Expand will generate additional policy templates for the Kyverno policy for auditing purposes
6665
// through Open Cluster Management. This should be run after the CanHandle method.
6766
func (k KyvernoPolicyExpander) Expand(
68-
manifest map[string]interface{}, severity string,
69-
) []map[string]interface{} {
70-
templates := []map[string]interface{}{}
67+
manifest map[string]any, severity string,
68+
) []map[string]any {
69+
templates := []map[string]any{}
7170
// This was previously validated in the CanHandle method.
7271
policyName, _, _ := unstructured.NestedString(manifest, "metadata", "name")
7372

7473
configPolicyName := "inform-kyverno-" + policyName
75-
configurationPolicy := map[string]interface{}{
76-
"objectDefinition": map[string]interface{}{
74+
configurationPolicy := map[string]any{
75+
"objectDefinition": map[string]any{
7776
"apiVersion": configPolicyAPIVersion,
7877
"kind": configPolicyKind,
79-
"metadata": map[string]interface{}{"name": configPolicyName},
80-
"spec": map[string]interface{}{
81-
"namespaceSelector": map[string]interface{}{
78+
"metadata": map[string]any{"name": configPolicyName},
79+
"spec": map[string]any{
80+
"namespaceSelector": map[string]any{
8281
"exclude": []string{"kube-*"},
8382
"include": []string{"*"},
8483
},
8584
"remediationAction": "inform",
8685
"severity": severity,
87-
"object-templates": []map[string]interface{}{
86+
"object-templates": []map[string]any{
8887
{
8988
"complianceType": "mustnothave",
90-
"objectDefinition": map[string]interface{}{
89+
"objectDefinition": map[string]any{
9190
"apiVersion": kyvernoPolicyReportAPIVersion,
9291
"kind": clusterPolicyReportKind,
93-
"results": []map[string]interface{}{
92+
"results": []map[string]any{
9493
{
9594
"policy": policyName,
9695
"result": "fail",
@@ -100,10 +99,10 @@ func (k KyvernoPolicyExpander) Expand(
10099
},
101100
{
102101
"complianceType": "mustnothave",
103-
"objectDefinition": map[string]interface{}{
102+
"objectDefinition": map[string]any{
104103
"apiVersion": kyvernoPolicyReportAPIVersion,
105104
"kind": namespacedPolicyReportKind,
106-
"results": []map[string]interface{}{
105+
"results": []map[string]any{
107106
{
108107
"policy": policyName,
109108
"result": "fail",

0 commit comments

Comments
 (0)