refactor: usage of strict mode

main
sundowndev 2021-03-29 19:01:35 +02:00
parent 54018e6b52
commit eb10e9cd69
2 changed files with 11 additions and 5 deletions

View File

@ -180,7 +180,7 @@ func scanRun(opts *ScanOptions) error {
resFactory := terraform.NewTerraformResourceFactory(providerLibrary)
ctl := pkg.NewDriftCTL(scanner, iacSupplier, opts.Filter, alerter, resFactory)
ctl := pkg.NewDriftCTL(scanner, iacSupplier, opts.Filter, alerter, resFactory, opts.Strict)
go func() {
<-c

View File

@ -21,10 +21,11 @@ type DriftCTL struct {
analyzer analyser.Analyzer
filter *jmespath.JMESPath
resourceFactory resource.ResourceFactory
strictMode bool
}
func NewDriftCTL(remoteSupplier resource.Supplier, iacSupplier resource.Supplier, filter *jmespath.JMESPath, alerter *alerter.Alerter, resFactory resource.ResourceFactory) *DriftCTL {
return &DriftCTL{remoteSupplier, iacSupplier, alerter, analyser.NewAnalyzer(alerter), filter, resFactory}
func NewDriftCTL(remoteSupplier resource.Supplier, iacSupplier resource.Supplier, filter *jmespath.JMESPath, alerter *alerter.Alerter, resFactory resource.ResourceFactory, strictMode bool) *DriftCTL {
return &DriftCTL{remoteSupplier, iacSupplier, alerter, analyser.NewAnalyzer(alerter), filter, resFactory, strictMode}
}
func (d DriftCTL) Run() (*analyser.Analysis, error) {
@ -53,10 +54,15 @@ func (d DriftCTL) Run() (*analyser.Analysis, error) {
middlewares.NewAwsSqsQueuePolicyExpander(d.resourceFactory),
middlewares.NewAwsDefaultSqsQueuePolicy(),
middlewares.NewAwsSNSTopicPolicyExpander(d.resourceFactory),
middlewares.NewAwsIamRolePolicyDefaults(),
middlewares.NewAwsIamRoleDefaults(),
)
if !d.strictMode {
middleware = append(middleware,
middlewares.NewAwsIamRolePolicyDefaults(),
middlewares.NewAwsIamRoleDefaults(),
)
}
logrus.Debug("Ready to run middlewares")
err = middleware.Execute(&remoteResources, &resourcesFromState)
if err != nil {