forked from volck/raven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
executable file
·66 lines (56 loc) · 1.41 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
package main
import (
"encoding/base64"
"fmt"
"github.com/hashicorp/vault/api"
log "github.com/sirupsen/logrus"
"io/fs"
"math/rand"
"path/filepath"
"strings"
"time"
)
func isBase64(s string) bool {
_, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return false
}
return true
}
func makeAbsolutePath(config config, filename fs.FileInfo) (newbase string) {
base := filepath.Join("declarative", config.destEnv, "sealedsecrets")
newbase = base + "/" + filename.Name()
return newbase
}
func parseGitStatusFileName(path string) string {
base := fmt.Sprintf("%s/%s/%s", "declarative", newConfig.destEnv, "sealedsecrets")
f := strings.ReplaceAll(path, base, "")
f = strings.ReplaceAll(f, ".yaml", "")
f = strings.ReplaceAll(f, "/", "")
return f
}
func sleep() {
rand.Seed(time.Now().UnixNano())
max := 30
min := 15
sleepTime := rand.Intn(max-min) + min
//now we sleep randomly
log.WithFields(log.Fields{"sleepTime": sleepTime}).Debug("Going to sleep.")
time.Sleep(time.Duration(sleepTime) * time.Second)
log.WithFields(log.Fields{"sleepTime": sleepTime}).Debug("Sleep done.")
}
func KeyInDictionary(dict map[string]*api.Secret, key string) bool {
inDictionary := false
if _, ok := dict[key]; ok {
inDictionary = true
}
return inDictionary
}
func stringSliceContainsString(slice []string, val string) bool {
for _, item := range slice {
if item == val {
return true
}
}
return false
}