github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/utc_now.go (about) 1 package functions 2 3 import ( 4 "strings" 5 "time" 6 ) 7 8 func UTCNow(args ...interface{}) interface{} { 9 if len(args) > 1 { 10 return nil 11 } 12 13 if len(args) == 1 { 14 format, ok := args[0].(string) 15 if ok { 16 goFormat := convertFormat(format) 17 return time.Now().UTC().Format(goFormat) 18 } 19 } 20 21 return time.Now().UTC().Format(time.RFC3339) 22 } 23 24 // don't look directly at this code 25 func convertFormat(format string) string { 26 goFormat := format 27 goFormat = strings.ReplaceAll(goFormat, "yyyy", "2006") 28 goFormat = strings.ReplaceAll(goFormat, "yy", "06") 29 goFormat = strings.ReplaceAll(goFormat, "MMMM", "January") 30 goFormat = strings.ReplaceAll(goFormat, "MMM", "Jan") 31 goFormat = strings.ReplaceAll(goFormat, "MM", "01") 32 goFormat = strings.ReplaceAll(goFormat, "M", "1") 33 goFormat = strings.ReplaceAll(goFormat, "dd", "02") 34 goFormat = strings.ReplaceAll(goFormat, "d", "2") 35 goFormat = strings.ReplaceAll(goFormat, "HH", "15") 36 goFormat = strings.ReplaceAll(goFormat, "H", "3") 37 goFormat = strings.ReplaceAll(goFormat, "hh", "03") 38 goFormat = strings.ReplaceAll(goFormat, "h", "3") 39 goFormat = strings.ReplaceAll(goFormat, "mm", "04") 40 goFormat = strings.ReplaceAll(goFormat, "m", "4") 41 goFormat = strings.ReplaceAll(goFormat, "ss", "05") 42 goFormat = strings.ReplaceAll(goFormat, "s", "5") 43 goFormat = strings.ReplaceAll(goFormat, "tt", "PM") 44 goFormat = strings.ReplaceAll(goFormat, "t", "PM") 45 return goFormat 46 47 }