Skip to content

Commit

Permalink
Fix access of json string redrive policy in sqs (cartography-cncf#687)
Browse files Browse the repository at this point in the history
* Fix access of json string redrive policy in sqs

* Update test data

* fix json string

* Set redrive policy in the object for loading into current object
  • Loading branch information
ryan-lane authored Sep 14, 2021
1 parent ed1d234 commit 92bab0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 14 additions & 6 deletions cartography/intel/aws/sqs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
from typing import Any
from typing import Dict
Expand Down Expand Up @@ -93,12 +94,19 @@ def load_sqs_queues(
queue['name'] = queue['QueueArn'].split(':')[-1]
queue['CreatedTimestamp'] = int(queue['CreatedTimestamp'])
queue['LastModifiedTimestamp'] = int(queue['LastModifiedTimestamp'])
dead_letter_arn = queue.get('RedrivePolicy', {}).get('deadLetterTargetArn')
if dead_letter_arn:
dead_letter_queues.append({
'arn': queue['QueueArn'],
'dead_letter_arn': dead_letter_arn,
})
redrive_policy = queue.get('RedrivePolicy')
if redrive_policy:
try:
rp = json.loads(redrive_policy)
except TypeError:
rp = {}
queue['RedrivePolicy'] = rp
dead_letter_arn = rp.get('deadLetterTargetArn')
if dead_letter_arn:
dead_letter_queues.append({
'arn': queue['QueueArn'],
'dead_letter_arn': dead_letter_arn,
})
queues.append(queue)

neo4j_session.run(
Expand Down
5 changes: 1 addition & 4 deletions tests/data/aws/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
'QueueArn': 'arn:aws:secretsmanager:us-east-1:000000000000:test-queue-1',
'CreatedTimestamp': '1627539901900',
'LastModifiedTimestamp': '1627539901900',
'RedrivePolicy': {
'deadLetterTargetArn': 'arn:aws:secretsmanager:us-east-1:000000000000:test-queue-2',
'maxReceiveCount': '1',
},
'RedrivePolicy': '{"deadLetterTargetArn": "arn:aws:secretsmanager:us-east-1:000000000000:test-queue-2", "maxReceiveCount": "1"}', # noqa: E501
'VisibilityTimeout': '10',
},
'https://us-east-1.queue.amazonaws.com/000000000000/test-queue-2': {
Expand Down

0 comments on commit 92bab0a

Please sign in to comment.