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

Adds proxy server to minio / aws s3 storage #962

Merged
merged 10 commits into from
Oct 1, 2021
22 changes: 19 additions & 3 deletions datajoint/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from io import BytesIO
import minio # https://docs.minio.io/docs/python-client-api-reference
import urllib3
import warnings
import uuid
import logging
Expand All @@ -16,9 +17,24 @@ class Folder:
"""
A Folder instance manipulates a flat folder of objects within an S3-compatible object store
"""
def __init__(self, endpoint, bucket, access_key, secret_key, *, secure=False, **_):
self.client = minio.Minio(endpoint, access_key=access_key, secret_key=secret_key,
secure=secure)
def __init__(self, endpoint, bucket, access_key, secret_key, *, secure=False,
proxy_server=None, **_):
# from https://docs.min.io/docs/python-client-api-reference
self.client = minio.Minio(
endpoint,
access_key=access_key,
secret_key=secret_key,
secure=secure,
http_client=(
urllib3.ProxyManager(proxy_server,
timeout=urllib3.Timeout.DEFAULT_TIMEOUT,
cert_reqs="CERT_REQUIRED",
retries=urllib3.Retry(total=5,
backoff_factor=0.2,
status_forcelist=[500, 502, 503,
504]))
if proxy_server else None),
)
self.bucket = bucket
if not self.client.bucket_exists(bucket):
raise errors.BucketInaccessible('Inaccessible s3 bucket %s' % bucket)
Expand Down
3 changes: 2 additions & 1 deletion datajoint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def get_store_spec(self, store):
spec['subfolding'] = spec.get('subfolding', DEFAULT_SUBFOLDING)
spec_keys = { # REQUIRED in uppercase and allowed in lowercase
'file': ('PROTOCOL', 'LOCATION', 'subfolding', 'stage'),
's3': ('PROTOCOL', 'ENDPOINT', 'BUCKET', 'ACCESS_KEY', 'SECRET_KEY', 'LOCATION', 'secure', 'subfolding', 'stage')}
's3': ('PROTOCOL', 'ENDPOINT', 'BUCKET', 'ACCESS_KEY', 'SECRET_KEY', 'LOCATION',
'secure', 'subfolding', 'stage', 'proxy_server')}

try:
spec_keys = spec_keys[spec.get('protocol', '').lower()]
Expand Down