Merge pull request #872 from cloudskiff/fix_sqs_queue_policy_crash

Fix SQS queue policy crash
main
Elie 2021-07-23 11:49:16 +02:00 committed by GitHub
commit b9f416161a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -32,21 +32,25 @@ func (e *SQSQueuePolicyEnumerator) Enumerate() ([]resource.Resource, error) {
return nil, remoteerror.NewResourceEnumerationErrorWithType(err, string(e.SupportedType()), aws.AwsSqsQueueResourceType)
}
results := make([]resource.Resource, len(queues))
results := make([]resource.Resource, 0, len(queues))
for _, queue := range queues {
attrs := map[string]interface{}{
"policy": "",
}
attributes, err := e.repository.GetQueueAttributes(*queue)
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, string(e.SupportedType()))
}
if attributes.Attributes != nil {
attrs["policy"] = *attributes.Attributes[sqs.QueueAttributeNamePolicy]
}
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
awssdk.StringValue(queue),
map[string]interface{}{
"policy": *attributes.Attributes[sqs.QueueAttributeNamePolicy],
},
attrs,
),
)
}

View File

@ -152,6 +152,23 @@ func TestSQSQueuePolicy(t *testing.T) {
},
wantErr: nil,
},
{
test: "multiple sqs queue policies (with nil attributes)",
dirName: "sqs_queue_policy_multiple",
mocks: func(client *repository.MockSQSRepository) {
client.On("ListAllQueues").Return([]*string{
awssdk.String("https://sqs.eu-west-3.amazonaws.com/047081014315/bar.fifo"),
awssdk.String("https://sqs.eu-west-3.amazonaws.com/047081014315/foo"),
awssdk.String("https://sqs.eu-west-3.amazonaws.com/047081014315/baz"),
}, nil)
client.On("GetQueueAttributes", mock.Anything).Return(
&sqs.GetQueueAttributesOutput{},
nil,
)
},
wantErr: nil,
},
{
test: "cannot list sqs queues, thus sqs queue policies",
dirName: "sqs_queue_policy_empty",