-
Notifications
You must be signed in to change notification settings - Fork 2
/
assertions.go
126 lines (107 loc) · 3.14 KB
/
assertions.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
117
118
119
120
121
122
123
124
125
126
package testenv
import (
"time"
"github.com/onsi/gomega"
"github.com/youniqx/heist/pkg/vault"
"github.com/youniqx/heist/pkg/vault/core"
"github.com/youniqx/heist/pkg/vault/kvsecret"
"github.com/youniqx/heist/pkg/vault/transit"
)
const (
timeout = 30 * time.Second
pollInterval = 200 * time.Millisecond
)
func (e *testEnv) fetch(fetcher func(api vault.API) interface{}) gomega.AsyncAssertion {
return gomega.Eventually(func() interface{} {
return fetcher(e.RootAPI)
}, timeout, pollInterval)
}
type TestSecret interface {
kvsecret.Entity
Engine() core.MountPathEntity
API() vault.API
}
type testSecret struct {
kvsecret.Entity
EngineRef core.MountPathEntity
VaultAPI vault.API
}
func (t *testSecret) Engine() core.MountPathEntity {
return t.EngineRef
}
func (t *testSecret) API() vault.API {
return t.VaultAPI
}
func (e *testEnv) KvSecret(engine core.MountPathEntity, secret core.SecretPathEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
secret, _ := api.ReadKvSecret(engine, secret)
if secret == nil {
return nil
}
return &testSecret{
Entity: secret,
EngineRef: engine,
VaultAPI: api,
}
})
}
func (e *testEnv) KvEngine(engine core.MountPathEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
engine, _ := api.ReadKvEngine(engine)
return engine
})
}
func (e *testEnv) TransitEngine(engine core.MountPathEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
engine, _ := api.ReadTransitEngine(engine)
return engine
})
}
func (e *testEnv) TransitKey(engine core.MountPathEntity, key transit.KeyNameEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
engine, _ := api.ReadTransitKey(engine, key)
return engine
})
}
func (e *testEnv) Policy(policy core.PolicyNameEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
engine, _ := api.ReadPolicy(policy)
return engine
})
}
func (e *testEnv) KubernetesAuthRole(auth core.MountPathEntity, role core.RoleNameEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
role, _ := api.ReadKubernetesAuthRole(auth, role)
return role
})
}
func (e *testEnv) AuthMethod(auth core.MountPathEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
auth, _ := api.ReadAuthMethod(auth)
return auth
})
}
func (e *testEnv) Mount(mount core.MountPathEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
mount, _ := api.ReadMount(mount)
return mount
})
}
func (e *testEnv) CA(mount core.MountPathEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
ca, _ := api.ReadCA(mount)
return ca
})
}
func (e *testEnv) TuneConfig(engine core.MountPathEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
config, _ := api.ReadTuneConfig(engine)
return config
})
}
func (e *testEnv) CertificateRole(ca core.MountPathEntity, role core.RoleNameEntity) gomega.AsyncAssertion {
return e.fetch(func(api vault.API) interface{} {
certRole, _ := api.ReadCertificateRole(ca, role)
return certRole
})
}