refactor: NewDriftCTL interface

main
sundowndev 2021-04-09 13:15:16 +02:00
parent 53bfa79423
commit c6ea94f6ce
2 changed files with 29 additions and 19 deletions

View File

@ -7,7 +7,6 @@ import (
"strings"
"syscall"
"github.com/jmespath/go-jmespath"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -26,20 +25,8 @@ import (
"github.com/cloudskiff/driftctl/pkg/terraform"
)
type ScanOptions struct {
Coverage bool
Detect bool
From []config.SupplierConfig
To string
Output output.OutputConfig
Filter *jmespath.JMESPath
Quiet bool
BackendOptions *backend.Options
Strict bool
}
func NewScanCmd() *cobra.Command {
opts := &ScanOptions{}
opts := &pkg.ScanOptions{}
opts.BackendOptions = &backend.Options{}
cmd := &cobra.Command{
@ -138,7 +125,7 @@ func NewScanCmd() *cobra.Command {
"Use those HTTP headers to query the provided URL.\n"+
"Only used with tfstate+http(s) backend for now.\n",
)
fl.BoolVar(&opts.Strict,
fl.BoolVar(&opts.StrictMode,
"strict",
false,
"Includes cloud provider service-linked roles (disabled by default)",
@ -147,7 +134,7 @@ func NewScanCmd() *cobra.Command {
return cmd
}
func scanRun(opts *ScanOptions) error {
func scanRun(opts *pkg.ScanOptions) error {
selectedOutput := output.GetOutput(opts.Output, opts.Quiet)
c := make(chan os.Signal)
@ -180,7 +167,7 @@ func scanRun(opts *ScanOptions) error {
resFactory := terraform.NewTerraformResourceFactory(providerLibrary)
ctl := pkg.NewDriftCTL(scanner, iacSupplier, opts.Filter, alerter, resFactory, opts.Strict)
ctl := pkg.NewDriftCTL(scanner, iacSupplier, alerter, resFactory, opts)
go func() {
<-c

View File

@ -9,11 +9,26 @@ import (
"github.com/cloudskiff/driftctl/pkg/alerter"
"github.com/cloudskiff/driftctl/pkg/analyser"
"github.com/cloudskiff/driftctl/pkg/cmd/scan/output"
"github.com/cloudskiff/driftctl/pkg/filter"
"github.com/cloudskiff/driftctl/pkg/iac/config"
"github.com/cloudskiff/driftctl/pkg/iac/terraform/state/backend"
"github.com/cloudskiff/driftctl/pkg/middlewares"
"github.com/cloudskiff/driftctl/pkg/resource"
)
type ScanOptions struct {
Coverage bool
Detect bool
From []config.SupplierConfig
To string
Output output.OutputConfig
Filter *jmespath.JMESPath
Quiet bool
BackendOptions *backend.Options
StrictMode bool
}
type DriftCTL struct {
remoteSupplier resource.Supplier
iacSupplier resource.Supplier
@ -24,8 +39,16 @@ type DriftCTL struct {
strictMode bool
}
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 NewDriftCTL(remoteSupplier resource.Supplier, iacSupplier resource.Supplier, alerter *alerter.Alerter, resFactory resource.ResourceFactory, opts *ScanOptions) *DriftCTL {
return &DriftCTL{
remoteSupplier,
iacSupplier,
alerter,
analyser.NewAnalyzer(alerter),
opts.Filter,
resFactory,
opts.StrictMode,
}
}
func (d DriftCTL) Run() (*analyser.Analysis, error) {