Skip to content

Commit

Permalink
Fixes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
alok87 committed Sep 28, 2020
1 parent cf36113 commit f615808
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions redshiftsink/pkg/transformer/masker/mask_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (m MaskConfig) DependentNonPiiKey(table, cName string) bool {
}

// PerformUnMasking checks if unmasking should be done or not
func (m MaskConfig) PerformUnMasking(table, cName string, cValue string,
func (m MaskConfig) PerformUnMasking(table, cName string, cValue *string,
allColumns map[string]*string) bool {

cName = strings.ToLower(cName)
Expand All @@ -188,7 +188,7 @@ func (m MaskConfig) PerformUnMasking(table, cName string, cValue string,

if m.unMaskNonPiiKeys(table, cName) ||
m.unMaskConditionalNonPiiKeys(table, cName, cValue) ||
m.unMaskDependentNonPiiKeys(table, cName, cValue, allColumns) {
m.unMaskDependentNonPiiKeys(table, cName, allColumns) {

return true
}
Expand All @@ -212,7 +212,10 @@ func (m MaskConfig) unMaskNonPiiKeys(table, cName string) bool {
}

func (m MaskConfig) unMaskConditionalNonPiiKeys(
table, cName string, cValue string) bool {
table, cName string, cValue *string) bool {
if cValue == nil {
return false
}

columnsToCheckRaw, ok := m.ConditionalNonPiiKeys[table]
if !ok {
Expand Down Expand Up @@ -256,7 +259,7 @@ func (m MaskConfig) unMaskConditionalNonPiiKeys(
m.regexes[pattern] = regex
}

if regex.MatchString(cValue) {
if regex.MatchString(*cValue) {
return true
}
}
Expand All @@ -266,7 +269,7 @@ func (m MaskConfig) unMaskConditionalNonPiiKeys(
}

func (m MaskConfig) unMaskDependentNonPiiKeys(
table, cName string, cValue string, allColumns map[string]*string) bool {
table, cName string, allColumns map[string]*string) bool {

// if table not in config, no unmasking required
columnsToCheckRaw, ok := m.DependentNonPiiKeys[table]
Expand Down
2 changes: 1 addition & 1 deletion redshiftsink/pkg/transformer/masker/mask_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func testMasked(t *testing.T, dir, topic, table, cName, cValue string,
t.Error(err)
}

gotResult := m.PerformUnMasking(table, cName, cValue, allColumns)
gotResult := m.PerformUnMasking(table, cName, &cValue, allColumns)
if gotResult != result {
t.Errorf(
"Expected column: %v to have mask=%v in table:%v, got mask=%v\n",
Expand Down
4 changes: 2 additions & 2 deletions redshiftsink/pkg/transformer/masker/masker.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ func (m *masker) Transform(
if cVal == nil {
columns[cName] = nil
// nil value is not masked but its schema should have masked type
maskInfo := serializer.MaskInfo{Masked: true}
maskInfo := serializer.MaskInfo{Masked: false}
maskSchema[cName] = maskInfo
continue
}

unmasked := m.config.PerformUnMasking(m.table, cName, *cVal, rawColumns)
unmasked := m.config.PerformUnMasking(m.table, cName, cVal, rawColumns)
sortKey := m.config.SortKey(m.table, cName)
distKey := m.config.DistKey(m.table, cName)
lengthKey := m.config.LengthKey(m.table, cName)
Expand Down

0 comments on commit f615808

Please sign in to comment.