Skip to content
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

[WIP] Add possibility to parameterize S3 service URL #137

Conversation

YevheniiSemendiak
Copy link
Contributor

Just a minor thing, related to #136
I didn't found contribution guides, so this is potentially draft PR.
Nevertheless, WDYT about the possibility to support non-AWS S3 deployments?

Re the PR: what else should be added?

P.S. Thank you folks for an awesome lib 👍

@codecov
Copy link

codecov bot commented Mar 18, 2021

Codecov Report

Merging #137 (762c884) into master (80b596f) will not change coverage.
The diff coverage is 100.0%.

@@          Coverage Diff           @@
##           master    #137   +/-   ##
======================================
  Coverage    93.5%   93.5%           
======================================
  Files          21      21           
  Lines        1119    1119           
======================================
  Hits         1047    1047           
  Misses         72      72           
Impacted Files Coverage Δ
cloudpathlib/s3/s3client.py 92.8% <100.0%> (ø)

@pjbull
Copy link
Member

pjbull commented Mar 18, 2021

Happy to take this change! A few questions:

  • Can we add some notes to the docs about Min.IO and other S3 compatible object stores so that people can find it? Maybe at the end of the authentication page
  • Can we make a similar note in the docstring for the endpoint param?
  • I don't think we need additional mocked tests, but we may want a live server config to do this. Is there a min.io test server or hosted version with a free tier we could get creds for the test suite to access?
  • Can we add a test rig like the s3 one that pulls the endpoint URL from an env var and sets up the live server for testing? We may need to update CloudProviderTestRig.__init__ to take kwargs for the client.

Update: Heroku one-button deploy worked like a charm for a test server.

image

@YevheniiSemendiak
Copy link
Contributor Author

The notes are added here: 258392b
And the custom S3 rig here: 02f7a8c
Hope I get what you meant properly.

Copy link
Member

@pjbull pjbull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great @YevheniiSemendiak, thanks! Just a couple small things to tweak.

Once those are done, I'll probably move this over to a PR branch on the repo so that I can get the integration tests that use a live backend properly configured before merging to main.

cp1 = client.CloudPath("s3://cloudpathlib-test-bucket/")
# or pass the client as keyword argument
cp2 = CloudPath("s3://cloudpathlib-test-bucket/", client=client)
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might set this up to show three scenarios:

from cloudpathlib import S3Client, CloudPath

# create a client pointing to the endpoint
client = S3Client(endpoint_url="http://my.s3.server:1234")

# option 1: use the client to create paths
cp1 = client.CloudPath("s3://cloudpathlib-test-bucket/")

# option 2: pass the client as keyword argument
cp2 = CloudPath("s3://cloudpathlib-test-bucket/", client=client)

# option3: set this client as the default so it is used in any future paths
client.set_as_default_client()
cp3 = CloudPath("s3://cloudpathlib-test-bucket/")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done here fc113dc

@@ -212,6 +219,49 @@ def s3_rig(request, monkeypatch, assets_dir):
bucket.objects.filter(Prefix=test_dir).delete()


@fixture()
def custom_s3_rig(request, monkeypatch, assets_dir):
Copy link
Member

@pjbull pjbull Mar 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a docstring that this is used for testing things like MinIO/ceph

Copy link
Contributor Author

@YevheniiSemendiak YevheniiSemendiak Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done here 762c884

custom_secret_key = os.getenv("CUSTOM_S3_SECRET_KEY")
test_dir = create_test_dir_name(request)

# Upload test assets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the same if os.getenv("USE_LIVE_CLOUD") == "1": logic as in the S3 one so that local tests are fully mocked (endpoint_url is basically ignored in the mock), but we are running the integration tests against live backends we do this copying.

Copy link
Contributor Author

@YevheniiSemendiak YevheniiSemendiak Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done here 762c884
thanks for the clarification 🙂

@YevheniiSemendiak YevheniiSemendiak marked this pull request as ready for review March 23, 2021 09:56
@pjbull pjbull changed the base branch from master to custom-s3-endpoint March 23, 2021 17:35
@pjbull pjbull merged commit 6918915 into drivendataorg:custom-s3-endpoint Mar 23, 2021
@YevheniiSemendiak YevheniiSemendiak deleted the ys/parameterize_s3_endpoint branch March 24, 2021 10:21
pjbull added a commit that referenced this pull request Apr 3, 2021
* [WIP] Add possibility to parameterize S3 service URL (#137)

* Add possibility to parameterize S3 service URL

* add usage description into the docs

* add rig for custom S3 servers

* address PR review: add cods to rig, allow mock

* forgot to commit tests/conftest.py :)

* Run MinIO test rig

* Update docs/docs/authentication.md

* Simplify custom S3 auth; fix boto3 session state leak between fixtures

* Set env vars on live test workflow

* Remove comment about MinIO. Test passed so it seems fine

* Fix incorrect secrets reference

* Skip default client reset for custom s3 endpoint

* Skip mod time touch test for custom s3

* Remove unneeded import

* Update changelog

Co-authored-by: Yevhenii Semendiak <semendyak@gmail.com>
Co-authored-by: Jay Qi <2721979+jayqi@users.noreply.github.com>
Co-authored-by: Jay Qi <jayqi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants