-
Notifications
You must be signed in to change notification settings - Fork 177
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
Add database role support #1207
Open
seediang
wants to merge
6
commits into
dbt-labs:main
Choose a base branch
from
seediang:feature/1206-databases-roles-alternative
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc32f1e
Initial version to support database roles
seediang f346d62
Pass apply_grants.py tests
seediang 44563c1
Drop unrequired split_grants_by_grantee_type macro
seediang c2b6847
Add tests based on dbt-adapters tests
seediang 1f544a4
Merge branch 'main' into feature/1206-databases-roles-alternative
seediang c1a769d
Merge branch 'main' into feature/1206-databases-roles-alternative
seediang 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 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,6 @@ | ||
kind: Features | ||
body: Support granting of Database Roles | ||
time: 2024-10-12T11:58:30.84775252+01:00 | ||
custom: | ||
Author: seediang | ||
Issue: "1206" |
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
Empty file.
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,67 @@ | ||
import os | ||
import pytest | ||
import snowflake.connector | ||
from dbt.tests.adapter.grants.base_grants import BaseGrants as OrigBaseGrants | ||
|
||
|
||
class BaseGrantsSnowflakePatch: | ||
""" | ||
Overides the adapter BaseGrants to use new adapter functions | ||
for grants. | ||
""" | ||
|
||
def assert_expected_grants_match_actual(self, project, relation_name, expected_grants): | ||
adapter = project.adapter | ||
actual_grants = self.get_grants_on_relation(project, relation_name) | ||
expected_grants_std = adapter.standardize_grant_config(expected_grants) | ||
|
||
# need a case-insensitive comparison -- this would not be true for all adapters | ||
# so just a simple "assert expected == actual_grants" won't work | ||
diff_a = adapter.diff_of_grants(actual_grants, expected_grants_std) | ||
diff_b = adapter.diff_of_grants(expected_grants_std, actual_grants) | ||
assert diff_a == diff_b == {} | ||
|
||
|
||
class BaseGrantsSnowflake(BaseGrantsSnowflakePatch, OrigBaseGrants): | ||
@pytest.fixture(scope="session", autouse=True) | ||
def ensure_database_roles(project): | ||
""" | ||
We need to create database roles since test framework does not | ||
have default database roles to work with. This has been patched | ||
in with ta session scoped fixture and custom connection. | ||
""" | ||
con = snowflake.connector.connect( | ||
user=os.getenv("SNOWFLAKE_TEST_USER"), | ||
password=os.getenv("SNOWFLAKE_TEST_PASSWORD"), | ||
account=os.getenv("SNOWFLAKE_TEST_ACCOUNT"), | ||
warehouse=os.getenv("SNOWFLAKE_TEST_WAREHOUSE"), | ||
database=os.getenv("SNOWFLAKE_TEST_DATABASE"), | ||
) | ||
|
||
number_of_roles = 3 | ||
|
||
for index in range(1, number_of_roles + 1): | ||
con.execute_string(f"CREATE DATABASE ROLE IF NOT EXISTS test_database_role_{index}") | ||
|
||
yield | ||
|
||
for index in range(1, number_of_roles + 1): | ||
con.execute_string(f"DROP DATABASE ROLE test_database_role_{index}") | ||
|
||
|
||
class BaseCopyGrantsSnowflake: | ||
# Try every test case without copy_grants enabled (default), | ||
# and with copy_grants enabled (this base class) | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"models": { | ||
"+copy_grants": True, | ||
}, | ||
"seeds": { | ||
"+copy_grants": True, | ||
}, | ||
"snapshots": { | ||
"+copy_grants": True, | ||
}, | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To allow tests that use database_roles, this fixture has been added at session level to create 3 database roles in a similar style to the account-level roles that exist in the testing framework.