From 3c993c063c9aeb8e0d037e021860be5b4b9ebe58 Mon Sep 17 00:00:00 2001 From: William Beuil Date: Mon, 5 Jul 2021 10:30:42 +0200 Subject: [PATCH] Fix enumerators --- pkg/remote/aws/ec2_ami_enumerator.go | 13 +++---- pkg/remote/aws/ec2_ebs_snapshot_enumerator.go | 13 +++---- pkg/remote/aws/ec2_ebs_volume_enumerator.go | 13 +++---- .../aws/ec2_eip_association_enumerator.go | 13 +++---- pkg/remote/aws/ec2_eip_enumerator.go | 13 +++---- pkg/remote/aws/ec2_instance_enumerator.go | 13 +++---- pkg/remote/aws/ec2_key_pair_enumerator.go | 13 +++---- pkg/remote/aws/init.go | 14 ++++---- pkg/remote/ec2_scanner_test.go | 36 ++++--------------- 9 files changed, 49 insertions(+), 92 deletions(-) diff --git a/pkg/remote/aws/ec2_ami_enumerator.go b/pkg/remote/aws/ec2_ami_enumerator.go index c2a9ad91..47408f9b 100644 --- a/pkg/remote/aws/ec2_ami_enumerator.go +++ b/pkg/remote/aws/ec2_ami_enumerator.go @@ -3,22 +3,19 @@ package aws import ( "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" - tf "github.com/cloudskiff/driftctl/pkg/remote/terraform" "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" ) type EC2AmiEnumerator struct { - repository repository.EC2Repository - factory resource.ResourceFactory - providerConfig tf.TerraformProviderConfig + repository repository.EC2Repository + factory resource.ResourceFactory } -func NewEC2AmiEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory, providerConfig tf.TerraformProviderConfig) *EC2AmiEnumerator { +func NewEC2AmiEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2AmiEnumerator { return &EC2AmiEnumerator{ - repository: repo, - factory: factory, - providerConfig: providerConfig, + repository: repo, + factory: factory, } } diff --git a/pkg/remote/aws/ec2_ebs_snapshot_enumerator.go b/pkg/remote/aws/ec2_ebs_snapshot_enumerator.go index 86fb0a93..dc9b9143 100644 --- a/pkg/remote/aws/ec2_ebs_snapshot_enumerator.go +++ b/pkg/remote/aws/ec2_ebs_snapshot_enumerator.go @@ -3,22 +3,19 @@ package aws import ( "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" - tf "github.com/cloudskiff/driftctl/pkg/remote/terraform" "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" ) type EC2EbsSnapshotEnumerator struct { - repository repository.EC2Repository - factory resource.ResourceFactory - providerConfig tf.TerraformProviderConfig + repository repository.EC2Repository + factory resource.ResourceFactory } -func NewEC2EbsSnapshotEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory, providerConfig tf.TerraformProviderConfig) *EC2EbsSnapshotEnumerator { +func NewEC2EbsSnapshotEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2EbsSnapshotEnumerator { return &EC2EbsSnapshotEnumerator{ - repository: repo, - factory: factory, - providerConfig: providerConfig, + repository: repo, + factory: factory, } } diff --git a/pkg/remote/aws/ec2_ebs_volume_enumerator.go b/pkg/remote/aws/ec2_ebs_volume_enumerator.go index 509733ad..285c07c0 100644 --- a/pkg/remote/aws/ec2_ebs_volume_enumerator.go +++ b/pkg/remote/aws/ec2_ebs_volume_enumerator.go @@ -3,22 +3,19 @@ package aws import ( "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" - tf "github.com/cloudskiff/driftctl/pkg/remote/terraform" "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" ) type EC2EbsVolumeEnumerator struct { - repository repository.EC2Repository - factory resource.ResourceFactory - providerConfig tf.TerraformProviderConfig + repository repository.EC2Repository + factory resource.ResourceFactory } -func NewEC2EbsVolumeEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory, providerConfig tf.TerraformProviderConfig) *EC2EbsVolumeEnumerator { +func NewEC2EbsVolumeEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2EbsVolumeEnumerator { return &EC2EbsVolumeEnumerator{ - repository: repo, - factory: factory, - providerConfig: providerConfig, + repository: repo, + factory: factory, } } diff --git a/pkg/remote/aws/ec2_eip_association_enumerator.go b/pkg/remote/aws/ec2_eip_association_enumerator.go index 41487da6..6d1beeeb 100644 --- a/pkg/remote/aws/ec2_eip_association_enumerator.go +++ b/pkg/remote/aws/ec2_eip_association_enumerator.go @@ -3,22 +3,19 @@ package aws import ( "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" - tf "github.com/cloudskiff/driftctl/pkg/remote/terraform" "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" ) type EC2EipAssociationEnumerator struct { - repository repository.EC2Repository - factory resource.ResourceFactory - providerConfig tf.TerraformProviderConfig + repository repository.EC2Repository + factory resource.ResourceFactory } -func NewEC2EipAssociationEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory, providerConfig tf.TerraformProviderConfig) *EC2EipAssociationEnumerator { +func NewEC2EipAssociationEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2EipAssociationEnumerator { return &EC2EipAssociationEnumerator{ - repository: repo, - factory: factory, - providerConfig: providerConfig, + repository: repo, + factory: factory, } } diff --git a/pkg/remote/aws/ec2_eip_enumerator.go b/pkg/remote/aws/ec2_eip_enumerator.go index 7bc3487f..7ff25ede 100644 --- a/pkg/remote/aws/ec2_eip_enumerator.go +++ b/pkg/remote/aws/ec2_eip_enumerator.go @@ -3,22 +3,19 @@ package aws import ( "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" - tf "github.com/cloudskiff/driftctl/pkg/remote/terraform" "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" ) type EC2EipEnumerator struct { - repository repository.EC2Repository - factory resource.ResourceFactory - providerConfig tf.TerraformProviderConfig + repository repository.EC2Repository + factory resource.ResourceFactory } -func NewEC2EipEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory, providerConfig tf.TerraformProviderConfig) *EC2EipEnumerator { +func NewEC2EipEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2EipEnumerator { return &EC2EipEnumerator{ - repository: repo, - factory: factory, - providerConfig: providerConfig, + repository: repo, + factory: factory, } } diff --git a/pkg/remote/aws/ec2_instance_enumerator.go b/pkg/remote/aws/ec2_instance_enumerator.go index eb1b3d76..188d541b 100644 --- a/pkg/remote/aws/ec2_instance_enumerator.go +++ b/pkg/remote/aws/ec2_instance_enumerator.go @@ -3,22 +3,19 @@ package aws import ( "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" - tf "github.com/cloudskiff/driftctl/pkg/remote/terraform" "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" ) type EC2InstanceEnumerator struct { - repository repository.EC2Repository - factory resource.ResourceFactory - providerConfig tf.TerraformProviderConfig + repository repository.EC2Repository + factory resource.ResourceFactory } -func NewEC2InstanceEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory, providerConfig tf.TerraformProviderConfig) *EC2InstanceEnumerator { +func NewEC2InstanceEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2InstanceEnumerator { return &EC2InstanceEnumerator{ - repository: repo, - factory: factory, - providerConfig: providerConfig, + repository: repo, + factory: factory, } } diff --git a/pkg/remote/aws/ec2_key_pair_enumerator.go b/pkg/remote/aws/ec2_key_pair_enumerator.go index 63585e9e..8bd3acab 100644 --- a/pkg/remote/aws/ec2_key_pair_enumerator.go +++ b/pkg/remote/aws/ec2_key_pair_enumerator.go @@ -3,22 +3,19 @@ package aws import ( "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" - tf "github.com/cloudskiff/driftctl/pkg/remote/terraform" "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" ) type EC2KeyPairEnumerator struct { - repository repository.EC2Repository - factory resource.ResourceFactory - providerConfig tf.TerraformProviderConfig + repository repository.EC2Repository + factory resource.ResourceFactory } -func NewEC2KeyPairEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory, providerConfig tf.TerraformProviderConfig) *EC2KeyPairEnumerator { +func NewEC2KeyPairEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2KeyPairEnumerator { return &EC2KeyPairEnumerator{ - repository: repo, - factory: factory, - providerConfig: providerConfig, + repository: repo, + factory: factory, } } diff --git a/pkg/remote/aws/init.go b/pkg/remote/aws/init.go index 7dcb99f5..8fd6c3b9 100644 --- a/pkg/remote/aws/init.go +++ b/pkg/remote/aws/init.go @@ -67,19 +67,19 @@ func Init(version string, alerter *alerter.Alerter, remoteLibrary.AddEnumerator(NewS3BucketMetricsEnumerator(s3Repository, factory, provider.Config)) remoteLibrary.AddDetailsFetcher(aws.AwsS3BucketMetricResourceType, NewS3BucketMetricsDetailsFetcher(provider, deserializer)) - remoteLibrary.AddEnumerator(NewEC2EbsVolumeEnumerator(ec2repository, factory, provider.Config)) + remoteLibrary.AddEnumerator(NewEC2EbsVolumeEnumerator(ec2repository, factory)) remoteLibrary.AddDetailsFetcher(aws.AwsEbsVolumeResourceType, common.NewGenericDetailsFetcher(aws.AwsEbsVolumeResourceType, provider, deserializer)) - remoteLibrary.AddEnumerator(NewEC2EbsSnapshotEnumerator(ec2repository, factory, provider.Config)) + remoteLibrary.AddEnumerator(NewEC2EbsSnapshotEnumerator(ec2repository, factory)) remoteLibrary.AddDetailsFetcher(aws.AwsEbsSnapshotResourceType, common.NewGenericDetailsFetcher(aws.AwsEbsSnapshotResourceType, provider, deserializer)) - remoteLibrary.AddEnumerator(NewEC2EipEnumerator(ec2repository, factory, provider.Config)) + remoteLibrary.AddEnumerator(NewEC2EipEnumerator(ec2repository, factory)) remoteLibrary.AddDetailsFetcher(aws.AwsEipResourceType, common.NewGenericDetailsFetcher(aws.AwsEipResourceType, provider, deserializer)) - remoteLibrary.AddEnumerator(NewEC2AmiEnumerator(ec2repository, factory, provider.Config)) + remoteLibrary.AddEnumerator(NewEC2AmiEnumerator(ec2repository, factory)) remoteLibrary.AddDetailsFetcher(aws.AwsAmiResourceType, common.NewGenericDetailsFetcher(aws.AwsAmiResourceType, provider, deserializer)) - remoteLibrary.AddEnumerator(NewEC2KeyPairEnumerator(ec2repository, factory, provider.Config)) + remoteLibrary.AddEnumerator(NewEC2KeyPairEnumerator(ec2repository, factory)) remoteLibrary.AddDetailsFetcher(aws.AwsKeyPairResourceType, common.NewGenericDetailsFetcher(aws.AwsKeyPairResourceType, provider, deserializer)) - remoteLibrary.AddEnumerator(NewEC2EipAssociationEnumerator(ec2repository, factory, provider.Config)) + remoteLibrary.AddEnumerator(NewEC2EipAssociationEnumerator(ec2repository, factory)) remoteLibrary.AddDetailsFetcher(aws.AwsEipAssociationResourceType, common.NewGenericDetailsFetcher(aws.AwsEipAssociationResourceType, provider, deserializer)) - remoteLibrary.AddEnumerator(NewEC2InstanceEnumerator(ec2repository, factory, provider.Config)) + remoteLibrary.AddEnumerator(NewEC2InstanceEnumerator(ec2repository, factory)) remoteLibrary.AddDetailsFetcher(aws.AwsInstanceResourceType, NewEC2InstanceDetailsFetcher(provider, deserializer)) supplierLibrary.AddSupplier(NewS3BucketAnalyticSupplier(provider, s3Repository, deserializer)) diff --git a/pkg/remote/ec2_scanner_test.go b/pkg/remote/ec2_scanner_test.go index 01c4a7ca..5b5f9271 100644 --- a/pkg/remote/ec2_scanner_test.go +++ b/pkg/remote/ec2_scanner_test.go @@ -13,7 +13,6 @@ import ( "github.com/cloudskiff/driftctl/pkg/remote/cache" "github.com/cloudskiff/driftctl/pkg/remote/common" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" - tf "github.com/cloudskiff/driftctl/pkg/remote/terraform" "github.com/cloudskiff/driftctl/pkg/resource" resourceaws "github.com/cloudskiff/driftctl/pkg/resource/aws" "github.com/cloudskiff/driftctl/pkg/terraform" @@ -98,10 +97,7 @@ func TestEC2EbsVolume(t *testing.T) { repo = repository.NewEC2Repository(sess, cache.New(0)) } - remoteLibrary.AddEnumerator(aws.NewEC2EbsVolumeEnumerator(repo, factory, tf.TerraformProviderConfig{ - Name: "test", - DefaultAlias: "eu-west-3", - })) + remoteLibrary.AddEnumerator(aws.NewEC2EbsVolumeEnumerator(repo, factory)) remoteLibrary.AddDetailsFetcher(resourceaws.AwsEbsVolumeResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsEbsVolumeResourceType, provider, deserializer)) s := NewScanner(nil, remoteLibrary, alerter, scanOptions) @@ -189,10 +185,7 @@ func TestEC2EbsSnapshot(t *testing.T) { repo = repository.NewEC2Repository(sess, cache.New(0)) } - remoteLibrary.AddEnumerator(aws.NewEC2EbsSnapshotEnumerator(repo, factory, tf.TerraformProviderConfig{ - Name: "test", - DefaultAlias: "eu-west-3", - })) + remoteLibrary.AddEnumerator(aws.NewEC2EbsSnapshotEnumerator(repo, factory)) remoteLibrary.AddDetailsFetcher(resourceaws.AwsEbsSnapshotResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsEbsSnapshotResourceType, provider, deserializer)) s := NewScanner(nil, remoteLibrary, alerter, scanOptions) @@ -280,10 +273,7 @@ func TestEC2Eip(t *testing.T) { repo = repository.NewEC2Repository(sess, cache.New(0)) } - remoteLibrary.AddEnumerator(aws.NewEC2EipEnumerator(repo, factory, tf.TerraformProviderConfig{ - Name: "test", - DefaultAlias: "eu-west-3", - })) + remoteLibrary.AddEnumerator(aws.NewEC2EipEnumerator(repo, factory)) remoteLibrary.AddDetailsFetcher(resourceaws.AwsEipResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsEipResourceType, provider, deserializer)) s := NewScanner(nil, remoteLibrary, alerter, scanOptions) @@ -371,10 +361,7 @@ func TestEC2Ami(t *testing.T) { repo = repository.NewEC2Repository(sess, cache.New(0)) } - remoteLibrary.AddEnumerator(aws.NewEC2AmiEnumerator(repo, factory, tf.TerraformProviderConfig{ - Name: "test", - DefaultAlias: "eu-west-3", - })) + remoteLibrary.AddEnumerator(aws.NewEC2AmiEnumerator(repo, factory)) remoteLibrary.AddDetailsFetcher(resourceaws.AwsAmiResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsAmiResourceType, provider, deserializer)) s := NewScanner(nil, remoteLibrary, alerter, scanOptions) @@ -462,10 +449,7 @@ func TestEC2KeyPair(t *testing.T) { repo = repository.NewEC2Repository(sess, cache.New(0)) } - remoteLibrary.AddEnumerator(aws.NewEC2KeyPairEnumerator(repo, factory, tf.TerraformProviderConfig{ - Name: "test", - DefaultAlias: "eu-west-3", - })) + remoteLibrary.AddEnumerator(aws.NewEC2KeyPairEnumerator(repo, factory)) remoteLibrary.AddDetailsFetcher(resourceaws.AwsKeyPairResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsKeyPairResourceType, provider, deserializer)) s := NewScanner(nil, remoteLibrary, alerter, scanOptions) @@ -552,10 +536,7 @@ func TestEC2EipAssociation(t *testing.T) { repo = repository.NewEC2Repository(sess, cache.New(0)) } - remoteLibrary.AddEnumerator(aws.NewEC2EipAssociationEnumerator(repo, factory, tf.TerraformProviderConfig{ - Name: "test", - DefaultAlias: "eu-west-3", - })) + remoteLibrary.AddEnumerator(aws.NewEC2EipAssociationEnumerator(repo, factory)) remoteLibrary.AddDetailsFetcher(resourceaws.AwsEipAssociationResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsEipAssociationResourceType, provider, deserializer)) s := NewScanner(nil, remoteLibrary, alerter, scanOptions) @@ -653,10 +634,7 @@ func TestEC2Instance(t *testing.T) { repo = repository.NewEC2Repository(sess, cache.New(0)) } - remoteLibrary.AddEnumerator(aws.NewEC2InstanceEnumerator(repo, factory, tf.TerraformProviderConfig{ - Name: "test", - DefaultAlias: "eu-west-3", - })) + remoteLibrary.AddEnumerator(aws.NewEC2InstanceEnumerator(repo, factory)) remoteLibrary.AddDetailsFetcher(resourceaws.AwsInstanceResourceType, aws.NewEC2InstanceDetailsFetcher(provider, deserializer)) s := NewScanner(nil, remoteLibrary, alerter, scanOptions)