Open Chobsz opened 2 years ago
I've edited the code to allow for the following post hooks in the project file to process only the relevant maskingpolicies on a run task.
+post-hook: "{{ dbt_snow_mask.apply_masking_policy('models','mymodelname')}}" +post-hook: "{{ dbt_snow_mask.apply_masking_policy('sources','mysourcename')}}"
{% macro apply_masking_policy(resource_type="models",resource_name="undefined",meta_key="masking_policy") %} {% if execute %} {% if resource_type == "sources" and resource_name == "undefined" %} {{ dbt_snow_mask.apply_masking_policy_list_for_sources(meta_key) }} {% elif resource_type == "models" and resource_name == "undefined" %} {{ dbt_snow_mask.apply_masking_policy_list_for_models(meta_key) }} {% elif resource_type == "sources" and resource_name != "undefined" %} {{ dbt_snow_mask.apply_masking_policy_list_for_onesource(meta_key,resource_name) }} {% elif resource_type == "models" and resource_name != "undefined" %} {{ dbt_snow_mask.apply_masking_policy_list_for_onemodel(meta_key,resource_name) }} {% endif %} {% endif %} {% endmacro %}
% macro apply_masking_policy_list_for_onesource(meta_key,resource_name,operation_type="apply") %} {% for node in graph.sources.values() -%} {%- if node.source_name == resource_name -%} [...]
-- New macro: [apply_masking_policy_list_for_onemodel] (95% the old macro apply_masking_policy_list_for_models) --Most important change:
{% macro apply_masking_policy_list_for_onemodel(meta_key,resource_name,operation_type="apply") %} {%set resource_name = '/'+ resource_name +'/' %} {% if operation_type == "apply" %} {% for node in graph.nodes.values() %} {%- if resource_name in node.path -%} [...]
If you need the whole code, I created a PullRequest
created PR 41, let me know if you need anything.
created PR #58, hope it meets standards. however the whole thing could have been done wth DRY, but my Jinja is just nog up to par.
41
I've edited the code to allow for the following post hooks in the project file to process only the relevant maskingpolicies on a run task.
-- Altered macro: [apply_masking_policy] (50% the old macro)
-- New macro: [apply_masking_policy_list_for_onesource] (95% the old macro apply_masking_policy_list_for_sources) --Most important change:
-- New macro: [apply_masking_policy_list_for_onemodel] (95% the old macro apply_masking_policy_list_for_models) --Most important change:
If you need the whole code, I created a PullRequest