diff --git a/redshiftsink/pkg/transformer/masker/mask_config.go b/redshiftsink/pkg/transformer/masker/mask_config.go index 990217c64..a9de30c53 100644 --- a/redshiftsink/pkg/transformer/masker/mask_config.go +++ b/redshiftsink/pkg/transformer/masker/mask_config.go @@ -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) @@ -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 } @@ -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 { @@ -256,7 +259,7 @@ func (m MaskConfig) unMaskConditionalNonPiiKeys( m.regexes[pattern] = regex } - if regex.MatchString(cValue) { + if regex.MatchString(*cValue) { return true } } @@ -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] diff --git a/redshiftsink/pkg/transformer/masker/mask_config_test.go b/redshiftsink/pkg/transformer/masker/mask_config_test.go index f0e6f35b4..19e32b1be 100644 --- a/redshiftsink/pkg/transformer/masker/mask_config_test.go +++ b/redshiftsink/pkg/transformer/masker/mask_config_test.go @@ -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", diff --git a/redshiftsink/pkg/transformer/masker/masker.go b/redshiftsink/pkg/transformer/masker/masker.go index 051a63d2f..c45e0ac5e 100644 --- a/redshiftsink/pkg/transformer/masker/masker.go +++ b/redshiftsink/pkg/transformer/masker/masker.go @@ -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)