@@ -56,7 +56,7 @@ def main(argv=None) -> int:
5656 clp_config = yaml .safe_load (clp_config_file )
5757
5858 env_vars : Dict [str , str ] = {}
59- if not _add_clp_env_vars (clp_config , clp_package_dir , env_vars ):
59+ if not _add_clp_env_vars (clp_config , clp_config_file_path , clp_package_dir , env_vars ):
6060 return 1
6161
6262 script_dir = Path (__file__ ).parent .resolve ()
@@ -76,12 +76,16 @@ def main(argv=None) -> int:
7676
7777
7878def _add_clp_env_vars (
79- clp_config : Dict [str , Any ], clp_package_dir : Path , env_vars : Dict [str , str ]
79+ clp_config : Dict [str , Any ],
80+ clp_config_file_path : Path ,
81+ clp_package_dir : Path ,
82+ env_vars : Dict [str , str ],
8083) -> bool :
8184 """
8285 Adds environment variables for CLP config values to `env_vars`.
8386
8487 :param clp_config:
88+ :param clp_config_file_path: Path to the file containing `clp_config`, for logging.
8589 :param clp_package_dir:
8690 :param env_vars:
8791 :return: Whether the environment variables were successfully added.
@@ -129,7 +133,7 @@ def _add_clp_env_vars(
129133 )
130134 )
131135
132- if not _add_clp_s3_env_vars (clp_config , env_vars ):
136+ if not _add_clp_s3_env_vars (clp_config , clp_config_file_path , env_vars ):
133137 return False
134138 else :
135139 logger .error (
@@ -147,46 +151,57 @@ def _add_clp_env_vars(
147151 with open (credentials_file_path , "r" ) as credentials_file :
148152 credentials = yaml .safe_load (credentials_file )
149153
150- database_user = _get_config_value (credentials , "database.user" )
151- database_password = _get_config_value (credentials , "database.password" )
152- if not database_user or not database_password :
153- logger .error (
154- "database.user and database.password must be specified in '%s'." , credentials_file_path
154+ try :
155+ database_user = _get_required_config_value (
156+ credentials , "database.user" , credentials_file_path
155157 )
158+ database_password = _get_required_config_value (
159+ credentials , "database.password" , credentials_file_path
160+ )
161+ except KeyError :
156162 return False
157163 env_vars ["PRESTO_COORDINATOR_CLPPROPERTIES_METADATA_DATABASE_USER" ] = database_user
158164 env_vars ["PRESTO_COORDINATOR_CLPPROPERTIES_METADATA_DATABASE_PASSWORD" ] = database_password
159165
160166 return True
161167
162168
163- def _add_clp_s3_env_vars (clp_config : Dict [str , Any ], env_vars : Dict [str , str ]) -> bool :
169+ def _add_clp_s3_env_vars (
170+ clp_config : Dict [str , Any ], clp_config_file_path : Path , env_vars : Dict [str , str ]
171+ ) -> bool :
164172 """
165173 Adds environment variables for CLP S3 config values to `env_vars`.
166174
167175 :param clp_config:
176+ :param clp_config_file_path: Path to the file containing `clp_config`, for logging.
168177 :param env_vars:
169178 :return: Whether the environment variables were successfully added.
170179 """
171180 try :
172181 s3_config_key = f"archive_output.storage.s3_config"
173- s3_bucket = _get_required_config_value (clp_config , f"{ s3_config_key } .bucket" )
174- s3_region_code = _get_required_config_value (clp_config , f"{ s3_config_key } .region_code" )
182+ s3_bucket = _get_required_config_value (
183+ clp_config , f"{ s3_config_key } .bucket" , clp_config_file_path
184+ )
185+ s3_region_code = _get_required_config_value (
186+ clp_config , f"{ s3_config_key } .region_code" , clp_config_file_path
187+ )
175188
176189 aws_auth_key = f"{ s3_config_key } .aws_authentication"
177190 aws_auth_type_key = f"{ aws_auth_key } .type"
178- aws_auth_type = _get_required_config_value (clp_config , aws_auth_type_key )
191+ aws_auth_type = _get_required_config_value (
192+ clp_config , aws_auth_type_key , clp_config_file_path
193+ )
179194 credentials_auth_type_str = "credentials"
180195 if credentials_auth_type_str != aws_auth_type :
181196 logger .error ("'%s' for %s is unsupported." , aws_auth_type , aws_auth_type_key )
182197 return False
183198
184199 s3_credentials_key = f"{ aws_auth_key } .{ credentials_auth_type_str } "
185200 s3_access_key_id = _get_required_config_value (
186- clp_config , f"{ s3_credentials_key } .access_key_id"
201+ clp_config , f"{ s3_credentials_key } .access_key_id" , clp_config_file_path
187202 )
188203 s3_secret_access_key = _get_required_config_value (
189- clp_config , f"{ s3_credentials_key } .secret_access_key"
204+ clp_config , f"{ s3_credentials_key } .secret_access_key" , clp_config_file_path
190205 )
191206 except KeyError :
192207 return False
@@ -279,18 +294,19 @@ def _get_path_clp_config_value(
279294 return clp_package_dir / value_as_path
280295
281296
282- def _get_required_config_value (config : Dict [str , Any ], key : str ) -> str :
297+ def _get_required_config_value (config : Dict [str , Any ], key : str , config_file_path : Path ) -> str :
283298 """
284299 Gets the value corresponding to `key` from `config`. Logs an error on failure.
285300
286301 :param config: The config.
287302 :param key: The key to look for in the config, in dot notation (e.g., "database.host").
303+ :param config_file_path: The path to the config file, for logging.
288304 :return: The value corresponding to `key`.
289305 :raises KeyError: If `key` doesn't exist in `config` or its value is `None`.
290306 """
291307 value = _get_config_value (config , key )
292308 if value is None :
293- logger .error ("Required config '%s' is missing or null." , key )
309+ logger .error ("Required config '%s' is missing or null in '%s' ." , key , config_file_path )
294310 raise KeyError (key )
295311 return value
296312
0 commit comments