-
Notifications
You must be signed in to change notification settings - Fork 1
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S3 localstack ize #266
Open
dmichaels-harvard
wants to merge
42
commits into
master
Choose a base branch
from
s3-localstack-ize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
S3 localstack ize #266
Changes from 30 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
9b4b6ab
Factor on boto3 s3/sqs client/resource creation for optional override…
dmichaels-harvard 17551d3
Version update
dmichaels-harvard 6dc574a
Version on CHANGES.rst updates.
dmichaels-harvard d136776
boto3 imports
dmichaels-harvard 9649ea6
Suppport for monkey patched version of localstack-ization of boto3 s3…
dmichaels-harvard c33cabd
Suppport for monkey patched version of localstack-ization of boto3 s3…
dmichaels-harvard 436ddd3
Suppport for monkey patched version of localstack-ization of boto3 s3…
dmichaels-harvard 0051a6e
Suppport for monkey patched version of localstack-ization of boto3 s3…
dmichaels-harvard 2ebe024
Suppport for monkey patched version of localstack-ization of boto3 s3…
dmichaels-harvard 1382272
flake8
dmichaels-harvard 25fcce1
Suppport for monkey patched version of localstack-ization of boto3 s3…
dmichaels-harvard 8fb480b
Debugging publish
dmichaels-harvard 3cd25c5
Debugging publish
dmichaels-harvard ebfa631
Debugging publish
dmichaels-harvard 024c6b4
Changed boto3 localstack monkeypatching to use LOCALSTACK_S3_URL and …
dmichaels-harvard 7e2f6f0
Added some notes on localstack usage in getting_started.rst and added…
dmichaels-harvard 11d0209
Added some notes on localstack usage in getting_started.rst and added…
dmichaels-harvard 9716414
Merge from master
dmichaels-harvard fd1ed9a
Fix for (smaht) for test_common.py - this fix needs to go in master too
dmichaels-harvard efe3495
Merge branch 'master' into s3-localstack-ize
dmichaels-harvard fcbe1f8
merge from master
dmichaels-harvard 48f5860
merge from master
dmichaels-harvard 11d881c
merge from master
dmichaels-harvard f537d44
merge from master
dmichaels-harvard b6a11ae
merge from master
dmichaels-harvard 3b7f212
merge from master
dmichaels-harvard a22ce88
merge in kmp_fix_broken_project_utils_test branch with test fix
dmichaels-harvard 1942232
Merge branch 'master' into s3-localstack-ize
dmichaels-harvard 9f59c2e
Merge branch 'kmp_add_dns_licenses' into s3-localstack-ize
dmichaels-harvard 2ae8317
Added localstack-ext (Apache-2.0) in license exception table.
dmichaels-harvard 9c20065
merge from master
dmichaels-harvard d0f5a5a
typo
dmichaels-harvard daad33e
white space fix
dmichaels-harvard 2a84d18
Minor comment/typo cleanup in publish_to_pypi.py
dmichaels-harvard fc91806
Update PyYAML to ^6.0.1; Mac M1 with Python 3.9 requires 5.3.1 (not 5…
dmichaels-harvard 7387f0f
Comments
dmichaels-harvard 05d78e6
Merge from master
dmichaels-harvard 0b37679
merge from master
dmichaels-harvard 646a265
CHANGELOG.rst updates.
dmichaels-harvard 0f3d3f0
Fix to test_s3_utils from kmp_sheet_utils_schema_hinting branch.
dmichaels-harvard 6eecccf
flake8 update
dmichaels-harvard 8f7cb75
comment
dmichaels-harvard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 @@ | ||
from . import boto_monkey_patching # noqa |
This file contains 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,68 @@ | ||
# Module to monkey patch the boto3 client and resource functions to use a custom endpoint-url. | ||
# Originally introduced June 2023 for overriding certain boto3 services (e.g. s3, sqs) to use the | ||
# localstack utility, which provides a way to run some AWS services locally, for testing purposes. | ||
# Currently only supported for S3 and SQS. To use this set the environment variables LOCALSTACK_S3_URL | ||
# and/or LOCALSTACK_SQS_URL to the localstack URL, for example, http://localhost:4566. | ||
# Reference: https://localstack.cloud | ||
|
||
import boto3 | ||
import os | ||
from typing import Optional | ||
|
||
LOCALSTACK_S3_URL_ENVIRON_NAME = "LOCALSTACK_S3_URL" | ||
LOCALSTACK_SQS_URL_ENVIRON_NAME = "LOCALSTACK_SQS_URL" | ||
|
||
|
||
_boto_client_original = boto3.client | ||
_boto_resource_original = boto3.resource | ||
_boto_service_overrides_supported = [ | ||
{"service": "s3", "env": LOCALSTACK_S3_URL_ENVIRON_NAME}, | ||
{"service": "sqs", "env": LOCALSTACK_SQS_URL_ENVIRON_NAME} | ||
] | ||
|
||
# This will entirely disable this feature; for troubleshooting only. | ||
_boto_monkey_patching_disabled = False | ||
|
||
# For import only in test_boto_monkey_patching; | ||
# the list of AWS services for which we support this monkey patching facility (e.g. ["s3", "sqs"]). | ||
_boto_monkey_patching_services = [item["service"] for item in _boto_service_overrides_supported] | ||
|
||
|
||
# For import only in test_boto_monkey_patching. | ||
def _boto_monkey_patching_endpoint_url_environ_name(service: str) -> Optional[str]: | ||
""" | ||
For the given AWS service name (e.g. "s3" or "sqs") returns environment variable name which | ||
needs to be set in order to use a different (e.g. localstack version of the) endpoint URL | ||
when creating a boto3 client or resource. E.g. given "s3" this will return "LOCALSTACK_S3_URL". | ||
""" | ||
for item in _boto_service_overrides_supported: | ||
if item["service"] == service: | ||
return item["env"] | ||
return None | ||
|
||
|
||
def _setup_monkey_patching_kwargs(*args, **kwargs) -> dict: | ||
if not _boto_monkey_patching_disabled: | ||
endpoint_url = kwargs.get("endpoint_url") | ||
if not endpoint_url: | ||
for service_override in _boto_service_overrides_supported: | ||
if service_override["service"] in args: | ||
endpoint_url = os.environ.get(service_override["env"]) | ||
if endpoint_url: | ||
kwargs["endpoint_url"] = endpoint_url | ||
break | ||
return kwargs | ||
|
||
|
||
def _monkey_patched_boto_client(*args, **kwargs): | ||
kwargs = _setup_monkey_patching_kwargs(*args, **kwargs) | ||
return _boto_client_original(*args, **kwargs) | ||
|
||
|
||
def _monkey_patched_boto_resource(*args, **kwargs): | ||
kwargs = _setup_monkey_patching_kwargs(*args, **kwargs) | ||
return _boto_resource_original(*args, **kwargs) | ||
|
||
|
||
boto3.client = _monkey_patched_boto_client | ||
boto3.resource = _monkey_patched_boto_resource |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a comment. Please don't add any item to these lists without supporting rationale.
Also, needs a trailing comma so you don't have to change an extra line to add to the list.