-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related issue: #350
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
"BigQuery Airflow connection -> dbt profile mappings" | ||
|
||
from .service_account_file import GoogleCloudServiceAccountFileProfileMapping | ||
from .service_account_keyfile_dict import GoogleCloudServiceAccountDictProfileMapping | ||
|
||
__all__ = ["GoogleCloudServiceAccountFileProfileMapping"] | ||
__all__ = [ | ||
"GoogleCloudServiceAccountFileProfileMapping", | ||
"GoogleCloudServiceAccountDictProfileMapping", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"Maps Airflow GCP connections to dbt BigQuery profiles if they use a service account keyfile dict/json." | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from cosmos.profiles.base import BaseProfileMapping | ||
|
||
|
||
class GoogleCloudServiceAccountDictProfileMapping(BaseProfileMapping): | ||
""" | ||
Maps Airflow GCP connections to dbt BigQuery profiles if they use a service account keyfile dict/json. | ||
https://docs.getdbt.com/reference/warehouse-setups/bigquery-setup#service-account-file | ||
https://airflow.apache.org/docs/apache-airflow-providers-google/stable/connections/gcp.html | ||
""" | ||
|
||
airflow_connection_type: str = "google_cloud_platform" | ||
|
||
required_fields = [ | ||
"project", | ||
"dataset", | ||
"keyfile_dict", | ||
] | ||
|
||
airflow_param_mapping = { | ||
"project": "extra.project", | ||
"dataset": "dataset", | ||
# multiple options for keyfile_dict param name because of older Airflow versions | ||
"keyfile_dict": ["extra.keyfile_dict", "keyfile_dict", "extra__google_cloud_platform__keyfile_dict"], | ||
} | ||
|
||
@property | ||
def profile(self) -> dict[str, Any | None]: | ||
"""Generates profile. Defaults `threads` to 1.""" | ||
return { | ||
"type": "bigquery", | ||
"method": "service-account-json", | ||
"project": self.project, | ||
"dataset": self.dataset, | ||
"threads": self.profile_args.get("threads") or 1, | ||
"keyfile_json": self.keyfile_dict, | ||
**self.profile_args, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters