-
Notifications
You must be signed in to change notification settings - Fork 312
Refactor LoadMethod.LOCAL to use symlinks instead of copying directory #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tatiana
merged 22 commits into
astronomer:main
from
jbandoro:use-symlinks-local-operator
Nov 14, 2023
Merged
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ca65d10
Intial change for Snowflake encrypted private key
DanMawdsleyBA 32c7f3d
Updating test description
DanMawdsleyBA ba8af7d
Work around for user/password mapping
DanMawdsleyBA c5668a7
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] feaae3e
Adding conditions on claiming connections
DanMawdsleyBA 6c8ec36
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] 8d95a49
Updating import on tests
DanMawdsleyBA 643f03f
Or condition for user pass
DanMawdsleyBA 0734166
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] 8f46b55
Adding private key to env test
DanMawdsleyBA 188fe56
Fixing typo
DanMawdsleyBA 9cd46d2
Add `operator_args` `full_refresh` as a templated field (#623)
joppevos 006b961
refactor: LoadMethod.LOCAL to use symlinks instead of copying directory
949e076
rm comment for copying
8e9e581
Merge branch 'main' into use-symlinks-local-operator
jbandoro 673a977
Merge branch 'main' into use-symlinks-local-operator
tatiana cc02e2c
move to from generic utils to dbt.project module
117cb77
move imdb file out of simple project
dfe264b
fix main schema so doesn't conflict with imdb
543e0dd
update main schema from imdb
1460b9d
Merge branch 'main' into use-symlinks-local-operator
jbandoro a9e69fe
Merge branch 'main' into use-symlinks-local-operator
tatiana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
93 changes: 93 additions & 0 deletions
93
cosmos/profiles/snowflake/user_encrypted_privatekey_env_variable.py
This file contains hidden or 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,93 @@ | ||
| "Maps Airflow Snowflake connections to dbt profiles if they use a user/private key." | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from ..base import BaseProfileMapping | ||
|
|
||
| if TYPE_CHECKING: | ||
| from airflow.models import Connection | ||
|
|
||
|
|
||
| class SnowflakeEncryptedPrivateKeyPemProfileMapping(BaseProfileMapping): | ||
| """ | ||
| Maps Airflow Snowflake connections to dbt profiles if they use a user/private key. | ||
| https://docs.getdbt.com/docs/core/connect-data-platform/snowflake-setup#key-pair-authentication | ||
| https://airflow.apache.org/docs/apache-airflow-providers-snowflake/stable/connections/snowflake.html | ||
| """ | ||
|
|
||
| airflow_connection_type: str = "snowflake" | ||
| dbt_profile_type: str = "snowflake" | ||
| is_community: bool = True | ||
|
|
||
| required_fields = [ | ||
| "account", | ||
| "user", | ||
| "database", | ||
| "warehouse", | ||
| "schema", | ||
| "private_key", | ||
| "private_key_passphrase", | ||
| ] | ||
| secret_fields = [ | ||
| "private_key", | ||
| "private_key_passphrase", | ||
| ] | ||
| airflow_param_mapping = { | ||
| "account": "extra.account", | ||
| "user": "login", | ||
| "database": "extra.database", | ||
| "warehouse": "extra.warehouse", | ||
| "schema": "schema", | ||
| "role": "extra.role", | ||
| "private_key": "extra.private_key_content", | ||
| "private_key_passphrase": "password", | ||
| } | ||
|
|
||
| def can_claim_connection(self) -> bool: | ||
| # Make sure this isn't a private key path credential | ||
| result = super().can_claim_connection() | ||
| if result and self.conn.extra_dejson.get("private_key_file") is not None: | ||
| return False | ||
| return result | ||
|
|
||
| @property | ||
| def conn(self) -> Connection: | ||
| """ | ||
| Snowflake can be odd because the fields used to be stored with keys in the format | ||
| 'extra__snowflake__account', but now are stored as 'account'. | ||
|
|
||
| This standardizes the keys to be 'account', 'database', etc. | ||
| """ | ||
| conn = super().conn | ||
|
|
||
| conn_dejson = conn.extra_dejson | ||
|
|
||
| if conn_dejson.get("extra__snowflake__account"): | ||
| conn_dejson = {key.replace("extra__snowflake__", ""): value for key, value in conn_dejson.items()} | ||
|
|
||
| conn.extra = json.dumps(conn_dejson) | ||
|
|
||
| return conn | ||
|
|
||
| @property | ||
| def profile(self) -> dict[str, Any | None]: | ||
| "Gets profile." | ||
| profile_vars = { | ||
| **self.mapped_params, | ||
| **self.profile_args, | ||
| "private_key": self.get_env_var_format("private_key"), | ||
| "private_key_passphrase": self.get_env_var_format("private_key_passphrase"), | ||
| } | ||
|
|
||
| # remove any null values | ||
| return self.filter_null(profile_vars) | ||
|
|
||
| def transform_account(self, account: str) -> str: | ||
| "Transform the account to the format <account>.<region> if it's not already." | ||
| region = self.conn.extra_dejson.get("region") | ||
| if region and region not in account: | ||
| account = f"{account}.{region}" | ||
|
|
||
| return str(account) |
This file contains hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| from pathlib import Path | ||
| import os | ||
| from cosmos.constants import ( | ||
| DBT_LOG_DIR_NAME, | ||
| DBT_TARGET_DIR_NAME, | ||
| ) | ||
|
|
||
|
|
||
| def create_symlinks(project_path: Path, tmp_dir: Path) -> None: | ||
| """Helper function to create symlinks to the dbt project files.""" | ||
| ignore_paths = (DBT_LOG_DIR_NAME, DBT_TARGET_DIR_NAME, "dbt_packages", "profiles.yml") | ||
| for child_name in os.listdir(project_path): | ||
| if child_name not in ignore_paths: | ||
| os.symlink(project_path / child_name, tmp_dir / child_name) | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.