- Notifications
You must be signed in to change notification settings - Fork0
Add sqs operations#6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
a9810e5 update spec and generated code
giograno890efed new stuff
giogranoe2b79b9 new generated code
giograno61dcc06 fix paths
giogranocf9d5a7 simplify and get messages
giogranoe3e26c3 better tests
giograno5cceb09 some utils
giogranoc5f95a1 fix import
giogranoFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 3 additions & 3 deletions.github/workflows/test.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletionslocalstack-sdk-python/localstack/sdk/aws/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from localstack.sdk.aws.client import AWSClient | ||
| __all__ = ["AWSClient"] |
51 changes: 51 additions & 0 deletionslocalstack-sdk-python/localstack/sdk/aws/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import json | ||
| from localstack.clients import BaseClient | ||
| from localstack.sdk.api.aws_api import AwsApi | ||
| from localstack.sdk.models import Message | ||
| def _from_sqs_query_to_json(xml_dict: dict) -> list[Message]: | ||
| """ | ||
| todo: developer endpoint implements sqs-query protocol. Remove this workaround one we move them to json. | ||
| """ | ||
| raw_messages = ( | ||
| xml_dict.get("ReceiveMessageResponse", {}).get("ReceiveMessageResult", {}) or {} | ||
| ).get("Message", []) | ||
| if isinstance(raw_messages, dict): | ||
| raw_messages = [raw_messages] | ||
| messages = [] | ||
| for msg in raw_messages: | ||
| _attributes = msg.get("Attribute", []) | ||
| attributes = {i["Name"]: i["Value"] for i in _attributes} | ||
| _m = { | ||
| "MessageId": msg.get("MessageId"), | ||
| "ReceiptHandle": msg.get("ReceiptHandle"), | ||
| "MD5OfBody": msg.get("MD5OfBody"), | ||
| "Body": msg.get("Body"), | ||
| "Attributes": attributes, | ||
| } | ||
| m = Message.from_dict(_m) | ||
| messages.append(m) | ||
| return messages | ||
| class AWSClient(BaseClient): | ||
| def __init__(self, **kwargs) -> None: | ||
| super().__init__(**kwargs) | ||
| self._client = AwsApi(self._api_client) | ||
| def list_sqs_messages(self, account_id: str, region: str, queue_name: str) -> list[Message]: | ||
| response = self._client.list_sqs_messages_with_http_info( | ||
| account_id=account_id, region=region, queue_name=queue_name | ||
| ) | ||
| return _from_sqs_query_to_json(json.loads(response.raw_data)) | ||
| def list_sqs_messages_from_queue_url(self, queue_url) -> list[Message]: | ||
| response = self._client.list_all_sqs_messages_with_http_info(queue_url=queue_url) | ||
| return _from_sqs_query_to_json(json.loads(response.raw_data)) | ||
| def get_default(**args) -> AwsApi: | ||
| """Return a client with a default configuration""" | ||
| return AwsApi(args) |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.