Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add for loop thru nodes to apply_masking_policy_list_for_models.sql #67

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ vars:
| models | `dbt run -- model <model-name>` |
| snapshots | `dbt snapshot --select <snapshot-name> --target <target-name>` |

- Alternatively, you can also apply the masking policies by specifying below `post-hook` OR `on-run-end` to `dbt_project.yml`
- Alternatively, you can also apply the masking policies by specifying below `post-hook` to `dbt_project.yml`

**Example** : dbt_project.yml

Expand All @@ -192,12 +192,17 @@ vars:
- "{{ dbt_snow_mask.apply_masking_policy('snapshots') }}"
```

- If you prefer to add this directly to a dbt model, see below command for an correct example
- If you prefer to add this directly to a dbt model, see below command for a correct example

```yaml
{{ config(post_hook = "{{ dbt_snow_mask.apply_masking_policy('models') }}") }}
```

- Note: ```"{{ dbt_snow_mask.apply_masking_policy('sources') }}"``` can be added to ```on-run-end```, but
```"{{ dbt_snow_mask.apply_masking_policy('models') }}"``` and
```"{{ dbt_snow_mask.apply_masking_policy('snapshots') }}"``` should either be included specifically as post-hooks to
the models or snapshots sections of dbt_project.yml or added as a custom config to an individual model.

# How to remove masking policy ?

- Remove the masking policy applied by this package by running below commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{% if execute %}

{% if operation_type == "apply" %}

{% set model_id = model.unique_id | string %}
{% set alias = model.alias %}
{% set alias = model.alias %}
{% set database = model.database %}
{% set schema = model.schema %}
{% set model_resource_type = model.resource_type | string %}
Expand All @@ -23,7 +23,7 @@

{% set masking_policy_db = model.database %}
{% set masking_policy_schema = model.schema %}

{# Override the database and schema name when use_common_masking_policy_db flag is set #}
{%- if (var('use_common_masking_policy_db', 'False')|upper in ['TRUE','YES']) -%}
{% if (var('common_masking_policy_db') and var('common_masking_policy_schema')) %}
Expand All @@ -39,7 +39,7 @@
{% endif %}
{% endif %}

{% set masking_policy_list_sql %}
{% set masking_policy_list_sql %}
show masking policies in {{masking_policy_db}}.{{masking_policy_schema}};
select $3||'.'||$4||'.'||$2 as masking_policy from table(result_scan(last_query_id()));
{% endset %}
Expand All @@ -53,7 +53,7 @@
{% set column = meta_tuple[0] %}
{% set masking_policy_name = meta_tuple[1] %}
{% set conditional_columns = meta_tuple[2] %}

{% if masking_policy_name is not none %}

{% for masking_policy_in_db in masking_policy_list['MASKING_POLICY'] %}
Expand Down