|
16 | 16 | # under the License. |
17 | 17 |
|
18 | 18 | """Objects relating to sourcing connections from Google Cloud Secrets Manager""" |
| 19 | +import logging |
19 | 20 | from typing import Optional |
20 | 21 |
|
21 | 22 | try: |
22 | 23 | from functools import cached_property |
23 | 24 | except ImportError: |
24 | 25 | from cached_property import cached_property |
25 | 26 |
|
| 27 | +from google.auth.exceptions import DefaultCredentialsError |
| 28 | + |
26 | 29 | from airflow.exceptions import AirflowException |
27 | 30 | from airflow.providers.google.cloud._internal_client.secret_manager_client import _SecretManagerClient |
28 | 31 | from airflow.providers.google.cloud.utils.credentials_provider import get_credentials_and_project_id |
29 | 32 | from airflow.secrets import BaseSecretsBackend |
30 | 33 | from airflow.utils.log.logging_mixin import LoggingMixin |
31 | 34 |
|
| 35 | +log = logging.getLogger(__name__) |
| 36 | + |
32 | 37 | SECRET_ID_PATTERN = r"^[a-zA-Z0-9-_]*$" |
33 | 38 |
|
34 | 39 |
|
@@ -101,9 +106,17 @@ def __init__( |
101 | 106 | "`connections_prefix`, `variables_prefix` and `sep` should " |
102 | 107 | f"follows that pattern {SECRET_ID_PATTERN}" |
103 | 108 | ) |
104 | | - self.credentials, self.project_id = get_credentials_and_project_id( |
105 | | - keyfile_dict=gcp_keyfile_dict, key_path=gcp_key_path, scopes=gcp_scopes |
106 | | - ) |
| 109 | + try: |
| 110 | + self.credentials, self.project_id = get_credentials_and_project_id( |
| 111 | + keyfile_dict=gcp_keyfile_dict, key_path=gcp_key_path, scopes=gcp_scopes |
| 112 | + ) |
| 113 | + except (DefaultCredentialsError, FileNotFoundError): |
| 114 | + log.exception( |
| 115 | + 'Unable to load credentials for GCP Secret Manager. ' |
| 116 | + 'Make sure that the keyfile path, dictionary, or GOOGLE_APPLICATION_CREDENTIALS ' |
| 117 | + 'environment variable is correct and properly configured.' |
| 118 | + ) |
| 119 | + |
107 | 120 | # In case project id provided |
108 | 121 | if project_id: |
109 | 122 | self.project_id = project_id |
|
0 commit comments