-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redact entity configuration metadata (#4862)
Heavy merge guessing by CK. Signed-off-by: James Phillips <jamesdphillips@gmail.com> (cherry picked from commit 7a13587)
- Loading branch information
1 parent
b3807f3
commit 41f3e41
Showing
7 changed files
with
332 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package strings | ||
|
||
import ( | ||
"strings" | ||
"unicode" | ||
) | ||
|
||
const ( | ||
lowerAlphaStart = 97 | ||
lowerAlphaStop = 122 | ||
) | ||
|
||
func isAlpha(r rune) bool { | ||
return r >= lowerAlphaStart && r <= lowerAlphaStop | ||
} | ||
|
||
func alphaNumeric(s string) bool { | ||
for _, r := range s { | ||
if !(unicode.IsDigit(r) || isAlpha(r)) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func normalize(s string) string { | ||
if alphaNumeric(s) { | ||
return s | ||
} | ||
lowered := strings.ToLower(s) | ||
if alphaNumeric(lowered) { | ||
return lowered | ||
} | ||
trimmed := make([]rune, 0, len(lowered)) | ||
for _, r := range lowered { | ||
if isAlpha(r) { | ||
trimmed = append(trimmed, r) | ||
} | ||
} | ||
return string(trimmed) | ||
} | ||
|
||
// FoundInArray searches array for item without distinguishing between uppercase | ||
// and lowercase and non-alphanumeric characters. Returns true if item is a | ||
// value of array | ||
func FoundInArray(item string, array []string) bool { | ||
if item == "" || len(array) == 0 { | ||
return false | ||
} | ||
|
||
item = normalize(item) | ||
|
||
for i := range array { | ||
if normalize(array[i]) == item { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package strings | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFoundInArray(t *testing.T) { | ||
var array []string | ||
|
||
found := FoundInArray("Foo", []string{}) | ||
assert.False(t, found) | ||
|
||
array = []string{"foo", "bar"} | ||
found = FoundInArray("Foo", array) | ||
assert.True(t, found) | ||
|
||
array = []string{"foo", "bar"} | ||
found = FoundInArray("FooBar", array) | ||
assert.False(t, found) | ||
|
||
array = []string{"foo", "bar"} | ||
found = FoundInArray("Foo ", array) | ||
assert.True(t, found) | ||
|
||
array = []string{"foo_bar"} | ||
found = FoundInArray("Foo_Bar", array) | ||
assert.True(t, found) | ||
|
||
array = []string{"foobar"} | ||
found = FoundInArray("Foo_Qux", array) | ||
assert.False(t, found) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package v3 | ||
|
||
// Redacter can return a redacted copy of the resource | ||
type Redacter interface { | ||
// ProduceRedacted returns a redacted copy of the resource | ||
ProduceRedacted() Resource | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.