-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve ineffecient module detector method #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,15 @@ import ( | |
"github.com/wata727/tflint/issue" | ||
) | ||
|
||
func (d *Detector) DetectAwsDbInstanceDefaultParameterGroup(issues *[]*issue.Issue) { | ||
type AwsDBInstanceDefaultParameterGroupDetector struct { | ||
*Detector | ||
} | ||
|
||
func (d *Detector) CreateAwsDBInstanceDefaultParameterGroupDetector() *AwsDBInstanceDefaultParameterGroupDetector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
return &AwsDBInstanceDefaultParameterGroupDetector{d} | ||
} | ||
|
||
func (d *AwsDBInstanceDefaultParameterGroupDetector) Detect(issues *[]*issue.Issue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
for filename, list := range d.ListMap { | ||
for _, item := range list.Filter("resource", "aws_db_instance").Items { | ||
parameterGroupToken, err := hclLiteralToken(item, "parameter_group_name") | ||
|
@@ -21,7 +29,7 @@ func (d *Detector) DetectAwsDbInstanceDefaultParameterGroup(issues *[]*issue.Iss | |
continue | ||
} | ||
|
||
if isDefaultDbParameterGroup(parameterGroup) { | ||
if d.isDefaultDbParameterGroup(parameterGroup) { | ||
issue := &issue.Issue{ | ||
Type: "NOTICE", | ||
Message: fmt.Sprintf("\"%s\" is default parameter group. You cannot edit it.", parameterGroup), | ||
|
@@ -34,6 +42,6 @@ func (d *Detector) DetectAwsDbInstanceDefaultParameterGroup(issues *[]*issue.Iss | |
} | ||
} | ||
|
||
func isDefaultDbParameterGroup(s string) bool { | ||
func (d *AwsDBInstanceDefaultParameterGroupDetector) isDefaultDbParameterGroup(s string) bool { | ||
return regexp.MustCompile("^default").Match([]byte(s)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,15 @@ import ( | |
"github.com/wata727/tflint/issue" | ||
) | ||
|
||
func (d *Detector) DetectAwsElasticacheClusterDefaultParameterGroup(issues *[]*issue.Issue) { | ||
type AwsElastiCacheClusterDefaultParameterGroupDetector struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
*Detector | ||
} | ||
|
||
func (d *Detector) CreateAwsElastiCacheClusterDefaultParameterGroupDetector() *AwsElastiCacheClusterDefaultParameterGroupDetector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
return &AwsElastiCacheClusterDefaultParameterGroupDetector{d} | ||
} | ||
|
||
func (d *AwsElastiCacheClusterDefaultParameterGroupDetector) Detect(issues *[]*issue.Issue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
for filename, list := range d.ListMap { | ||
for _, item := range list.Filter("resource", "aws_elasticache_cluster").Items { | ||
parameterGroupToken, err := hclLiteralToken(item, "parameter_group_name") | ||
|
@@ -21,7 +29,7 @@ func (d *Detector) DetectAwsElasticacheClusterDefaultParameterGroup(issues *[]*i | |
continue | ||
} | ||
|
||
if isDefaultCacheParameterGroup(parameterGroup) { | ||
if d.isDefaultCacheParameterGroup(parameterGroup) { | ||
issue := &issue.Issue{ | ||
Type: "NOTICE", | ||
Message: fmt.Sprintf("\"%s\" is default parameter group. You cannot edit it.", parameterGroup), | ||
|
@@ -34,6 +42,6 @@ func (d *Detector) DetectAwsElasticacheClusterDefaultParameterGroup(issues *[]*i | |
} | ||
} | ||
|
||
func isDefaultCacheParameterGroup(s string) bool { | ||
func (d *AwsElastiCacheClusterDefaultParameterGroupDetector) isDefaultCacheParameterGroup(s string) bool { | ||
return regexp.MustCompile("^default").Match([]byte(s)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,15 @@ import ( | |
"github.com/wata727/tflint/issue" | ||
) | ||
|
||
func (d *Detector) DetectAwsInstanceDefaultStandardVolume(issues *[]*issue.Issue) { | ||
type AwsInstanceDefaultStandardVolumeDetector struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
*Detector | ||
} | ||
|
||
func (d *Detector) CreateAwsInstanceDefaultStandardVolumeDetector() *AwsInstanceDefaultStandardVolumeDetector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
return &AwsInstanceDefaultStandardVolumeDetector{d} | ||
} | ||
|
||
func (d *AwsInstanceDefaultStandardVolumeDetector) Detect(issues *[]*issue.Issue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
for filename, list := range d.ListMap { | ||
for _, item := range list.Filter("resource", "aws_instance").Items { | ||
d.detectForBlockDevices(issues, item, filename, "root_block_device") | ||
|
@@ -14,7 +22,7 @@ func (d *Detector) DetectAwsInstanceDefaultStandardVolume(issues *[]*issue.Issue | |
} | ||
} | ||
|
||
func (d *Detector) detectForBlockDevices(issues *[]*issue.Issue, item *ast.ObjectItem, filename string, device string) { | ||
func (d *AwsInstanceDefaultStandardVolumeDetector) detectForBlockDevices(issues *[]*issue.Issue, item *ast.ObjectItem, filename string, device string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
if !IsKeyNotFound(item, device) { | ||
deviceItems, err := hclObjectItems(item, device) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,30 @@ import ( | |
"github.com/wata727/tflint/issue" | ||
) | ||
|
||
func (d *Detector) DetectAwsInstanceInvalidAmi(issues *[]*issue.Issue) { | ||
type AwsInstanceInvalidAMIDetector struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
*Detector | ||
} | ||
|
||
func (d *Detector) CreateAwsInstanceInvalidAMIDetector() *AwsInstanceInvalidAMIDetector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
return &AwsInstanceInvalidAMIDetector{d} | ||
} | ||
|
||
func (d *AwsInstanceInvalidAMIDetector) Detect(issues *[]*issue.Issue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
if !d.Config.DeepCheck { | ||
d.Logger.Info("skip this rule.") | ||
return | ||
} | ||
|
||
validAmi := map[string]bool{} | ||
resp, err := d.AwsClient.Ec2.DescribeImages(&ec2.DescribeImagesInput{}) | ||
if err != nil { | ||
d.Logger.Error(err) | ||
d.Error = true | ||
if d.ResponseCache.DescribeImagesOutput == nil { | ||
resp, err := d.AwsClient.Ec2.DescribeImages(&ec2.DescribeImagesInput{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
if err != nil { | ||
d.Logger.Error(err) | ||
d.Error = true | ||
} | ||
d.ResponseCache.DescribeImagesOutput = resp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
} | ||
for _, image := range resp.Images { | ||
for _, image := range d.ResponseCache.DescribeImagesOutput.Images { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
validAmi[*image.ImageId] = true | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,30 @@ import ( | |
"github.com/wata727/tflint/issue" | ||
) | ||
|
||
func (d *Detector) DetectAwsInstanceInvalidIamProfile(issues *[]*issue.Issue) { | ||
type AwsInstanceInvalidIAMProfileDetector struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
*Detector | ||
} | ||
|
||
func (d *Detector) CreateAwsInstanceInvalidIAMProfileDetector() *AwsInstanceInvalidIAMProfileDetector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
return &AwsInstanceInvalidIAMProfileDetector{d} | ||
} | ||
|
||
func (d *AwsInstanceInvalidIAMProfileDetector) Detect(issues *[]*issue.Issue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
if !d.Config.DeepCheck { | ||
d.Logger.Info("skip this rule.") | ||
return | ||
} | ||
|
||
validIamProfiles := map[string]bool{} | ||
resp, err := d.AwsClient.Iam.ListInstanceProfiles(&iam.ListInstanceProfilesInput{}) | ||
if err != nil { | ||
d.Logger.Error(err) | ||
d.Error = true | ||
if d.ResponseCache.ListInstanceProfilesOutput == nil { | ||
resp, err := d.AwsClient.Iam.ListInstanceProfiles(&iam.ListInstanceProfilesInput{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
if err != nil { | ||
d.Logger.Error(err) | ||
d.Error = true | ||
} | ||
d.ResponseCache.ListInstanceProfilesOutput = resp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
} | ||
for _, iamProfile := range resp.InstanceProfiles { | ||
for _, iamProfile := range d.ResponseCache.ListInstanceProfilesOutput.InstanceProfiles { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [gometalinter]
|
||
validIamProfiles[*iamProfile.InstanceProfileName] = true | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[gometalinter]