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

changes to add more examples for apply masking #44

Merged
merged 2 commits into from
Aug 12, 2022
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ This package was created using examples from [Serge](https://www.linkedin.com/in
# References
- https://docs.snowflake.com/en/user-guide/security-column-ddm-intro.html
- https://getdbt.slack.com/archives/CJN7XRF1B/p1609177817234800
- https://docs.snowflake.com/en/sql-reference/functions/policy_references.html
- https://docs.snowflake.com/en/user-guide/security-column-ddm-use.html

# Contributions
Contributions to this package are welcomed. Please create issues for bugs or feature requests for enhancement ideas or PRs for any enhancement contributions.
Expand Down
5 changes: 2 additions & 3 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ clean-targets:

seeds:
dbt_snow_mask_integration_tests:
sakila:
schema: raw_sakila
+schema: seeds

models:
pre-hook:
Expand All @@ -39,7 +38,7 @@ models:

dbt_snow_mask_integration_tests:
staging:
database: "DEV_ENTECHLOG_RAW_DB"
database: "DEV_ENTECHLOG_DEMO_DB"
schema: staging

on-run-start:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% macro create_masking_policy_mp_email(node_database,node_schema) %}

CREATE MASKING POLICY IF NOT EXISTS {{node_database}}.{{node_schema}}.mp_email AS (val string)
RETURNS string ->
CASE WHEN CURRENT_ROLE() IN ('SYSADMIN') THEN val
WHEN CURRENT_ROLE() IN ('DEVELOPER') THEN SHA2(val)
ELSE '**********'
END

{% endmacro %}
2 changes: 1 addition & 1 deletion integration_tests/models/sources/sakila/src_sakila.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2

sources:
- name: raw_sakila
- name: seeds
tables:
- name: customer
columns:
Expand Down
19 changes: 19 additions & 0 deletions integration_tests/models/staging/pii/stg_contacts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
WITH contacts AS (
SELECT
contact_id,
first_name,
last_name,
email,
gender,
ip_address,
ssn,phone

FROM {{ ref('contact') }}
),

final AS (
SELECT *
FROM contacts
)

SELECT * FROM final
27 changes: 27 additions & 0 deletions integration_tests/models/staging/pii/stg_contacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 2

models:
- name: stg_contacts
description: ""
columns:
- name: contact_id
description: ""
- name: first_name
description: ""
- name: last_name
description: ""
- name: email
description: "Email Address"
meta:
masking_policy: mp_email
- name: gender
description: ""

- name: ip_address
description: ""

- name: ssn
description: ""

- name: phone
description: ""
2 changes: 1 addition & 1 deletion integration_tests/models/staging/sakila/stg_customer.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
)
}}

SELECT * FROM {{ source('raw_sakila', 'customer') }}
SELECT * FROM {{ source('seeds', 'customer') }}
1,001 changes: 1,001 additions & 0 deletions integration_tests/seeds/pii/contact.csv

Large diffs are not rendered by default.