-
Notifications
You must be signed in to change notification settings - Fork 11
/
helpers.go
107 lines (91 loc) · 2.09 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package shared
import (
"context"
"regexp"
"strings"
"github.com/gookit/color"
)
const (
CONTENT_TYPE_JSON = "application/json"
CONTENT_TYPE_URL_ENCODED = "application/x-www-form-urlencoded"
USER_AGENT = "aws-cli/2.5.3 Python/3.9.12"
CONTENT_TYPE_HEADER = "Content-Type"
)
var AzureTemplatePropertyRegex = regexp.MustCompile(`\{.(\w+)\}`)
var AwsTemplatePropertyRegex = regexp.MustCompile(`(?:^|)\b(//)`)
var CheckForEmptyPathRegex = regexp.MustCompile(`//`)
type Scanner interface {
EnumerateAll(ctx context.Context, region string, creds interface{}) error
EnumerateSpecificService(ctx context.Context, region, service string, creds interface{}) error
}
func GetMessageColor(p string) string {
switch p {
case "error":
return Red("●")
case "timeout":
return Red("⊗")
case "warning", "maybe":
return Yellow("●")
case "debug", "low":
return Cyan("●")
case "info":
return Magenta("●")
case "success":
return Green("●")
// return Green("✓")
default:
return ""
}
}
func Red(s string) string {
return color.Red.Sprintf("%s", s)
}
func Cyan(s string) string {
return color.Cyan.Sprintf("%s", s)
}
func Yellow(s string) string {
return color.Yellow.Sprintf("%s", s)
}
func Green(s string) string {
return color.Green.Sprintf("%s", s)
}
func Blue(s string) string {
return color.Blue.Sprintf("%s", s)
}
func Magenta(s string) string {
return color.Magenta.Sprintf("%s", s)
}
func Black(s string) string {
return color.Black.Sprintf("%s", s)
}
// remove duplicates from a slice of strings
func RemoveDuplicates(slice []string) []string {
if len(slice) == 0 {
return slice
}
m := make(map[string]bool)
for _, s := range slice {
m[s] = true
}
var res []string
for k := range m {
res = append(res, k)
}
return res
}
func KebabToCamelCase(kebab string) (camelCase string) {
isToUpper := false
for _, runeValue := range kebab {
if isToUpper {
camelCase += strings.ToUpper(string(runeValue))
isToUpper = false
} else {
if runeValue == '-' {
isToUpper = true
} else {
camelCase += string(runeValue)
}
}
}
return
}