Skip to content

Commit

Permalink
feat: read endpoint_url from more config keys & env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
sisterdong committed May 13, 2024
1 parent 62afeac commit fd91769
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions megfile/s3_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,19 @@ def get_endpoint_url(profile_name: Optional[str] = None) -> str:
:returns: S3 endpoint url
'''
environ_key = f'{profile_name}__OSS_ENDPOINT'.upper(
) if profile_name else 'OSS_ENDPOINT'
environ_endpoint_url = os.environ.get(environ_key)
if environ_endpoint_url:
warning_endpoint_url(environ_key, environ_endpoint_url)
return environ_endpoint_url
if profile_name:
environ_keys = (f'{profile_name}__OSS_ENDPOINT'.upper(),)
else:
environ_keys = ('OSS_ENDPOINT', 'AWS_ENDPOINT_URL')
for environ_key in environ_keys:
environ_endpoint_url = os.environ.get(environ_key)
if environ_endpoint_url:
warning_endpoint_url(environ_key, environ_endpoint_url)
return environ_endpoint_url
try:
config_endpoint_url = get_scoped_config(profile_name=profile_name).get(
's3', {}).get('endpoint_url')
config = get_scoped_config(profile_name=profile_name)
config_endpoint_url = config.get('s3', {}).get('endpoint_url')
config_endpoint_url = config_endpoint_url or config.get('endpoint_url')
if config_endpoint_url:
warning_endpoint_url('~/.aws/config', config_endpoint_url)
return config_endpoint_url
Expand Down

0 comments on commit fd91769

Please sign in to comment.