@@ -22,13 +22,6 @@ import (
2222 valid8orv1alpha1 "github.com/spectrocloud-labs/valid8or/api/v1alpha1"
2323)
2424
25- type permission struct {
26- Actions map [iamAction ]bool
27- Condition * v1alpha1.Condition
28- Errors []string
29- PolicyName string
30- }
31-
3225type iamAction struct {
3326 Service string
3427 Verb string
@@ -47,25 +40,32 @@ type missing struct {
4740 PolicyName string
4841}
4942
50- type IamRuleObj interface {
43+ type permission struct {
44+ Actions map [iamAction ]bool
45+ Condition * v1alpha1.Condition
46+ Errors []string
47+ PolicyName string
48+ }
49+
50+ type iamRule interface {
5151 Name () string
5252 IAMPolicies () []v1alpha1.PolicyDocument
5353}
5454
5555type IAMRuleService struct {
56- iamSvc * iam.IAM
5756 log logr.Logger
57+ iamSvc * iam.IAM
5858}
5959
6060func NewIAMRuleService (log logr.Logger , s * session.Session ) * IAMRuleService {
6161 return & IAMRuleService {
62- iamSvc : aws .IAMService (s ),
6362 log : log ,
63+ iamSvc : aws .IAMService (s ),
6464 }
6565}
6666
6767// ReconcileIAMRoleRule reconciles an IAM role validation rule from an AWSValidator config
68- func (s * IAMRuleService ) ReconcileIAMRoleRule (nn k8stypes.NamespacedName , rule IamRuleObj ) (* types.ValidationResult , error ) {
68+ func (s * IAMRuleService ) ReconcileIAMRoleRule (nn k8stypes.NamespacedName , rule iamRule ) (* types.ValidationResult , error ) {
6969
7070 // Build the default ValidationResult for this IAM rule
7171 vr := buildValidationResult (rule , constants .ValidationTypeIAMRolePolicy )
@@ -95,7 +95,7 @@ func (s *IAMRuleService) ReconcileIAMRoleRule(nn k8stypes.NamespacedName, rule I
9595}
9696
9797// ReconcileIAMUserRule reconciles an IAM user validation rule from an AWSValidator config
98- func (s * IAMRuleService ) ReconcileIAMUserRule (nn k8stypes.NamespacedName , rule IamRuleObj ) (* types.ValidationResult , error ) {
98+ func (s * IAMRuleService ) ReconcileIAMUserRule (nn k8stypes.NamespacedName , rule iamRule ) (* types.ValidationResult , error ) {
9999
100100 // Build the default ValidationResult for this IAM rule
101101 vr := buildValidationResult (rule , constants .ValidationTypeIAMUserPolicy )
@@ -125,7 +125,7 @@ func (s *IAMRuleService) ReconcileIAMUserRule(nn k8stypes.NamespacedName, rule I
125125}
126126
127127// ReconcileIAMGroupRule reconciles an IAM group validation rule from an AWSValidator config
128- func (s * IAMRuleService ) ReconcileIAMGroupRule (nn k8stypes.NamespacedName , rule IamRuleObj ) (* types.ValidationResult , error ) {
128+ func (s * IAMRuleService ) ReconcileIAMGroupRule (nn k8stypes.NamespacedName , rule iamRule ) (* types.ValidationResult , error ) {
129129
130130 // Build the default ValidationResult for this IAM rule
131131 vr := buildValidationResult (rule , constants .ValidationTypeIAMGroupPolicy )
@@ -155,7 +155,7 @@ func (s *IAMRuleService) ReconcileIAMGroupRule(nn k8stypes.NamespacedName, rule
155155}
156156
157157// ReconcileIAMPolicyRule reconciles an IAM policy validation rule from an AWSValidator config
158- func (s * IAMRuleService ) ReconcileIAMPolicyRule (nn k8stypes.NamespacedName , rule IamRuleObj ) (* types.ValidationResult , error ) {
158+ func (s * IAMRuleService ) ReconcileIAMPolicyRule (nn k8stypes.NamespacedName , rule iamRule ) (* types.ValidationResult , error ) {
159159
160160 // Build the default ValidationResult for this IAM rule
161161 vr := buildValidationResult (rule , constants .ValidationTypeIAMPolicy )
@@ -229,7 +229,7 @@ func (s *IAMRuleService) getPolicyDocument(policyArn *string, context []string)
229229}
230230
231231// buildValidationResult builds a default ValidationResult for a given validation type
232- func buildValidationResult (rule IamRuleObj , validationType string ) * types.ValidationResult {
232+ func buildValidationResult (rule iamRule , validationType string ) * types.ValidationResult {
233233 state := valid8orv1alpha1 .ValidationSucceeded
234234 latestCondition := valid8orv1alpha1 .DefaultValidationCondition ()
235235 latestCondition .Message = fmt .Sprintf ("All required %s permissions were found" , validationType )
@@ -239,7 +239,7 @@ func buildValidationResult(rule IamRuleObj, validationType string) *types.Valida
239239}
240240
241241// buildPermissions builds an IAM permission map from an IAM rule
242- func buildPermissions (rule IamRuleObj ) map [string ]* permission {
242+ func buildPermissions (rule iamRule ) map [string ]* permission {
243243 permissions := make (map [string ]* permission )
244244 for _ , p := range rule .IAMPolicies () {
245245 for _ , s := range p .Statements {
@@ -332,7 +332,7 @@ func updatePermissions(policyDocument *awspolicy.Policy, permissions map[string]
332332}
333333
334334// computeFailures derives IAM rule failures from an IAM permissions map once it has been fully updated
335- func computeFailures (rule IamRuleObj , permissions map [string ]* permission , vr * types.ValidationResult ) {
335+ func computeFailures (rule iamRule , permissions map [string ]* permission , vr * types.ValidationResult ) {
336336 failures := make ([]string , 0 )
337337 missingActions := make (map [string ]* missing )
338338
0 commit comments