diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 24d1c284..ee976927 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -29,6 +29,7 @@ * [GenericSecret](resources/generic_secret.md) * [GlueCatalogIntegration](resources/glue_catalog_integration.md) * [Grant](resources/grant.md) +* [GrantOnAll](resources/grant_on_all.md) * [HybridTable](resources/hybrid_table.md) * [ImageRepository](resources/image_repository.md) * [InternalStage](resources/internal_stage.md) diff --git a/docs/resources/grant_on_all.md b/docs/resources/grant_on_all.md new file mode 100644 index 00000000..8816dc32 --- /dev/null +++ b/docs/resources/grant_on_all.md @@ -0,0 +1,62 @@ +--- +description: >- + +--- + +# GrantOnAll + +[Snowflake Documentation](https://docs.snowflake.com/en/sql-reference/sql/grant-privilege) + +Represents a grant of privileges on all resources of a specified type to a role in Snowflake. + + +## Examples + +### Python + +```python + # Schema Privs: + grant_on_all = GrantOnAll( + priv="CREATE TABLE", + on_all_schemas_in_database="somedb", + to="somerole", + ) + grant_on_all = GrantOnAll( + priv="CREATE VIEW", + on_all_schemas_in=Database(name="somedb"), + to="somerole", + ) + # Schema Object Privs: + grant_on_all = GrantOnAll( + priv="SELECT", + on_all_tables_in_schema="someschema", + to="somerole", + ) + grant_on_all = GrantOnAll( + priv="SELECT", + on_all_views_in_database="somedb", + to="somerole", + ) +``` + + +### YAML + +```yaml +grants_on_all: + - priv: SELECT + on_all_tables_in_schema: someschema + to: somerole +``` + + +## Fields + +* `priv` (string, required) - The privilege to grant. Examples include 'SELECT', 'INSERT', 'CREATE TABLE'. +* `on_type` (string or [ResourceType](resource_type.md), required) - The type of resource on which the privileges are granted. +* `in_type` (string or [ResourceType](resource_type.md), required) - The type of container resource in which the privilege is granted. +* `in_name` (string, required) - The name of the container resource in which the privilege is granted. +* `to` (string or [Role](role.md), required) - The role to which the privileges are granted. +* `grant_option` (bool) - Specifies whether the grantee can grant the privileges to other roles. Defaults to False. + + diff --git a/titan/resources/grant.py b/titan/resources/grant.py index 8e7be2ac..a7327f93 100644 --- a/titan/resources/grant.py +++ b/titan/resources/grant.py @@ -435,6 +435,62 @@ def __post_init__(self): class GrantOnAll(Resource): + """ + Description: + Represents a grant of privileges on all resources of a specified type to a role in Snowflake. + + Snowflake Docs: + https://docs.snowflake.com/en/sql-reference/sql/grant-privilege + + Fields: + priv (string, required): The privilege to grant. Examples include 'SELECT', 'INSERT', 'CREATE TABLE'. + on_type (string or ResourceType, required): The type of resource on which the privileges are granted. + in_type (string or ResourceType, required): The type of container resource in which the privilege is granted. + in_name (string, required): The name of the container resource in which the privilege is granted. + to (string or Role, required): The role to which the privileges are granted. + grant_option (bool): Specifies whether the grantee can grant the privileges to other roles. Defaults to False. + + Python: + + ```python + # Schema Privs: + grant_on_all = GrantOnAll( + priv="CREATE TABLE", + on_all_schemas_in_database="somedb", + to="somerole", + ) + + grant_on_all = GrantOnAll( + priv="CREATE VIEW", + on_all_schemas_in=Database(name="somedb"), + to="somerole", + ) + + # Schema Object Privs: + grant_on_all = GrantOnAll( + priv="SELECT", + on_all_tables_in_schema="someschema", + to="somerole", + ) + + grant_on_all = GrantOnAll( + priv="SELECT", + on_all_views_in_database="somedb", + to="somerole", + ) + ``` + + Yaml: + + ```yaml + grants_on_all: + - priv: SELECT + on_all_tables_in_schema: someschema + to: somerole + ``` + + """ + resource_type = ResourceType.GRANT_ON_ALL props = Props( priv=IdentifierProp("priv", eq=False), @@ -454,19 +510,6 @@ def __init__( grant_option: bool = False, **kwargs, ): - """ - Usage - ----- - - Schema Privs: - >>> GrantOnAll(priv="CREATE TABLE", on_all_schemas_in_database="somedb", to="somerole") - >>> GrantOnAll(priv="CREATE VIEW", on_all_schemas_in=Database(name="somedb"), to="somerole") - - Schema Object Privs: - >>> GrantOnAll(priv="SELECT", on_all_tables_in_schema="sch", to="somerole") - >>> GrantOnAll(priv="SELECT", on_all_views_in_database="somedb", to="somerole") - - """ on_type = kwargs.pop("on_type", None) in_type = kwargs.pop("in_type", None) in_name = kwargs.pop("in_name", None)