feat: add anonymization flag

Signed-off-by: Matthis Holleville <matthish29@gmail.com>
This commit is contained in:
Matthis Holleville
2023-04-09 23:37:29 +02:00
parent 9423b53c1d
commit d2a84ea2b5
17 changed files with 278 additions and 63 deletions

View File

@@ -2,6 +2,9 @@ package util
import (
"context"
"fmt"
"math/rand"
"regexp"
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -96,3 +99,20 @@ func SliceDiff(source, dest []string) []string {
}
return diff
}
func MaskString(input string) string {
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
result := make([]rune, len(input))
for i := range result {
result[i] = letters[rand.Intn(len(letters))]
}
return string(result)
}
func ReplaceIfMatch(text string, pattern string, replacement string) string {
re := regexp.MustCompile(fmt.Sprintf(`%s(\b\s)`, pattern))
if re.MatchString(text) {
text = re.ReplaceAllString(text, replacement+" ")
}
return text
}