Merge pull request #822 from cloudskiff/change_Sqs_to_SQS

Change Sqs to SQS typo (except resourceType)
main
William BEUIL 2021-07-08 17:25:11 +02:00 committed by GitHub
commit 97af9a43b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 28 deletions

View File

@ -95,8 +95,8 @@ func (d DriftCTL) Run() (*analyser.Analysis, error) {
middlewares.NewAwsDefaultRoute(), middlewares.NewAwsDefaultRoute(),
middlewares.NewAwsNatGatewayEipAssoc(), middlewares.NewAwsNatGatewayEipAssoc(),
middlewares.NewAwsBucketPolicyExpander(d.resourceFactory), middlewares.NewAwsBucketPolicyExpander(d.resourceFactory),
middlewares.NewAwsSqsQueuePolicyExpander(d.resourceFactory, d.resourceSchemaRepository), middlewares.NewAwsSQSQueuePolicyExpander(d.resourceFactory, d.resourceSchemaRepository),
middlewares.NewAwsDefaultSqsQueuePolicy(), middlewares.NewAwsDefaultSQSQueuePolicy(),
middlewares.NewAwsSNSTopicPolicyExpander(d.resourceFactory, d.resourceSchemaRepository), middlewares.NewAwsSNSTopicPolicyExpander(d.resourceFactory, d.resourceSchemaRepository),
middlewares.NewAwsRoleManagedPolicyExpander(d.resourceFactory), middlewares.NewAwsRoleManagedPolicyExpander(d.resourceFactory),
middlewares.NewTagsAllManager(), middlewares.NewTagsAllManager(),

View File

@ -12,13 +12,13 @@ import (
// the SDK return an empty policy (e.g. policy = ""). // the SDK return an empty policy (e.g. policy = "").
// We need to ignore those policy from unmanaged resources if they are not managed // We need to ignore those policy from unmanaged resources if they are not managed
// by IaC. // by IaC.
type AwsDefaultSqsQueuePolicy struct{} type AwsDefaultSQSQueuePolicy struct{}
func NewAwsDefaultSqsQueuePolicy() AwsDefaultSqsQueuePolicy { func NewAwsDefaultSQSQueuePolicy() AwsDefaultSQSQueuePolicy {
return AwsDefaultSqsQueuePolicy{} return AwsDefaultSQSQueuePolicy{}
} }
func (m AwsDefaultSqsQueuePolicy) Execute(remoteResources, resourcesFromState *[]resource.Resource) error { func (m AwsDefaultSQSQueuePolicy) Execute(remoteResources, resourcesFromState *[]resource.Resource) error {
newRemoteResources := make([]resource.Resource, 0) newRemoteResources := make([]resource.Resource, 0)
for _, res := range *remoteResources { for _, res := range *remoteResources {
// Ignore all resources other than sqs_queue_policy // Ignore all resources other than sqs_queue_policy

View File

@ -11,7 +11,7 @@ import (
"github.com/cloudskiff/driftctl/pkg/resource/aws" "github.com/cloudskiff/driftctl/pkg/resource/aws"
) )
func TestAwsDefaultSqsQueuePolicy_Execute(t *testing.T) { func TestAwsDefaultSQSQueuePolicy_Execute(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
remoteResources []resource.Resource remoteResources []resource.Resource
@ -129,7 +129,7 @@ func TestAwsDefaultSqsQueuePolicy_Execute(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
m := NewAwsDefaultSqsQueuePolicy() m := NewAwsDefaultSQSQueuePolicy()
err := m.Execute(&tt.remoteResources, &tt.resourcesFromState) err := m.Execute(&tt.remoteResources, &tt.resourcesFromState)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -8,19 +8,19 @@ import (
) )
// Explodes policy found in aws_sqs_queue.policy from state resources to dedicated resources // Explodes policy found in aws_sqs_queue.policy from state resources to dedicated resources
type AwsSqsQueuePolicyExpander struct { type AwsSQSQueuePolicyExpander struct {
resourceFactory resource.ResourceFactory resourceFactory resource.ResourceFactory
resourceSchemaRepository resource.SchemaRepositoryInterface resourceSchemaRepository resource.SchemaRepositoryInterface
} }
func NewAwsSqsQueuePolicyExpander(resourceFactory resource.ResourceFactory, resourceSchemaRepository resource.SchemaRepositoryInterface) AwsSqsQueuePolicyExpander { func NewAwsSQSQueuePolicyExpander(resourceFactory resource.ResourceFactory, resourceSchemaRepository resource.SchemaRepositoryInterface) AwsSQSQueuePolicyExpander {
return AwsSqsQueuePolicyExpander{ return AwsSQSQueuePolicyExpander{
resourceFactory, resourceFactory,
resourceSchemaRepository, resourceSchemaRepository,
} }
} }
func (m AwsSqsQueuePolicyExpander) Execute(remoteResources, resourcesFromState *[]resource.Resource) error { func (m AwsSQSQueuePolicyExpander) Execute(remoteResources, resourcesFromState *[]resource.Resource) error {
for _, res := range *remoteResources { for _, res := range *remoteResources {
if res.TerraformType() != aws.AwsSqsQueueResourceType { if res.TerraformType() != aws.AwsSqsQueueResourceType {
continue continue
@ -59,7 +59,7 @@ func (m AwsSqsQueuePolicyExpander) Execute(remoteResources, resourcesFromState *
return nil return nil
} }
func (m *AwsSqsQueuePolicyExpander) handlePolicy(queue *resource.AbstractResource, results *[]resource.Resource) error { func (m *AwsSQSQueuePolicyExpander) handlePolicy(queue *resource.AbstractResource, results *[]resource.Resource) error {
policy, exists := queue.Attrs.Get("policy") policy, exists := queue.Attrs.Get("policy")
if !exists || policy.(string) == "" { if !exists || policy.(string) == "" {
queue.Attrs.SafeDelete([]string{"policy"}) queue.Attrs.SafeDelete([]string{"policy"})
@ -86,7 +86,7 @@ func (m *AwsSqsQueuePolicyExpander) handlePolicy(queue *resource.AbstractResourc
// It is mandatory since it's possible to have a aws_sqs_queue with an inline policy // It is mandatory since it's possible to have a aws_sqs_queue with an inline policy
// AND a aws_sqs_queue_policy resource at the same time. At the end, on the AWS console, // AND a aws_sqs_queue_policy resource at the same time. At the end, on the AWS console,
// the aws_sqs_queue_policy will be used. // the aws_sqs_queue_policy will be used.
func (m *AwsSqsQueuePolicyExpander) hasPolicyAttached(queue *resource.AbstractResource, resourcesFromState *[]resource.Resource) bool { func (m *AwsSQSQueuePolicyExpander) hasPolicyAttached(queue *resource.AbstractResource, resourcesFromState *[]resource.Resource) bool {
for _, res := range *resourcesFromState { for _, res := range *resourcesFromState {
if res.TerraformType() == aws.AwsSqsQueuePolicyResourceType && if res.TerraformType() == aws.AwsSqsQueuePolicyResourceType &&
res.TerraformId() == queue.Id { res.TerraformId() == queue.Id {

View File

@ -15,7 +15,7 @@ import (
"github.com/r3labs/diff/v2" "github.com/r3labs/diff/v2"
) )
func TestAwsSqsQueuePolicyExpander_Execute(t *testing.T) { func TestAwsSQSQueuePolicyExpander_Execute(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
resourcesFromState []resource.Resource resourcesFromState []resource.Resource
@ -224,7 +224,7 @@ func TestAwsSqsQueuePolicyExpander_Execute(t *testing.T) {
repo := testresource.InitFakeSchemaRepository("aws", "3.19.0") repo := testresource.InitFakeSchemaRepository("aws", "3.19.0")
aws.InitResourcesMetadata(repo) aws.InitResourcesMetadata(repo)
m := NewAwsSqsQueuePolicyExpander(factory, repo) m := NewAwsSQSQueuePolicyExpander(factory, repo)
err := m.Execute(&[]resource.Resource{}, &tt.resourcesFromState) err := m.Execute(&[]resource.Resource{}, &tt.resourcesFromState)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -119,7 +119,7 @@ func Init(version string, alerter *alerter.Alerter,
remoteLibrary.AddEnumerator(NewCloudfrontDistributionEnumerator(cloudfrontRepository, factory)) remoteLibrary.AddEnumerator(NewCloudfrontDistributionEnumerator(cloudfrontRepository, factory))
remoteLibrary.AddDetailsFetcher(aws.AwsCloudfrontDistributionResourceType, common.NewGenericDetailsFetcher(aws.AwsCloudfrontDistributionResourceType, provider, deserializer)) remoteLibrary.AddDetailsFetcher(aws.AwsCloudfrontDistributionResourceType, common.NewGenericDetailsFetcher(aws.AwsCloudfrontDistributionResourceType, provider, deserializer))
remoteLibrary.AddEnumerator(NewSqsQueueEnumerator(sqsRepository, factory)) remoteLibrary.AddEnumerator(NewSQSQueueEnumerator(sqsRepository, factory))
remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueueResourceType, common.NewGenericDetailsFetcher(aws.AwsSqsQueueResourceType, provider, deserializer)) remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueueResourceType, common.NewGenericDetailsFetcher(aws.AwsSqsQueueResourceType, provider, deserializer))
remoteLibrary.AddEnumerator(NewSQSQueuePolicyEnumerator(sqsRepository, factory)) remoteLibrary.AddEnumerator(NewSQSQueuePolicyEnumerator(sqsRepository, factory))
remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueuePolicyResourceType, common.NewGenericDetailsFetcher(aws.AwsSqsQueuePolicyResourceType, provider, deserializer)) remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueuePolicyResourceType, common.NewGenericDetailsFetcher(aws.AwsSqsQueuePolicyResourceType, provider, deserializer))

View File

@ -9,23 +9,23 @@ import (
awssdk "github.com/aws/aws-sdk-go/aws" awssdk "github.com/aws/aws-sdk-go/aws"
) )
type SqsQueueEnumerator struct { type SQSQueueEnumerator struct {
repository repository.SQSRepository repository repository.SQSRepository
factory resource.ResourceFactory factory resource.ResourceFactory
} }
func NewSqsQueueEnumerator(repo repository.SQSRepository, factory resource.ResourceFactory) *SqsQueueEnumerator { func NewSQSQueueEnumerator(repo repository.SQSRepository, factory resource.ResourceFactory) *SQSQueueEnumerator {
return &SqsQueueEnumerator{ return &SQSQueueEnumerator{
repository: repo, repository: repo,
factory: factory, factory: factory,
} }
} }
func (e *SqsQueueEnumerator) SupportedType() resource.ResourceType { func (e *SQSQueueEnumerator) SupportedType() resource.ResourceType {
return aws.AwsSqsQueueResourceType return aws.AwsSqsQueueResourceType
} }
func (e *SqsQueueEnumerator) Enumerate() ([]resource.Resource, error) { func (e *SQSQueueEnumerator) Enumerate() ([]resource.Resource, error) {
queues, err := e.repository.ListAllQueues() queues, err := e.repository.ListAllQueues()
if err != nil { if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, string(e.SupportedType())) return nil, remoteerror.NewResourceEnumerationError(err, string(e.SupportedType()))

View File

@ -22,7 +22,7 @@ import (
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )
func TestSqsQueue(t *testing.T) { func TestSQSQueue(t *testing.T) {
cases := []struct { cases := []struct {
test string test string
dirName string dirName string
@ -99,7 +99,7 @@ func TestSqsQueue(t *testing.T) {
repo = repository.NewSQSRepository(sess, cache.New(0)) repo = repository.NewSQSRepository(sess, cache.New(0))
} }
remoteLibrary.AddEnumerator(aws.NewSqsQueueEnumerator(repo, factory)) remoteLibrary.AddEnumerator(aws.NewSQSQueueEnumerator(repo, factory))
remoteLibrary.AddDetailsFetcher(resourceaws.AwsSqsQueueResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsSqsQueueResourceType, provider, deserializer)) remoteLibrary.AddDetailsFetcher(resourceaws.AwsSqsQueueResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsSqsQueueResourceType, provider, deserializer))
s := NewScanner(nil, remoteLibrary, alerter, scanOptions) s := NewScanner(nil, remoteLibrary, alerter, scanOptions)

View File

@ -7,7 +7,7 @@ import (
const AwsSqsQueuePolicyResourceType = "aws_sqs_queue_policy" const AwsSqsQueuePolicyResourceType = "aws_sqs_queue_policy"
func initAwsSqsQueuePolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { func initAwsSQSQueuePolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) {
resourceSchemaRepository.UpdateSchema(AwsSqsQueuePolicyResourceType, map[string]func(attributeSchema *resource.AttributeSchema){ resourceSchemaRepository.UpdateSchema(AwsSqsQueuePolicyResourceType, map[string]func(attributeSchema *resource.AttributeSchema){
"policy": func(attributeSchema *resource.AttributeSchema) { "policy": func(attributeSchema *resource.AttributeSchema) {
attributeSchema.JsonString = true attributeSchema.JsonString = true

View File

@ -12,7 +12,7 @@ import (
"github.com/cloudskiff/driftctl/test/acceptance" "github.com/cloudskiff/driftctl/test/acceptance"
) )
func TestAcc_AwsSqsQueuePolicy(t *testing.T) { func TestAcc_AwsSQSQueuePolicy(t *testing.T) {
acceptance.Run(t, acceptance.AccTestCase{ acceptance.Run(t, acceptance.AccTestCase{
TerraformVersion: "0.14.9", TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_sqs_queue_policy"}, Paths: []string{"./testdata/acc/aws_sqs_queue_policy"},

View File

@ -19,7 +19,7 @@ import (
"github.com/cloudskiff/driftctl/test/acceptance/awsutils" "github.com/cloudskiff/driftctl/test/acceptance/awsutils"
) )
func TestAcc_AwsSqsQueue(t *testing.T) { func TestAcc_AwsSQSQueue(t *testing.T) {
var mutatedQueue string var mutatedQueue string
acceptance.Run(t, acceptance.AccTestCase{ acceptance.Run(t, acceptance.AccTestCase{
TerraformVersion: "0.14.9", TerraformVersion: "0.14.9",

View File

@ -38,7 +38,7 @@ func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInt
initAwsLambdaFunctionMetaData(resourceSchemaRepository) initAwsLambdaFunctionMetaData(resourceSchemaRepository)
initAwsLambdaEventSourceMappingMetaData(resourceSchemaRepository) initAwsLambdaEventSourceMappingMetaData(resourceSchemaRepository)
initAwsSubnetMetaData(resourceSchemaRepository) initAwsSubnetMetaData(resourceSchemaRepository)
initAwsSqsQueuePolicyMetaData(resourceSchemaRepository) initAwsSQSQueuePolicyMetaData(resourceSchemaRepository)
initAwsSecurityGroupRuleMetaData(resourceSchemaRepository) initAwsSecurityGroupRuleMetaData(resourceSchemaRepository)
initAwsSecurityGroupMetaData(resourceSchemaRepository) initAwsSecurityGroupMetaData(resourceSchemaRepository)
} }