-
Notifications
You must be signed in to change notification settings - Fork 53
/
trust.go
48 lines (44 loc) · 1.22 KB
/
trust.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
package machinery
import (
"fmt"
"github.com/rancher/opni/pkg/config/v1beta1"
"github.com/rancher/opni/pkg/keyring"
"github.com/rancher/opni/pkg/trust"
)
func BuildTrustStrategy(kind v1beta1.TrustStrategyKind, kr keyring.Keyring) (trust.Strategy, error) {
var trustStrategy trust.Strategy
var err error
switch kind {
case v1beta1.TrustStrategyPKP:
conf := trust.StrategyConfig{
PKP: &trust.PKPConfig{
Pins: trust.NewKeyringPinSource(kr),
},
}
trustStrategy, err = conf.Build()
if err != nil {
return nil, fmt.Errorf("error configuring pkp trust from keyring: %w", err)
}
case v1beta1.TrustStrategyCACerts:
conf := trust.StrategyConfig{
CACerts: &trust.CACertsConfig{
CACerts: trust.NewKeyringCACertsSource(kr),
},
}
trustStrategy, err = conf.Build()
if err != nil {
return nil, fmt.Errorf("error configuring ca certs trust from keyring: %w", err)
}
case v1beta1.TrustStrategyInsecure:
conf := trust.StrategyConfig{
Insecure: &trust.InsecureConfig{},
}
trustStrategy, err = conf.Build()
if err != nil {
return nil, fmt.Errorf("error configuring insecure trust: %w", err)
}
default:
return nil, fmt.Errorf("unknown trust strategy: %s", kind)
}
return trustStrategy, nil
}