Skip to content

Commit

Permalink
code cleanup - remove leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
stremovsky committed Dec 27, 2024
1 parent 202ed0f commit 71ae4a6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/agreements_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (e mainEnv) agreementAccept(w http.ResponseWriter, r *http.Request, ps http
if len(status) == 0 {
status = "yes"
} else {
status = utils.NormalizeConsentStatus(status)
status = utils.NormalizeConsentValue(status)
}
if value, ok := records["expiration"]; ok {
switch records["expiration"].(type) {
Expand Down
3 changes: 0 additions & 3 deletions src/storage/mysql-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ func (dbobj *MySQLDB) OpenDB(dbname *string) error {
}
tx.Commit()
fmt.Printf("tables: %s\n", allTables)
if isContainer() == true && len(os.Getenv("MYSQL_USER_PASS_FILE")) > 0 {
os.Remove(os.Getenv("MYSQL_USER_PASS_FILE"))
}
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions src/storage/pgsql-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ func (dbobj *PGSQLDB) OpenDB(dbname *string) error {
}
tx.Commit()
fmt.Printf("tables: %s\n", allTables)
if isContainer() == true && len(os.Getenv("PGSQL_USER_PASS_FILE")) > 0 {
os.Remove(os.Getenv("PGSQL_USER_PASS_FILE"))
}
return nil
}

Expand Down
13 changes: 0 additions & 13 deletions src/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,3 @@ func SliceContains(slice []string, item string) bool {
_, ok := set[item]
return ok
}

func isContainer() bool {
//if _, err := os.Stat("/.dockerenv"); err == nil {
// return true
//}
if len(os.Getenv("KUBERNETES_SERVICE_HOST")) > 0 {
return true
}
if _, err := os.Stat("/var/run/secrets/kubernetes.io"); err == nil {
return true
}
return false
}
51 changes: 9 additions & 42 deletions src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ var (
regexAppName = regexp.MustCompile("^[a-z][a-z0-9\\_]{1,30}$")
regexExpiration = regexp.MustCompile("^([0-9]+)([mhds])?$")
regexHex = regexp.MustCompile("^[a-zA-F0-9]+$")
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
numbers = []rune("0123456789")
numbers0 = []rune("123456789")
indexNames = map[string]bool{
"custom": true,
"email": true,
"login": true,
"phone": true,
"token": true,
}
consentYesStatuses = map[string]bool{
consentValueTypes = map[string]bool{
"1": true,
"accept": true,
"agree": true,
Expand All @@ -49,7 +52,7 @@ var (
"y": true,
"yes": true,
}
basisTypes = map[string]bool{
legalBasisTypes = map[string]bool{
"consent": true,
"contract": true,
"legal-requirement": true,
Expand Down Expand Up @@ -151,17 +154,17 @@ func HashString(md5Salt []byte, src string) string {
return base64.StdEncoding.EncodeToString(hashed[:])
}

func NormalizeConsentStatus(status string) string {
func NormalizeConsentValue(status string) string {
status = strings.ToLower(status)
if consentYesStatuses[status] {
if consentValueTypes[status] {
return "yes"
}
return "no"
}

func normalizeBasisType(status string) string {
func NormalizeLegalBasisType(status string) string {
status = strings.ToLower(status)
if basisTypes[status] {
if legalBasisTypes[status] {
return status
}
return "consent"
Expand Down Expand Up @@ -211,24 +214,6 @@ func ParseFields(fields string) []string {
return strings.Split(fields, ",")
}

// Binary search implementation for a sorted array of strings
func binarySearch(arr []string, target string) bool {
low := 0
high := len(arr) - 1

for low <= high {
mid := (low + high) / 2
if arr[mid] == target {
return true
} else if arr[mid] < target {
low = mid + 1
} else {
high = mid - 1
}
}
return false
}

func SliceContains(slice []string, item string) bool {
set := make(map[string]bool, len(slice))
for _, s := range slice {
Expand Down Expand Up @@ -352,19 +337,6 @@ func CheckValidHex(hex1 string) bool {
return regexHex.MatchString(hex1)
}

func isContainer() bool {
//if _, err := os.Stat("/.dockerenv"); err == nil {
// return true
//}
if len(os.Getenv("KUBERNETES_SERVICE_HOST")) > 0 {
return true
}
if _, err := os.Stat("/var/run/secrets/kubernetes.io"); err == nil {
return true
}
return false
}

// StringPatternMatch looks for basic human patterns like "*", "*abc*", etc...
func StringPatternMatch(pattern string, value string) bool {
if len(pattern) == 0 {
Expand Down Expand Up @@ -563,8 +535,6 @@ func GetUserJSONStruct(r *http.Request, defaultCountry string) (UserJSONStruct,
return result, err
}

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func RandSeq(n int) string {
b := make([]rune, n)
for i := range b {
Expand All @@ -573,9 +543,6 @@ func RandSeq(n int) string {
return string(b)
}

var numbers0 = []rune("123456789")
var numbers = []rune("0123456789")

func RandNum(n int) int32 {
b := make([]rune, n)
for i := range b {
Expand Down

0 comments on commit 71ae4a6

Please sign in to comment.