Merge pull request #21 from sacheinbaala/users/baala/fix_issue#12

Allow partial masking of an attribute value from left or right with given text
This commit is contained in:
Kranthi Kumar Medam 2020-04-28 10:49:27 +05:30 коммит произвёл GitHub
Родитель ff509a4b83 48cf2bdca6
Коммит ade9d523de
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 56 добавлений и 11 удалений

Просмотреть файл

@ -258,7 +258,8 @@ namespace CosmicCloneUI
{
//check comobox status based on it change visibility of scrubvalue stack panel
var cbox = (ComboBox)sender;
if (cbox.SelectedValue.ToString().Equals(RuleType.SingleValue.ToString()))
var scrubType = cbox.SelectedValue.ToString();
if (scrubType == RuleType.SingleValue.ToString() || scrubType == RuleType.PartialMaskFromLeft.ToString() || scrubType == RuleType.PartialMaskFromRight.ToString())
{
var parentPanel = (StackPanel)cbox.Parent;
var gpPanel = (StackPanel)parentPanel.Parent;

Просмотреть файл

@ -38,5 +38,5 @@ namespace CosmosCloneCommon.Model
}
public enum RuleType { SingleValue, NullValue, Shuffle };//Can add random rule type later if required.
}
public enum RuleType { SingleValue, NullValue, Shuffle, PartialMaskFromLeft, PartialMaskFromRight };//Can add random rule type later if required.
}

Просмотреть файл

@ -16,13 +16,13 @@ namespace CosmosCloneCommon.Utility
//var scrubbedObjects = new List<string>();
var scrubbedObjects = new List<JToken>();
var propNames = scrubRule.PropertyName.Split('.').ToList();
if(scrubRule.Type == RuleType.NullValue || scrubRule.Type == RuleType.SingleValue)
if(scrubRule.Type == RuleType.NullValue || scrubRule.Type == RuleType.SingleValue || scrubRule.Type == RuleType.PartialMaskFromLeft || scrubRule.Type == RuleType.PartialMaskFromRight)
{
foreach (var strObj in srcList)
{
try
{
JToken jToken = GetUpdatedJsonArrayValue((JToken)JObject.Parse(strObj), propNames, scrubRule.UpdateValue);
JToken jToken = GetUpdatedJsonArrayValue((JToken)JObject.Parse(strObj), propNames, scrubRule.UpdateValue, scrubRule.Type);
scrubbedObjects.Add(jToken);
}
catch(Exception ex)
@ -205,7 +205,7 @@ namespace CosmosCloneCommon.Utility
return jTokenResult;
}
public JToken GetUpdatedJsonArrayValue(JToken token, List<string> propNames, string overwritevalue)
public JToken GetUpdatedJsonArrayValue(JToken token, List<string> propNames, string overwritevalue, RuleType? ruleType)
{
if (token == null || token.Type == JTokenType.Null) return null;
@ -227,7 +227,7 @@ namespace CosmosCloneCommon.Utility
{
if (jArray[k][currentProperty] != null && jArray[k][currentProperty].Type != JTokenType.Null)
{
jArray[k][currentProperty] = overwritevalue;
jArray[k][currentProperty] = ScrubTokenValue(ruleType, jArray[k][currentProperty], overwritevalue);
}
continue;
}
@ -235,7 +235,7 @@ namespace CosmosCloneCommon.Utility
{
if (jArray[k] != null && jArray[k][currentProperty].Type != JTokenType.Null)
{
jArray[k] = GetUpdatedJsonArrayValue(jArray[k], propNames.GetRange(1, propNames.Count - 1), overwritevalue);
jArray[k] = GetUpdatedJsonArrayValue(jArray[k], propNames.GetRange(1, propNames.Count - 1), overwritevalue, ruleType);
continue;
}
//else return null;
@ -251,14 +251,14 @@ namespace CosmosCloneCommon.Utility
{
if (jObj[currentProperty] != null && jObj[currentProperty].Type != JTokenType.Null)
{
jObj[currentProperty] = overwritevalue;
jObj[currentProperty] = ScrubTokenValue(ruleType, jObj[currentProperty], overwritevalue);
}
}
else
{
if (jObj[currentProperty] != null && jObj[currentProperty].Type != JTokenType.Null)
{
jObj[currentProperty] = GetUpdatedJsonArrayValue((JToken)jObj[currentProperty], propNames.GetRange(1, propNames.Count - 1), overwritevalue);
jObj[currentProperty] = GetUpdatedJsonArrayValue((JToken)jObj[currentProperty], propNames.GetRange(1, propNames.Count - 1), overwritevalue, ruleType);
}
//else return null;
}
@ -272,6 +272,42 @@ namespace CosmosCloneCommon.Utility
jTokenResult = token;
}
return jTokenResult;
}
}
private JToken ScrubTokenValue(RuleType? ruleType, JToken tokenToBeScrubbed, string overwriteValue)
{
if (ruleType.HasValue)
{
var oldValue = tokenToBeScrubbed.ToString();
if (ruleType == RuleType.PartialMaskFromLeft)
{
if (overwriteValue.Length >= oldValue.Length)
{
tokenToBeScrubbed = overwriteValue;
}
else
{
tokenToBeScrubbed = string.Concat(overwriteValue, oldValue.Remove(0, overwriteValue.Length));
}
}
else if (ruleType == RuleType.PartialMaskFromRight)
{
if (overwriteValue.Length >= oldValue.Length)
{
tokenToBeScrubbed = overwriteValue;
}
else
{
tokenToBeScrubbed = string.Concat(oldValue.Remove(oldValue.Length - overwriteValue.Length, overwriteValue.Length), overwriteValue);
}
}
else
{
tokenToBeScrubbed = overwriteValue;
}
}
return tokenToBeScrubbed;
}
}
}

Просмотреть файл

@ -89,6 +89,8 @@ The Scrub Type field provides options such as
* Single value: Replace the attribute value with a fixed value
* Null Value: Empty the attribute content.
* Shuffle: Random shuffle the attribute values across all documents of the collection.
* PartialMaskFromLeft: Masks the the attribute value partially starting from left with the given value
* PartialMaskFromRight: Masks the attribute value partially starting from right with the given value
**Sample rule1**
@ -103,6 +105,12 @@ This shuffles the Full name attribute value between all documents.
To update key values of the Nested Entities you can configure an anonymization rule as above. Note the Filter Query that tells the tool to perform this operation only if the EntityType attribute of the document is an “Individual”.
**Sample rule3**
![screen10](/docs/images/sRule3.png)
To mask a given attribute value partially with some text, you can use the Scrub Type options "PartialMaskFromLeft" or "PartialMaskFromRight"
Note there are options on the anonymization screen to validate, save and load these rules
**Migration screen**

Двоичные данные
docs/images/sRule3.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 26 KiB