github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_api_gateway_integration_response_invalid_status_code.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  	"regexp"
     8  
     9  	hcl "github.com/hashicorp/hcl/v2"
    10  	"github.com/wata727/tflint/tflint"
    11  )
    12  
    13  // AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule checks the pattern is valid
    14  type AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule struct {
    15  	resourceType  string
    16  	attributeName string
    17  	pattern       *regexp.Regexp
    18  }
    19  
    20  // NewAwsAPIGatewayIntegrationResponseInvalidStatusCodeRule returns new rule with default attributes
    21  func NewAwsAPIGatewayIntegrationResponseInvalidStatusCodeRule() *AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule {
    22  	return &AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule{
    23  		resourceType:  "aws_api_gateway_integration_response",
    24  		attributeName: "status_code",
    25  		pattern:       regexp.MustCompile(`^[1-5]\d\d$`),
    26  	}
    27  }
    28  
    29  // Name returns the rule name
    30  func (r *AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule) Name() string {
    31  	return "aws_api_gateway_integration_response_invalid_status_code"
    32  }
    33  
    34  // Enabled returns whether the rule is enabled by default
    35  func (r *AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule) Enabled() bool {
    36  	return true
    37  }
    38  
    39  // Severity returns the rule severity
    40  func (r *AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule) Severity() string {
    41  	return tflint.ERROR
    42  }
    43  
    44  // Link returns the rule reference link
    45  func (r *AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule) Link() string {
    46  	return ""
    47  }
    48  
    49  // Check checks the pattern is valid
    50  func (r *AwsAPIGatewayIntegrationResponseInvalidStatusCodeRule) Check(runner *tflint.Runner) error {
    51  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    52  
    53  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    54  		var val string
    55  		err := runner.EvaluateExpr(attribute.Expr, &val)
    56  
    57  		return runner.EnsureNoError(err, func() error {
    58  			if !r.pattern.MatchString(val) {
    59  				runner.EmitIssue(
    60  					r,
    61  					`status_code does not match valid pattern ^[1-5]\d\d$`,
    62  					attribute.Expr.Range(),
    63  				)
    64  			}
    65  			return nil
    66  		})
    67  	})
    68  }