@@ -117,6 +117,15 @@ def _nested_dict():
117
117
# placeholder
118
118
# generator, probe, detector, buff = {}, {}, {}, {}
119
119
120
+ def _key_exists (d : dict , key : str ) -> bool :
121
+ # Check for the presence of a key in a nested dict.
122
+ if not isinstance (d , dict ):
123
+ return False
124
+ if key in d .keys ():
125
+ return True
126
+ else :
127
+ return any ([_key_exists (val , key ) for val in d .values ()])
128
+
120
129
121
130
def _set_settings (config_obj , settings_obj : dict ):
122
131
for k , v in settings_obj .items ():
@@ -143,10 +152,11 @@ def _load_yaml_config(settings_filenames) -> dict:
143
152
with open (settings_filename , encoding = "utf-8" ) as settings_file :
144
153
settings = yaml .safe_load (settings_file )
145
154
if settings is not None :
146
- if "api_key" in settings .keys ():
155
+ if _key_exists (settings , "api_key" ):
156
+ logging .info (f"API key found in { settings_filename } . Checking readability..." )
147
157
res = os .stat (settings_filename )
148
158
if res .st_mode & stat .S_IROTH or res .st_mode & stat .S_IRGRP :
149
- raise ConfigSecretWarning (f"A possibly secret value (`api_key`) was detected in { settings_filename } , which is readable by users other than yourself." )
159
+ logging . warn (f"A possibly secret value (`api_key`) was detected in { settings_filename } , which is readable by users other than yourself." )
150
160
config = _combine_into (settings , config )
151
161
return config
152
162
0 commit comments