-
Notifications
You must be signed in to change notification settings - Fork 5
/
tools.go
61 lines (56 loc) · 1.35 KB
/
tools.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
package secret
import (
"time"
corev1 "k8s.io/api/core/v1"
)
// GetType returns the secret type.
func (h *Handler) GetType(object interface{}) (string, error) {
switch val := object.(type) {
case string:
secret, err := h.Get(val)
if err != nil {
return "", err
}
return string(secret.Type), nil
case *corev1.Secret:
return string(val.Type), nil
case corev1.Secret:
return string(val.Type), nil
default:
return "", ErrInvalidToolsType
}
}
// GetNumData returns the number of the secret.
func (h *Handler) GetNumData(object interface{}) (int, error) {
switch val := object.(type) {
case string:
secret, err := h.Get(val)
if err != nil {
return 0, err
}
return len(secret.Data), nil
case *corev1.Secret:
return len(val.Data), nil
case corev1.Secret:
return len(val.Data), nil
default:
return 0, ErrInvalidToolsType
}
}
// GetAge returns the age of the secret.
func (h *Handler) GetAge(object interface{}) (time.Duration, error) {
switch val := object.(type) {
case string:
secret, err := h.Get(val)
if err != nil {
return time.Duration(0), err
}
return time.Now().Sub(secret.CreationTimestamp.Time), nil
case *corev1.Secret:
return time.Now().Sub(val.CreationTimestamp.Time), nil
case corev1.Secret:
return time.Now().Sub(val.CreationTimestamp.Time), nil
default:
return time.Duration(0), ErrInvalidToolsType
}
}