Skip to content

Commit f4ffef3

Browse files
authored
update logic to keep extension open to other providers
1 parent bad87fa commit f4ffef3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

jupyter_drives/base.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,35 @@ def __init__(self, **kwargs):
7676
self._load_credentials()
7777

7878
def _load_credentials(self):
79+
# check if credentials were already set in jupyter_notebook_config.py
80+
if self.access_key_id is not None and self.secret_access_key is not None:
81+
return
82+
83+
# automatically extract credentials for S3 drives
84+
try:
85+
s = boto3.Session()
86+
c = s.get_credentials()
87+
if c is not None:
88+
self.access_key_id = c.access_key
89+
self.secret_access_key = c.secret_key
90+
self.region_name = s.region_name
91+
self.session_token = c.token
92+
self.provider = 's3'
93+
return
94+
except:
95+
# S3 credentials couldn't automatically be extracted through boto
96+
pass
97+
98+
# use environment variables
99+
if "JP_DRIVES_ACCESS_KEY_ID" in os.environ and "JP_DRIVES_SECRET_ACCESS_KEY" in os.environ:
100+
self.access_key_id = os.environ["JP_DRIVES_ACCESS_KEY_ID"]
101+
self.secret_access_key = os.environ["JP_DRIVES_SECRET_ACCESS_KEY"]
102+
if "JP_DRIVES_SESSION_TOKEN" in os.environ:
103+
self.session_token = os.environ["JP_DRIVES_SESSION_TOKEN"]
104+
if "JP_DRIVES_PROVIDER" in os.environ:
105+
self.provider = os.environ["JP_DRIVES_PROVIDER"]
106+
return
107+
79108
s = boto3.Session()
80109
c = s.get_credentials()
81110
self.access_key_id = c.access_key

0 commit comments

Comments
 (0)