11import os
22from sys import platform
33import entrypoints
4- from traitlets import Enum , Unicode , default
4+ from traitlets import Enum , Unicode , default , Set
55from traitlets .config import Configurable
66import boto3
77
@@ -71,10 +71,27 @@ def set_default_api_base_url(self):
7171 help = "The source control provider." ,
7272 )
7373
74+ excluded_drives = Set (
75+ trait = Unicode (),
76+ config = True ,
77+ help = "List of drives that should be excluded from drive browser listing. Drive names should be separated by spaces." ,
78+ )
79+
80+ included_drives = Set (
81+ trait = Unicode (),
82+ config = True ,
83+ help = "List of drives that should be included in drive browser listing. Drive names should be separated by spaces." ,
84+ )
85+
7486 def __init__ (self , ** kwargs ):
7587 super ().__init__ (** kwargs )
7688 # check if credentials were already set in jupyter_notebook_config.py
7789 self .credentials_already_set = self .access_key_id is not None and self .secret_access_key is not None
90+
91+ # check list of excluded and included drives
92+ self .check_excluded_and_included_drives ()
93+
94+ # load credentials
7895 self .load_credentials ()
7996
8097 def load_credentials (self ):
@@ -111,4 +128,26 @@ def load_credentials(self):
111128 self .access_key_id = c .access_key
112129 self .secret_access_key = c .secret_key
113130 self .region_name = s .region_name
114- self .session_token = c .token
131+ self .session_token = c .token
132+
133+ def check_excluded_and_included_drives (self ):
134+ # list of drives to exclude was provided
135+ if len (self .excluded_drives ) != 0 :
136+ return
137+
138+ # list of what drives to include was provided
139+ if len (self .included_drives ) != 0 :
140+ return
141+
142+ # check environment variables for excluded or included drives configuration, only one is taken into account
143+ if "JP_DRIVES_EXCLUDED_DRIVES" in os .environ :
144+ drives = os .environ ["JP_DRIVES_EXCLUDED_DRIVES" ]
145+ self .excluded_drives = drives .split (' ' )
146+ return
147+
148+ if "JP_DRIVES_INCLUDED_DRIVES" in os .environ :
149+ drives = os .environ ["JP_DRIVES_INCLUDED_DRIVES" ]
150+ self .included_drives = drives .split (' ' )
151+ return
152+
153+ return
0 commit comments