-
Notifications
You must be signed in to change notification settings - Fork 238
/
Copy pathapply_grants.sql
52 lines (45 loc) · 1.87 KB
/
apply_grants.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{% macro spark__copy_grants() %}
{% if config.materialized == 'view' %}
{#-- Spark views don't copy grants when they're replaced --#}
{{ return(False) }}
{% else %}
{#-- This depends on how we're replacing the table, which depends on its file format
-- Just play it safe by assuming that grants have been copied over, and need to be checked / possibly revoked
-- We can make this more efficient in the future
#}
{{ return(True) }}
{% endif %}
{% endmacro %}
{%- macro spark__get_grant_sql(relation, grant_config) -%}
{%- set grant_statements = [] -%}
{%- for privilege in grant_config.keys() %}
{%- set grantees = grant_config[privilege] -%}
{%- for grantee in grantees -%}
{% set grant_sql -%}
grant {{ privilege }} on {{ relation }} to {{ adapter.quote(grantee) }}
{%- endset %}
{%- do grant_statements.append(grant_sql) -%}
{% endfor -%}
{%- endfor -%}
{{ return(grant_statements) }}
{%- endmacro %}
{%- macro spark__get_revoke_sql(relation, grant_config) -%}
{%- set revoke_statements = [] -%}
{%- for privilege in grant_config.keys() %}
{%- set grantees = grant_config[privilege] -%}
{%- for grantee in grantees -%}
{% set grant_sql -%}
revoke {{ privilege }} on {{ relation }} from {{ adapter.quote(grantee) }}
{%- endset %}
{%- do revoke_statements.append(grant_sql) -%}
{% endfor -%}
{%- endfor -%}
{{ return(revoke_statements) }}
{%- endmacro %}
{% macro spark__call_grant_revoke_statement_list(grant_and_revoke_statement_list) %}
{% for grant_or_revoke_statement in grant_and_revoke_statement_list %}
{% call statement('grant_or_revoke') %}
{{ grant_or_revoke_statement }}
{% endcall %}
{% endfor %}
{% endmacro %}