moiseenkov commented on code in PR #39873: URL: https://github.com/apache/airflow/pull/39873#discussion_r1633349736
########## airflow/providers/google/cloud/utils/credentials_provider.py: ########## @@ -426,3 +459,38 @@ def _get_project_id_from_service_account_email(service_account_email: str) -> st raise AirflowException( f"Could not extract project_id from service account's email: {service_account_email}." ) + + +def _get_info_from_credential_configuration_file( + credential_configuration_file: str | dict[str, str], +) -> dict[str, str]: + """ + Extract the Credential Configuration File information, either from a json file, json string or dictionary. + + :param credential_configuration_file: File path or content (as json string or dictionary) of a GCP credential configuration file. + + :return: Returns a dictionary containing the Credential Configuration File information. + """ + # if it's already a dict, just return it + if isinstance(credential_configuration_file, dict): + return credential_configuration_file + + if not isinstance(credential_configuration_file, str): + raise AirflowException( + f"Invalid argument type, expected str or dict, got {type(credential_configuration_file)}." + ) + + if os.path.exists(credential_configuration_file): # attempts to load from json file + with open(credential_configuration_file) as file_obj: + try: + return json.load(file_obj) + except ValueError: + raise AirflowException( + f"Credential Configuration File '{credential_configuration_file}' is not a valid json file." + ) + + # if not a file, attempt to load it from a json string + try: + return json.loads(credential_configuration_file) + except ValueError: + raise AirflowException("Credential Configuration File is not a valid json string.") Review Comment: Could you please double-check if credentials can come as a string (not a file path)? If not, we probably don't need this block of code. ########## airflow/providers/google/cloud/utils/credentials_provider.py: ########## @@ -350,6 +365,24 @@ def _get_credentials_using_credential_config_file(self): return credentials, project_id + def _get_credentials_using_credential_config_file_and_token_supplier(self): + self._log_info( + "Getting connection using credential configuration file and external Identity Provider." + ) + + if not self.credential_config_file: + raise AirflowException( + "Credential configuration is needed to use authentication by External Identity Provider." + ) Review Comment: Sorry, but this comment isn't addressed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org