Skip to content

Commit

Permalink
Add parameter owner_integration_usage for schemas; Add future grant f…
Browse files Browse the repository at this point in the history
…or dynamic tables to schema owner roles
  • Loading branch information
littleK0i committed Jan 17, 2024
1 parent b4c395d commit 6ad193b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.23.1] - 2024-01-17

- Added `owner_integration_usage` parameter for `SCHEMA`. It grants usage privilege to schema owner role on integrations pre-configured outside SnowDDL.
- Added future grant on `DYNAMIC TABLES` for schema owner role. Previously this future grant was not implemented by Snowflake.

## [0.23.0] - 2024-01-16

- Added remaining parameters for `TASK`.
Expand Down
7 changes: 7 additions & 0 deletions snowddl/blueprint/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ class ObjectType(Enum):
"blueprint_cls": "FunctionBlueprint",
}

# Technical object type, used for GRANTs only
# There is no blueprint
INTEGRATION = {
"singular": "INTEGRATION",
"plural": "INTEGRATIONS",
}

MASKING_POLICY = {
"singular": "MASKING POLICY",
"plural": "MASKING POLICIES",
Expand Down
18 changes: 17 additions & 1 deletion snowddl/parser/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from snowddl.blueprint import SchemaBlueprint, SchemaIdent, Grant, ObjectType, build_role_ident
from snowddl.blueprint import SchemaBlueprint, SchemaIdent, Grant, ObjectType, Ident, build_role_ident
from snowddl.parser.abc_parser import AbstractParser
from snowddl.parser.database import database_json_schema

Expand Down Expand Up @@ -28,6 +28,12 @@
"type": "string"
}
},
"owner_integration_usage": {
"type": "array",
"items": {
"type": "string"
}
},
"comment": {
"type": "string"
}
Expand Down Expand Up @@ -69,6 +75,9 @@ def load_blueprints(self):
for full_schema_name in schema_params.get("owner_schema_write", []):
owner_additional_grants.append(self.build_schema_role_grant(full_schema_name, "WRITE"))

for integration_name in schema_params.get("owner_integration_usage", []):
owner_additional_grants.append(self.build_integration_usage_grant(integration_name))

bp = SchemaBlueprint(
full_name=SchemaIdent(self.env_prefix, database_path.name, schema_path.name),
is_transient=combined_params.get("is_transient", False),
Expand All @@ -88,3 +97,10 @@ def build_schema_role_grant(self, full_schema_name, grant_type):
on=ObjectType.ROLE,
name=build_role_ident(self.env_prefix, database, schema, grant_type, self.config.SCHEMA_ROLE_SUFFIX),
)

def build_integration_usage_grant(self, integration_name):
return Grant(
privilege="USAGE",
on=ObjectType.INTEGRATION,
name=Ident(integration_name),
)
1 change: 1 addition & 0 deletions snowddl/resolver/schema_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_blueprint_owner_role(self, schema_bp: SchemaBlueprint):
)

ownership_object_types = [
ObjectType.DYNAMIC_TABLE,
ObjectType.EXTERNAL_TABLE,
ObjectType.FILE_FORMAT,
ObjectType.FUNCTION,
Expand Down
2 changes: 1 addition & 1 deletion snowddl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.23.0"
__version__ = "0.23.1"
2 changes: 2 additions & 0 deletions test/_config/step1/db1/sc1/params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
owner_integration_usage:
- test_notification_integration
2 changes: 2 additions & 0 deletions test/_config/step2/db1/sc1/params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
owner_integration_usage:
- test_notification_integration

0 comments on commit 6ad193b

Please sign in to comment.