Skip to content

Commit

Permalink
Merge pull request #82 from janjagusch/s3-disable-ssl-verification
Browse files Browse the repository at this point in the history
Add option to disable SSL verification for S3Store
  • Loading branch information
xhochy authored Aug 15, 2023
2 parents df0e1d3 + 7b40a87 commit 23d636f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
1.8.0
=====
* Fixed the behaviour of ``S3FSStore`` when providing a custom endpoint.
* Added ``verify`` constructor argument to ``S3FSStore`` that disables SSL verification. Use it in an URI as ``?verify=false``.

1.7.0
=====
Expand Down
8 changes: 6 additions & 2 deletions minimalkv/net/s3fsstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(
reduced_redundancy=False,
public=False,
metadata=None,
verify=True,
):
if isinstance(bucket, str):
import boto3
Expand All @@ -47,6 +48,7 @@ def __init__(
self.reduced_redundancy = reduced_redundancy
self.public = public
self.metadata = metadata or {}
self.verify = verify

# Get endpoint URL
self.endpoint_url = self.bucket.meta.client.meta.endpoint_url
Expand All @@ -66,7 +68,7 @@ def _create_filesystem(self) -> "S3FileSystem":
if not has_s3fs:
raise ImportError("Cannot find optional dependency s3fs.")

client_kwargs = {}
client_kwargs = {"verify": self.verify}
if self.endpoint_url:
client_kwargs["endpoint_url"] = self.endpoint_url

Expand Down Expand Up @@ -187,4 +189,6 @@ def _from_parsed_url(
# The bucket will be created in the `create_filesystem` method if it doesn't exist.
bucket = resource.Bucket(bucket_name)

return cls(bucket)
verify = query.get("verify", "true").lower() == "true"

return cls(bucket, verify=verify)
3 changes: 2 additions & 1 deletion tests/store_creation/test_creation_boto3store.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

storage = pytest.importorskip("google.cloud.storage")

S3_URL = "s3://minio:[email protected]:9000/bucketname?create_if_missing=true&is_secure=false"
S3_URL = "s3://minio:[email protected]:9000/bucketname?create_if_missing=true&is_secure=false&verify=false"

"""
When using the `s3` scheme in a URL, the new store creation returns an `S3FSStore`.
Expand All @@ -26,6 +26,7 @@ def test_new_s3fs_creation():
bucket_name="bucketname-minio",
is_secure=False,
),
verify=False,
)

actual = get_store_from_url(S3_URL)
Expand Down

0 comments on commit 23d636f

Please sign in to comment.