github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_guardduty_ipset_invalid_format.go (about)

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