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