Skip to content

Commit

Permalink
[raz] Automatically set host and check env credential values
Browse files Browse the repository at this point in the history
  • Loading branch information
romainr committed Jun 11, 2021
1 parent e024246 commit ed0e627
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions desktop/libs/aws/src/aws/conf.py
Expand Up @@ -24,7 +24,7 @@

from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, coerce_bool, coerce_password_from_script
from desktop.lib.idbroker import conf as conf_idbroker
from hadoop.core_site import get_s3a_access_key, get_s3a_secret_key, get_s3a_session_token
from hadoop.core_site import get_s3a_access_key, get_s3a_secret_key, get_s3a_session_token, get_raz_api_url, get_raz_default_endpoint

if sys.version_info[0] > 2:
from django.utils.translation import gettext_lazy as _, gettext as _t
Expand Down Expand Up @@ -169,6 +169,19 @@ def get_key_expiry():
default=False,
)

def get_default_host():
'''Returns the S3 host when Raz is configued'''

if get_raz_api_url():
endpoint = get_raz_default_endpoint()
if endpoint:
return endpoint.get('host')

def get_default_get_environment_credentials():
'''Allow to check if environment credentials are present or not'''
return not get_raz_api_url()


AWS_ACCOUNTS = UnspecifiedConfigSection(
'aws_accounts',
help=_('One entry for each AWS account'),
Expand Down Expand Up @@ -208,12 +221,12 @@ def get_key_expiry():
ALLOW_ENVIRONMENT_CREDENTIALS=Config(
help=_('Allow to use environment sources of credentials (environment variables, EC2 profile).'),
key='allow_environment_credentials',
default=True,
dynamic_default=get_default_get_environment_credentials(),
type=coerce_bool
),
REGION=Config(
key='region',
default=None,
dynamic_default=get_default_host,
type=str
),
HOST=Config(
Expand Down
2 changes: 1 addition & 1 deletion desktop/libs/hadoop/src/hadoop/core_site.py
Expand Up @@ -144,7 +144,7 @@ def get_raz_default_endpoint():
match = re.search(_CNF_S3A_RAZ_BUCKET_ENDPOINT, key)
if match:
return {
'region': val,
'host': val,
'bucket': match.group('bucket')
}

Expand Down

0 comments on commit ed0e627

Please sign in to comment.