github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_acm_certificate_invalid_certificate_body.go (about) 1 // This file generated by `generator/`. DO NOT EDIT 2 3 package models 4 5 import ( 6 "fmt" 7 "log" 8 "regexp" 9 10 hcl "github.com/hashicorp/hcl/v2" 11 "github.com/terraform-linters/tflint/tflint" 12 ) 13 14 // AwsAcmCertificateInvalidCertificateBodyRule checks the pattern is valid 15 type AwsAcmCertificateInvalidCertificateBodyRule struct { 16 resourceType string 17 attributeName string 18 max int 19 min int 20 pattern *regexp.Regexp 21 } 22 23 // NewAwsAcmCertificateInvalidCertificateBodyRule returns new rule with default attributes 24 func NewAwsAcmCertificateInvalidCertificateBodyRule() *AwsAcmCertificateInvalidCertificateBodyRule { 25 return &AwsAcmCertificateInvalidCertificateBodyRule{ 26 resourceType: "aws_acm_certificate", 27 attributeName: "certificate_body", 28 max: 32768, 29 min: 1, 30 pattern: regexp.MustCompile(`^-{5}BEGIN CERTIFICATE-{5}\x{000D}?\x{000A}([A-Za-z0-9/+]{64}\x{000D}?\x{000A})*[A-Za-z0-9/+]{1,64}={0,2}\x{000D}?\x{000A}-{5}END CERTIFICATE-{5}(\x{000D}?\x{000A})?$`), 31 } 32 } 33 34 // Name returns the rule name 35 func (r *AwsAcmCertificateInvalidCertificateBodyRule) Name() string { 36 return "aws_acm_certificate_invalid_certificate_body" 37 } 38 39 // Enabled returns whether the rule is enabled by default 40 func (r *AwsAcmCertificateInvalidCertificateBodyRule) Enabled() bool { 41 return true 42 } 43 44 // Severity returns the rule severity 45 func (r *AwsAcmCertificateInvalidCertificateBodyRule) Severity() string { 46 return tflint.ERROR 47 } 48 49 // Link returns the rule reference link 50 func (r *AwsAcmCertificateInvalidCertificateBodyRule) Link() string { 51 return "" 52 } 53 54 // Check checks the pattern is valid 55 func (r *AwsAcmCertificateInvalidCertificateBodyRule) Check(runner *tflint.Runner) error { 56 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 57 58 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 59 var val string 60 err := runner.EvaluateExpr(attribute.Expr, &val) 61 62 return runner.EnsureNoError(err, func() error { 63 if len(val) > r.max { 64 runner.EmitIssue( 65 r, 66 "certificate_body must be 32768 characters or less", 67 attribute.Expr.Range(), 68 ) 69 } 70 if len(val) < r.min { 71 runner.EmitIssue( 72 r, 73 "certificate_body must be 1 characters or higher", 74 attribute.Expr.Range(), 75 ) 76 } 77 if !r.pattern.MatchString(val) { 78 runner.EmitIssue( 79 r, 80 fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^-{5}BEGIN CERTIFICATE-{5}\x{000D}?\x{000A}([A-Za-z0-9/+]{64}\x{000D}?\x{000A})*[A-Za-z0-9/+]{1,64}={0,2}\x{000D}?\x{000A}-{5}END CERTIFICATE-{5}(\x{000D}?\x{000A})?$`), 81 attribute.Expr.Range(), 82 ) 83 } 84 return nil 85 }) 86 }) 87 }