Skip to content

Commit

Permalink
Support roles in grants
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmeireles committed Jan 3, 2025
1 parent f5392a1 commit 7ae52d1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion dbt/include/dremio/macros/adapters/apply_grants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ limitations under the License.*/
{{ return(False) }}
{%- endmacro -%}

{%- macro dremio__split_grantee(grantee) -%}
{%- set splitted = grantee.split(':') %}
{%- if splitted | length == 2 %}
{%- set type = splitted[0] %}
{%- if type in ['user', 'role'] %}
{%- set name = splitted[1] %}
{%- else %}
{% do exceptions.CompilationError("Invalid prefix. Use either user or role") %}
{%- endif %}
{%- else %}
{%- set type = 'user' %}
{%- set name = grantee %}
{%- endif %}

{{ return((type, name)) }}
{%- endmacro -%}

{% macro dremio__get_show_grant_sql(relation) %}
{%- if relation.type == 'table' -%}
{%- set relation_without_double_quotes = target.datalake ~ '.' ~ target.root_path ~ '.' ~ relation.identifier-%}
Expand All @@ -36,7 +53,10 @@ limitations under the License.*/
{% endmacro %}

{%- macro dremio__get_grant_sql(relation, privilege, grantees) -%}
grant {{ privilege }} on {{relation.type}} {{ relation }} to user {{adapter.quote(grantees[0])}}
{%- set type, name = dremio__split_grantee(grantees[0]) %}

grant {{ privilege }} on {{ relation.type }} {{ relation }}
to {{ type }} {{ adapter.quote(name) }}
{%- endmacro -%}

{%- macro default__get_revoke_sql(relation, privilege, grantees) -%}
Expand Down

0 comments on commit 7ae52d1

Please sign in to comment.