All pages
1 of 1

Loading...

Can I Add a New Masking Rule?

How to Create A New Masking Rule

CS:Govern Masking Rules are implemented as custom database functions and are persisted in the GovernMaskingRule table in a CopyStorm database.

The procedure to create a new Masking Rule is:

  • Review the code of an existing Masking Rule in your database.

  • Write and test SQL code for a new Masking Rule.

  • Insert a new record into the CS:Govern Masking Rule control table.

Example: Create Reverse Masking Rule

In this example, create a new masking rule which masks data by reversing its characters (e.g. ABC become CBA).

The follow code for SQL/Server was developed by looking at an existing masking rule.

CREATE OR ALTER  FUNCTION [dbo].[guard_mask_to_reverse]( @original NVARCHAR(MAX) ) RETURNS NVARCHAR(MAX)
AS
BEGIN
    IF @original IS NULL RETURN NULL;
    IF @original = '' RETURN '';
    RETURN REVERSE(@original)
END;

After installing the new function into the database, the next step is to teach CS:Govern about the new Masking Rule.

BEGIN
	DECLARE @id INT;
	DECLARE @templateRuleId INT;
	DECLARE @now DATETIME;

--
-- Insert a top level masking rule.
--
	INSERT INTO GuardianMaskingRule(name,functionName,isActive,createdDate,modifiedDate)
		VALUES( 'Reverse', 'guard_mask_to_reverse([[VALUE]])', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
	;

--
-- Pick an existing rule which works on the same field types as the new rule.
-- Find the unique id assigned to the new rule.
--
	SELECT @templateRuleId=id FROM GuardianMaskingRule WHERE name='Asterisks';
	SELECT @id=id, @now=createdDate FROM GuardianMaskingRule WHERE name='Reverse';

--
-- Register the type of Salesforce fields supported by the masking rule.
--
	INSERT INTO GuardianMaskingRuleFieldType(fieldTypeName, maskingRuleId
		, createdDate, modifiedDate)
		SELECT fieldTypeName, @id, @now, @now 
          FROM GuardianMaskingRuleFieldType
          WHERE maskingRuleId = @templateRuleId;

END;

Restart the CS:Govern GUI and the new Reverse masking rule will be available.