-
Notifications
You must be signed in to change notification settings - Fork 20
/
util.go
116 lines (103 loc) · 2.36 KB
/
util.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
108
109
110
111
112
113
114
115
116
package pki
import (
"bytes"
"fmt"
"net"
"os"
"sort"
"strconv"
"strings"
)
func sliceContains(slice []string, item string) bool {
set := make(map[string]struct{}, len(slice))
for _, s := range slice {
set[s] = struct{}{}
}
_, ok := set[item]
return ok
}
func getHexFormatted(buf []byte, sep string) (string, error) {
var ret bytes.Buffer
for _, cur := range buf {
if ret.Len() > 0 {
if _, err := fmt.Fprint(&ret, sep); err != nil {
return "", err
}
}
if _, err := fmt.Fprintf(&ret, "%02x", cur); err != nil {
return "", err
}
}
return ret.String(), nil
}
func normalizeSerial(serial string) string {
return strings.Replace(strings.ToLower(serial), ":", "-", -1)
}
type RunContext struct {
TPPurl string
TPPuser string
TPPPassword string
TPPZone string
CloudUrl string
CloudAPIkey string
CloudZone string
TPPTestingEnabled bool
CloudTestingEnabled bool
FakeTestingEnabled bool
TPPIssuerCN string
CloudIssuerCN string
FakeIssuerCN string
}
func GetContext() *RunContext {
c := RunContext{}
c.TPPurl = os.Getenv("TPPURL")
c.TPPuser = os.Getenv("TPPUSER")
c.TPPPassword = os.Getenv("TPPPASSWORD")
c.TPPZone = os.Getenv("TPPZONE")
c.CloudUrl = os.Getenv("CLOUDURL")
c.CloudAPIkey = os.Getenv("CLOUDAPIKEY")
c.CloudZone = os.Getenv("CLOUDZONE")
c.TPPTestingEnabled, _ = strconv.ParseBool(os.Getenv("VENAFI_TPP_TESTING"))
c.CloudTestingEnabled, _ = strconv.ParseBool(os.Getenv("VENAFI_CLOUD_TESTING"))
c.FakeTestingEnabled, _ = strconv.ParseBool(os.Getenv("VENAFI_FAKE_TESTING"))
c.TPPIssuerCN = os.Getenv("TPP_ISSUER_CN")
c.CloudIssuerCN = os.Getenv("CLOUD_ISSUER_CN")
c.FakeIssuerCN = os.Getenv("FAKE_ISSUER_CN")
return &c
}
func SameIpSlice(x, y []net.IP) bool {
if len(x) != len(y) {
return false
}
x1 := make([]string, len(x))
y1 := make([]string, len(y))
for i := range x {
x1[i] = x[i].String()
y1[i] = y[i].String()
}
sort.Strings(x1)
sort.Strings(y1)
for i := range x1 {
if x1[i] != y1[i] {
return false
}
}
return true
}
func SameStringSlice(x, y []string) bool {
if len(x) != len(y) {
return false
}
x1 := make([]string, len(x))
y1 := make([]string, len(y))
copy(x1, x)
copy(y1, y)
sort.Strings(x1)
sort.Strings(y1)
for i := range x1 {
if x1[i] != y1[i] {
return false
}
}
return true
}