github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_guardduty_ipset_invalid_format.go (about) 1 // This file generated by `generator/`. DO NOT EDIT 2 3 package models 4 5 import ( 6 "fmt" 7 "log" 8 9 hcl "github.com/hashicorp/hcl/v2" 10 "github.com/terraform-linters/tflint/tflint" 11 ) 12 13 // AwsGuarddutyIpsetInvalidFormatRule checks the pattern is valid 14 type AwsGuarddutyIpsetInvalidFormatRule struct { 15 resourceType string 16 attributeName string 17 max int 18 min int 19 enum []string 20 } 21 22 // NewAwsGuarddutyIpsetInvalidFormatRule returns new rule with default attributes 23 func NewAwsGuarddutyIpsetInvalidFormatRule() *AwsGuarddutyIpsetInvalidFormatRule { 24 return &AwsGuarddutyIpsetInvalidFormatRule{ 25 resourceType: "aws_guardduty_ipset", 26 attributeName: "format", 27 max: 300, 28 min: 1, 29 enum: []string{ 30 "TXT", 31 "STIX", 32 "OTX_CSV", 33 "ALIEN_VAULT", 34 "PROOF_POINT", 35 "FIRE_EYE", 36 }, 37 } 38 } 39 40 // Name returns the rule name 41 func (r *AwsGuarddutyIpsetInvalidFormatRule) Name() string { 42 return "aws_guardduty_ipset_invalid_format" 43 } 44 45 // Enabled returns whether the rule is enabled by default 46 func (r *AwsGuarddutyIpsetInvalidFormatRule) Enabled() bool { 47 return true 48 } 49 50 // Severity returns the rule severity 51 func (r *AwsGuarddutyIpsetInvalidFormatRule) Severity() string { 52 return tflint.ERROR 53 } 54 55 // Link returns the rule reference link 56 func (r *AwsGuarddutyIpsetInvalidFormatRule) Link() string { 57 return "" 58 } 59 60 // Check checks the pattern is valid 61 func (r *AwsGuarddutyIpsetInvalidFormatRule) Check(runner *tflint.Runner) error { 62 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 63 64 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 65 var val string 66 err := runner.EvaluateExpr(attribute.Expr, &val) 67 68 return runner.EnsureNoError(err, func() error { 69 if len(val) > r.max { 70 runner.EmitIssue( 71 r, 72 "format must be 300 characters or less", 73 attribute.Expr.Range(), 74 ) 75 } 76 if len(val) < r.min { 77 runner.EmitIssue( 78 r, 79 "format must be 1 characters or higher", 80 attribute.Expr.Range(), 81 ) 82 } 83 found := false 84 for _, item := range r.enum { 85 if item == val { 86 found = true 87 } 88 } 89 if !found { 90 runner.EmitIssue( 91 r, 92 fmt.Sprintf(`"%s" is an invalid value as format`, truncateLongMessage(val)), 93 attribute.Expr.Range(), 94 ) 95 } 96 return nil 97 }) 98 }) 99 }