Skip to content

Commit bf73c2c

Browse files
committed
work in review suggestions
1 parent 359de2a commit bf73c2c

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

localstack-core/localstack/services/sqs/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
)
3131
from localstack.services.sqs.queue import InterruptiblePriorityQueue, InterruptibleQueue
3232
from localstack.services.sqs.utils import (
33-
decode_receipt_handle,
3433
encode_move_task_handle,
3534
encode_receipt_handle,
3635
extract_receipt_handle_info,
@@ -446,7 +445,7 @@ def approx_number_of_messages_delayed(self) -> int:
446445
return len(self.delayed)
447446

448447
def validate_receipt_handle(self, receipt_handle: str):
449-
if self.arn != decode_receipt_handle(receipt_handle):
448+
if self.arn != extract_receipt_handle_info(receipt_handle).queue_arn:
450449
raise ReceiptHandleIsInvalid(
451450
f'The input receipt handle "{receipt_handle}" is not a valid receipt handle.'
452451
)

localstack-core/localstack/services/sqs/utils.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,6 @@ def parse_queue_url(queue_url: str) -> Tuple[str, Optional[str], str]:
116116
return account_id, region, queue_name
117117

118118

119-
def decode_receipt_handle(receipt_handle: str) -> str:
120-
try:
121-
_, queue_arn, *_ = extract_receipt_handle_info(receipt_handle)
122-
parse_arn(queue_arn) # raises a ValueError if it is not an arn
123-
return queue_arn
124-
except (IndexError, ValueError):
125-
raise ReceiptHandleIsInvalid(
126-
f'The input receipt handle "{receipt_handle}" is not a valid receipt handle.'
127-
)
128-
129-
130119
class ReceiptHandleInformation(NamedTuple):
131120
identifier: str
132121
queue_arn: str
@@ -137,11 +126,15 @@ class ReceiptHandleInformation(NamedTuple):
137126
def extract_receipt_handle_info(receipt_handle: str) -> ReceiptHandleInformation:
138127
try:
139128
handle = base64.b64decode(receipt_handle).decode("utf-8")
140-
return ReceiptHandleInformation(*handle.split(" "))
141-
except (IndexError, ValueError):
129+
parts = handle.split(" ")
130+
if len(parts) != 4:
131+
raise ValueError(f'The input receipt handle "{receipt_handle}" is incomplete.')
132+
parse_arn(parts[1])
133+
return ReceiptHandleInformation(*parts)
134+
except (IndexError, ValueError) as e:
142135
raise ReceiptHandleIsInvalid(
143136
f'The input receipt handle "{receipt_handle}" is not a valid receipt handle.'
144-
)
137+
) from e
145138

146139

147140
def encode_receipt_handle(queue_arn, message) -> str:

0 commit comments

Comments
 (0)