Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
RouganStriker authored and junkert committed Dec 5, 2023
1 parent 44c7dd6 commit 0ac3e04
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
72 changes: 36 additions & 36 deletions processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,28 @@ type safeAlphaNumericMap struct {

// safeStringMap is a concurrency-safe map for storing unique values
type safeStringMap struct {
v map[string]struct{}
v map[string]struct{}
mux sync.Mutex
}

// safeUniqueAlphaNumericMap is a concurrency-safe map for storing the unique value mappings for each column
type safeUniqueAlphaNumericMap struct {
uniqueMap map[string]safeStringMap
mux sync.Mutex
uniqueMap map[string]*safeStringMap
mux sync.Mutex
}

var UniqueScrambledColumnValueMap = safeUniqueAlphaNumericMap{
uniqueMap: make(map[string]safeStringMap),
uniqueMap: make(map[string]*safeStringMap),
}

func (c *safeUniqueAlphaNumericMap) Get(parentKey, input string) (string, error) {
c.mux.Lock()
defer c.mux.Unlock()

uniqueMap, ok := c.uniqueMap[parentKey]
var uniqueMap, ok = c.uniqueMap[parentKey]

if !ok {
c.uniqueMap[parentKey] = safeStringMap{
c.uniqueMap[parentKey] = &safeStringMap{
v: make(map[string]struct{}),
}
uniqueMap = c.uniqueMap[parentKey]
Expand Down Expand Up @@ -137,8 +139,6 @@ type safeUUIDMap struct {
mux sync.Mutex
}



// Get returns a mapped uuid for a given UUID if it has already previously been anonymized and a new UUID otherwise.
func (c *safeUUIDMap) Get(key uuid.UUID) (uuid.UUID, error) {
result, ok := c.v[key]
Expand Down Expand Up @@ -184,30 +184,30 @@ var UUIDMap = safeUUIDMap{
// init initializes the ProcessorCatalog map for all processors. A processor must be listed here to be accessible.
func init() {
ProcessorCatalog = map[string]ProcessorFunc{
"AlphaNumericScrambler": ProcessorAlphaNumericScrambler,
"EmptyJson": ProcessorEmptyJson,
"FakeStreetAddress": ProcessorAddress,
"FakeCity": ProcessorCity,
"FakeLatitude": ProcessorLatitude,
"FakeLongitude": ProcessorLongitude,
"FakeCompanyName": ProcessorCompanyName,
"FakeEmailAddress": ProcessorEmailAddress,
"FakeFirstName": ProcessorFirstName,
"FakeFullName": ProcessorFullName,
"FakeIPv4": ProcessorIPv4,
"FakeLastName": ProcessorLastName,
"FakePhoneNumber": ProcessorPhoneNumber,
"FakeState": ProcessorState,
"FakeStateAbbrev": ProcessorStateAbbrev,
"FakeUsername": ProcessorUserName,
"FakeZip": ProcessorZip,
"Identity": ProcessorIdentity, // Default: Does not modify field
"RandomBoolean": ProcessorRandomBoolean,
"RandomDate": ProcessorRandomDate,
"RandomDigits": ProcessorRandomDigits,
"RandomUUID": ProcessorRandomUUID,
"ScrubString": ProcessorScrubString,
"UniqueAlphaNumericScrambler": ProcessorUniqueAlphaNumericScrambler,
"AlphaNumericScrambler": ProcessorAlphaNumericScrambler,
"EmptyJson": ProcessorEmptyJson,
"FakeStreetAddress": ProcessorAddress,
"FakeCity": ProcessorCity,
"FakeLatitude": ProcessorLatitude,
"FakeLongitude": ProcessorLongitude,
"FakeCompanyName": ProcessorCompanyName,
"FakeEmailAddress": ProcessorEmailAddress,
"FakeFirstName": ProcessorFirstName,
"FakeFullName": ProcessorFullName,
"FakeIPv4": ProcessorIPv4,
"FakeLastName": ProcessorLastName,
"FakePhoneNumber": ProcessorPhoneNumber,
"FakeState": ProcessorState,
"FakeStateAbbrev": ProcessorStateAbbrev,
"FakeUsername": ProcessorUserName,
"FakeZip": ProcessorZip,
"Identity": ProcessorIdentity, // Default: Does not modify field
"RandomBoolean": ProcessorRandomBoolean,
"RandomDate": ProcessorRandomDate,
"RandomDigits": ProcessorRandomDigits,
"RandomUUID": ProcessorRandomUUID,
"ScrubString": ProcessorScrubString,
"UniqueAlphaNumericScrambler": ProcessorUniqueAlphaNumericScrambler,
}

}
Expand Down Expand Up @@ -237,10 +237,10 @@ func ProcessorAlphaNumericScrambler(cmap *ColumnMapper, input string) (string, e
// ProcessorUniqueAlphaNumericScrambler behaves just like ProcessorAlphaNumericScrambler except it
// ensures that it will return unique values.
func ProcessorUniqueAlphaNumericScrambler(cmap *ColumnMapper, input string) (string, error) {
var scrambleStringUniquely = func(input string) (string, error) {
tableKey := fmt.Sprintf("%s.%s.%s", cmap.TableSchema, cmap.TableName, cmap.ColumnName)
return UniqueScrambledColumnValueMap.Get(tableKey, input)
}
var scrambleStringUniquely = func(input string) (string, error) {
tableKey := fmt.Sprintf("%s.%s.%s", cmap.TableSchema, cmap.TableName, cmap.ColumnName)
return UniqueScrambledColumnValueMap.Get(tableKey, input)
}

if cmap.ParentSchema != "" && cmap.ParentTable != "" && cmap.ParentColumn != "" {
parentKey := fmt.Sprintf("%s.%s.%s", cmap.ParentSchema, cmap.ParentTable, cmap.ParentColumn)
Expand Down
6 changes: 3 additions & 3 deletions processors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var cMap = ColumnMapper{

// Pre-generated scrambled strings for the text "This is my unscrambled text" using a fixed rng seed
const rngSeed = 5336

var preGeneratedScrambledStrings = []string{
"Hdva nn ef lujjclagwxv mdtj",
"Wjpp vj nw idiicqtcaab yyoy",
Expand All @@ -62,7 +63,6 @@ var preGeneratedScrambledStrings = []string{
"Aiya kb zg ljctcijzuyj fqze",
}


func TestProcessorFunc(t *testing.T) {
}

Expand Down Expand Up @@ -158,7 +158,7 @@ func TestProcessorUniqueAlphaNumericScramblerEnsuresUniqueness(t *testing.T) {
tableKey := fmt.Sprintf("%s.%s.%s", cMap.TableSchema, cMap.TableName, cMap.ColumnName)

// Pre-populate the mapping to check that the scrambler only returns unique values
UniqueScrambledColumnValueMap.uniqueMap[tableKey] = safeStringMap{
UniqueScrambledColumnValueMap.uniqueMap[tableKey] = &safeStringMap{
v: make(map[string]struct{}),
}
for _, scrambledString := range preGeneratedScrambledStrings {
Expand All @@ -179,7 +179,7 @@ func TestProcessorUniqueAlphaNumericScramblerEnsuresUniquenessPerColumn(t *testi
tableKey := fmt.Sprintf("%s.%s.%s", cMap.TableSchema, cMap.TableName, cMap.ColumnName)

// Pre-populate the mapping to check that the scrambler only returns unique values
UniqueScrambledColumnValueMap.uniqueMap[tableKey] = safeStringMap{
UniqueScrambledColumnValueMap.uniqueMap[tableKey] = &safeStringMap{
v: make(map[string]struct{}),
}
for _, scrambledString := range preGeneratedScrambledStrings {
Expand Down

0 comments on commit 0ac3e04

Please sign in to comment.