Skip to content

Commit 19de71e

Browse files
authored
[BUGFIX] share ownership (#151)
* Support share with custom owner --------- Co-authored-by: TJ Murphy <[email protected]>
1 parent d7780fc commit 19de71e

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

tests/integration/test_blueprint.py

+16
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,19 @@ def test_blueprint_split_role_user(cursor):
591591
cursor.execute("DROP USER IF EXISTS SPLIT_ROLE_USER")
592592
cursor.execute("DROP ROLE IF EXISTS SPLIT_ROLE_A")
593593
cursor.execute("DROP ROLE IF EXISTS SPLIT_ROLE_B")
594+
595+
596+
def test_blueprint_share_custom_owner(cursor, suffix):
597+
session = cursor.connection
598+
share_name = f"TEST_SHARE_CUSTOM_OWNER_{suffix}"
599+
share = res.Share(name=share_name, owner="TITAN_SHARE_ADMIN")
600+
601+
try:
602+
blueprint = Blueprint(resources=[share])
603+
plan = blueprint.plan(session)
604+
assert len(plan) == 1
605+
assert isinstance(plan[0], CreateResource)
606+
assert plan[0].urn.fqn.name == share_name
607+
blueprint.apply(session, plan)
608+
finally:
609+
cursor.execute(f"DROP SHARE IF EXISTS {share_name}")

tests/test_blueprint_ownership.py

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
)
1212
from titan.enums import AccountEdition
1313
from titan.identifiers import parse_URN
14-
from titan.privs import AccountPriv, GrantedPrivilege
1514
from titan.resource_name import ResourceName
1615

1716

titan/blueprint.py

+7
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,13 @@ def execution_strategy_for_change(
10521052
elif isinstance(change, CreateResource):
10531053
if isinstance(change.resource_cls.scope, AccountScope):
10541054
create_priv = CREATE_PRIV_FOR_RESOURCE_TYPE[change.urn.resource_type]
1055+
1056+
# SHARE ownership cannot be changed
1057+
if change.urn.resource_type == ResourceType.SHARE:
1058+
if change_owner is None:
1059+
raise RuntimeError
1060+
return change_owner, False
1061+
10551062
system_role = system_role_for_priv(create_priv)
10561063
if system_role and system_role in available_roles:
10571064
transfer_ownership = system_role != change_owner

tools/test_account_configs/base.yml

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ roles:
7878
comment: This role has every privilege
7979
- name: TITAN_GRANT_ADMIN
8080
comment: This role has MANAGE GRANTS privileges
81+
- name: TITAN_SHARE_ADMIN
82+
comment: This role has CREATE SHARE privilege
8183

8284
databases:
8385
- name: static_database
@@ -103,6 +105,9 @@ role_grants:
103105
- role: TITAN_GRANT_ADMIN
104106
roles:
105107
- SYSADMIN
108+
- role: TITAN_SHARE_ADMIN
109+
roles:
110+
- SYSADMIN
106111

107112
# database_role_grants:
108113
# - role: static_database_role
@@ -134,6 +139,9 @@ grants:
134139
# TITAN_GRANT_ADMIN grants
135140
- GRANT MANAGE GRANTS ON ACCOUNT TO ROLE TITAN_GRANT_ADMIN
136141

142+
# TITAN_SHARE_ADMIN grants
143+
- GRANT CREATE SHARE ON ACCOUNT TO ROLE TITAN_SHARE_ADMIN
144+
137145
# CI grants
138146
- GRANT USAGE ON WAREHOUSE STATIC_WAREHOUSE TO ROLE CI
139147
- GRANT USAGE ON DATABASE static_database TO ROLE CI

0 commit comments

Comments
 (0)