SQS - Accept queue-names as QueueUrl-parameter (#5073)
This commit is contained in:
parent
3cb455edb7
commit
56806fb310
@ -128,13 +128,3 @@ class OverLimit(RESTError):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
"OverLimit", "{} Actions were found, maximum allowed is 7.".format(count)
|
"OverLimit", "{} Actions were found, maximum allowed is 7.".format(count)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class InvalidAddress(RESTError):
|
|
||||||
code = 400
|
|
||||||
|
|
||||||
def __init__(self, address):
|
|
||||||
super().__init__(
|
|
||||||
"InvalidAddress",
|
|
||||||
"The address {} is not valid for this endpoint.".format(address),
|
|
||||||
)
|
|
||||||
|
@ -12,7 +12,6 @@ from urllib.parse import urlparse
|
|||||||
|
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
EmptyBatchRequest,
|
EmptyBatchRequest,
|
||||||
InvalidAddress,
|
|
||||||
InvalidAttributeName,
|
InvalidAttributeName,
|
||||||
ReceiptHandleIsInvalid,
|
ReceiptHandleIsInvalid,
|
||||||
BatchEntryIdsNotDistinct,
|
BatchEntryIdsNotDistinct,
|
||||||
@ -53,7 +52,8 @@ class SQSResponse(BaseResponse):
|
|||||||
if queue_url.startswith("http://") or queue_url.startswith("https://"):
|
if queue_url.startswith("http://") or queue_url.startswith("https://"):
|
||||||
return queue_url.split("/")[-1]
|
return queue_url.split("/")[-1]
|
||||||
else:
|
else:
|
||||||
raise InvalidAddress(queue_url)
|
# The parameter could be the name itself, which AWS also accepts
|
||||||
|
return queue_url
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Fallback to reading from the URL for botocore
|
# Fallback to reading from the URL for botocore
|
||||||
return self.path.split("/")[-1]
|
return self.path.split("/")[-1]
|
||||||
|
@ -3018,7 +3018,7 @@ def test_fifo_send_message_when_same_group_id_is_in_dlq():
|
|||||||
|
|
||||||
|
|
||||||
@mock_sqs
|
@mock_sqs
|
||||||
def test_receive_message_should_not_accept_invalid_urls():
|
def test_receive_message_using_name__should_return_name_as_url():
|
||||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||||
conn = boto3.client("sqs", region_name="us-east-1")
|
conn = boto3.client("sqs", region_name="us-east-1")
|
||||||
name = str(uuid4())[0:6]
|
name = str(uuid4())[0:6]
|
||||||
@ -3029,17 +3029,10 @@ def test_receive_message_should_not_accept_invalid_urls():
|
|||||||
working_url.should.match(f"/{ACCOUNT_ID}/{name}")
|
working_url.should.match(f"/{ACCOUNT_ID}/{name}")
|
||||||
|
|
||||||
queue = sqs.Queue(name)
|
queue = sqs.Queue(name)
|
||||||
with pytest.raises(ClientError) as e:
|
|
||||||
queue.send_message(MessageBody="this is a test message")
|
queue.send_message(MessageBody="this is a test message")
|
||||||
err = e.value.response["Error"]
|
|
||||||
err["Code"].should.equal("InvalidAddress")
|
|
||||||
err["Message"].should.equal(f"The address {name} is not valid for this endpoint.")
|
|
||||||
|
|
||||||
with pytest.raises(ClientError) as e:
|
resp = queue.receive_messages()
|
||||||
conn.receive_message(QueueUrl=name)
|
resp[0].queue_url.should.equal(name)
|
||||||
err = e.value.response["Error"]
|
|
||||||
err["Code"].should.equal("InvalidAddress")
|
|
||||||
err["Message"].should.equal(f"The address {name} is not valid for this endpoint.")
|
|
||||||
|
|
||||||
|
|
||||||
@mock_sqs
|
@mock_sqs
|
||||||
|
Loading…
Reference in New Issue
Block a user