@@ -23,6 +23,8 @@ import (
2323
2424 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
26+ "github.com/validator-labs/validator/pkg/validationrule"
27+
2628 "github.com/validator-labs/validator-plugin-aws/pkg/constants"
2729)
2830
@@ -97,11 +99,25 @@ type AwsSTSAuth struct {
9799// Each AmiRule is intended to match a single AMI, as an AmiRule is considered successful if at least one AMI is found.
98100// Refer to https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html for more information.
99101type AmiRule struct {
100- Name string `json:"name" yaml:"name"`
101- AmiIDs []string `json:"amiIds,omitempty" yaml:"amiIds,omitempty"`
102- Filters []Filter `json:"filters,omitempty" yaml:"filters,omitempty"`
103- Owners []string `json:"owners,omitempty" yaml:"owners,omitempty"`
104- Region string `json:"region" yaml:"region"`
102+ validationrule.ManuallyNamed `json:"-"`
103+
104+ RuleName string `json:"name" yaml:"name"`
105+ AmiIDs []string `json:"amiIds,omitempty" yaml:"amiIds,omitempty"`
106+ Filters []Filter `json:"filters,omitempty" yaml:"filters,omitempty"`
107+ Owners []string `json:"owners,omitempty" yaml:"owners,omitempty"`
108+ Region string `json:"region" yaml:"region"`
109+ }
110+
111+ var _ validationrule.Interface = (* AmiRule )(nil )
112+
113+ // Name returns the name of the AmiRule.
114+ func (r AmiRule ) Name () string {
115+ return r .RuleName
116+ }
117+
118+ // SetName sets the name of the AmiRule.
119+ func (r * AmiRule ) SetName (name string ) {
120+ r .RuleName = name
105121}
106122
107123// Filter defines a filter to apply to an AWS API query.
@@ -113,10 +129,14 @@ type Filter struct {
113129
114130// IamRoleRule compares the IAM permissions associated with an IAM role against an expected permission set.
115131type IamRoleRule struct {
132+ validationrule.AutomaticallyNamed `json:"-"`
133+
116134 IamRoleName string `json:"iamRoleName" yaml:"iamRoleName"`
117135 Policies []PolicyDocument `json:"iamPolicies" yaml:"iamPolicies"`
118136}
119137
138+ var _ validationrule.Interface = (* IamRoleRule )(nil )
139+
120140// Name returns the name of an IamRoleRule.
121141func (r IamRoleRule ) Name () string {
122142 return r .IamRoleName
@@ -129,10 +149,14 @@ func (r IamRoleRule) IAMPolicies() []PolicyDocument {
129149
130150// IamUserRule compares the IAM permissions associated with an IAM user against an expected permission set.
131151type IamUserRule struct {
152+ validationrule.AutomaticallyNamed `json:"-"`
153+
132154 IamUserName string `json:"iamUserName" yaml:"iamUserName"`
133155 Policies []PolicyDocument `json:"iamPolicies" yaml:"iamPolicies"`
134156}
135157
158+ var _ validationrule.Interface = (* IamUserRule )(nil )
159+
136160// Name returns the name of an IamUserRule.
137161func (r IamUserRule ) Name () string {
138162 return r .IamUserName
@@ -145,10 +169,14 @@ func (r IamUserRule) IAMPolicies() []PolicyDocument {
145169
146170// IamGroupRule compares the IAM permissions associated with an IAM group against an expected permission set.
147171type IamGroupRule struct {
172+ validationrule.AutomaticallyNamed `json:"-"`
173+
148174 IamGroupName string `json:"iamGroupName" yaml:"iamGroupName"`
149175 Policies []PolicyDocument `json:"iamPolicies" yaml:"iamPolicies"`
150176}
151177
178+ var _ validationrule.Interface = (* IamGroupRule )(nil )
179+
152180// Name returns the name of an IamGroupRule.
153181func (r IamGroupRule ) Name () string {
154182 return r .IamGroupName
@@ -161,10 +189,14 @@ func (r IamGroupRule) IAMPolicies() []PolicyDocument {
161189
162190// IamPolicyRule compares the IAM permissions associated with an IAM policy against an expected permission set.
163191type IamPolicyRule struct {
192+ validationrule.AutomaticallyNamed `json:"-"`
193+
164194 IamPolicyARN string `json:"iamPolicyArn" yaml:"iamPolicyArn"`
165195 Policies []PolicyDocument `json:"iamPolicies" yaml:"iamPolicies"`
166196}
167197
198+ var _ validationrule.Interface = (* IamPolicyRule )(nil )
199+
168200// Name returns the name of an IamPolicyRule.
169201func (r IamPolicyRule ) Name () string {
170202 return r .IamPolicyARN
@@ -208,12 +240,26 @@ func (c Condition) String() string {
208240
209241// ServiceQuotaRule ensures that AWS service quotas are within a particular threshold.
210242type ServiceQuotaRule struct {
211- Name string `json:"name" yaml:"name"`
243+ validationrule.ManuallyNamed `json:"-"`
244+
245+ RuleName string `json:"name" yaml:"name"`
212246 Region string `json:"region" yaml:"region"`
213247 ServiceCode string `json:"serviceCode" yaml:"serviceCode"`
214248 ServiceQuotas []ServiceQuota `json:"serviceQuotas" yaml:"serviceQuotas"`
215249}
216250
251+ var _ validationrule.Interface = (* ServiceQuotaRule )(nil )
252+
253+ // Name returns the name of the ServiceQuotaRule.
254+ func (r ServiceQuotaRule ) Name () string {
255+ return r .RuleName
256+ }
257+
258+ // SetName sets the name of the ServiceQuotaRule.
259+ func (r * ServiceQuotaRule ) SetName (name string ) {
260+ r .RuleName = name
261+ }
262+
217263// ServiceQuota defines an AWS service quota and an associated buffer.
218264type ServiceQuota struct {
219265 Name string `json:"name" yaml:"name"`
@@ -222,14 +268,28 @@ type ServiceQuota struct {
222268
223269// TagRule ensures that the tags associated with a particular AWS resource match an expected tag set.
224270type TagRule struct {
225- Name string `json:"name" yaml:"name"`
271+ validationrule.ManuallyNamed `json:"-"`
272+
273+ RuleName string `json:"name" yaml:"name"`
226274 Key string `json:"key" yaml:"key"`
227275 ExpectedValue string `json:"expectedValue" yaml:"expectedValue"`
228276 Region string `json:"region" yaml:"region"`
229277 ResourceType string `json:"resourceType" yaml:"resourceType"`
230278 ARNs []string `json:"arns" yaml:"arns"`
231279}
232280
281+ var _ validationrule.Interface = (* TagRule )(nil )
282+
283+ // Name returns the name of the ServiceQuotaRule.
284+ func (r TagRule ) Name () string {
285+ return r .RuleName
286+ }
287+
288+ // SetName sets the name of the ServiceQuotaRule.
289+ func (r * TagRule ) SetName (name string ) {
290+ r .RuleName = name
291+ }
292+
233293// AwsValidatorStatus defines the observed state of AwsValidator
234294type AwsValidatorStatus struct {}
235295
0 commit comments