in data_validation/clients.py [0:0]
def get_data_client(connection_config):
"""Return DataClient client from given configuration"""
connection_config = copy.deepcopy(connection_config)
source_type = connection_config.pop(consts.SOURCE_TYPE)
secret_manager_type = connection_config.pop(consts.SECRET_MANAGER_TYPE, None)
secret_manager_project_id = connection_config.pop(
consts.SECRET_MANAGER_PROJECT_ID, None
)
decrypted_connection_config = {}
if secret_manager_type is not None:
sm = SecretManagerBuilder().build(secret_manager_type.lower())
for config_item in connection_config:
decrypted_connection_config[config_item] = sm.maybe_secret(
secret_manager_project_id, connection_config[config_item]
)
else:
decrypted_connection_config = connection_config
# The ibis_bigquery.connect expects a credentials object, not a string.
if consts.GOOGLE_SERVICE_ACCOUNT_KEY_PATH in decrypted_connection_config:
key_path = decrypted_connection_config.pop(
consts.GOOGLE_SERVICE_ACCOUNT_KEY_PATH
)
if key_path:
decrypted_connection_config[
"credentials"
] = google.oauth2.service_account.Credentials.from_service_account_file(
key_path
)
if source_type not in CLIENT_LOOKUP:
msg = 'ConfigurationError: Source type "{source_type}" is not supported'.format(
source_type=source_type
)
raise Exception(msg)
try:
data_client = CLIENT_LOOKUP[source_type](**decrypted_connection_config)
data_client._source_type = source_type
except Exception as e:
msg = 'Connection Type "{source_type}" could not connect: {error}'.format(
source_type=source_type, error=str(e)
)
raise exceptions.DataClientConnectionFailure(msg)
return data_client