-
Notifications
You must be signed in to change notification settings - Fork 458
/
configure.go
79 lines (61 loc) · 1.99 KB
/
configure.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
package catalog
import (
"context"
"github.com/sirupsen/logrus"
"github.com/spiffe/go-spiffe/v2/spiffeid"
configv1 "github.com/spiffe/spire-plugin-sdk/proto/spire/service/common/config/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type CoreConfig struct {
TrustDomain spiffeid.TrustDomain
}
func (c CoreConfig) v1() *configv1.CoreConfiguration {
return &configv1.CoreConfiguration{
TrustDomain: c.TrustDomain.String(),
}
}
type Configurer interface {
Configure(ctx context.Context, coreConfig CoreConfig, configuration string) error
}
type configurerRepo struct {
configurer Configurer
}
func (repo *configurerRepo) Binder() interface{} {
return func(configurer Configurer) {
repo.configurer = configurer
}
}
func (repo *configurerRepo) Versions() []Version {
return []Version{
configurerV1Version{},
}
}
func (repo *configurerRepo) Clear() {
// This function is only for conforming to the Repo interface and isn't
// expected to be called, but just in case, we'll do the right thing
// and clear out the configurer that has been bound.
repo.configurer = nil
}
type configurerV1Version struct{}
func (configurerV1Version) New() Facade { return new(configurerV1) }
func (configurerV1Version) Deprecated() bool { return false }
type configurerV1 struct {
configv1.ConfigServiceClient
}
var _ Configurer = (*configurerV1)(nil)
func (v1 *configurerV1) InitInfo(PluginInfo) {
}
func (v1 *configurerV1) InitLog(logrus.FieldLogger) {
}
func (v1 *configurerV1) Configure(ctx context.Context, coreConfig CoreConfig, hclConfiguration string) error {
_, err := v1.ConfigServiceClient.Configure(ctx, &configv1.ConfigureRequest{
CoreConfiguration: coreConfig.v1(),
HclConfiguration: hclConfiguration,
})
return err
}
type configurerUnsupported struct{}
func (c configurerUnsupported) Configure(ctx context.Context, coreConfig CoreConfig, hclConfiguration string) error {
return status.Error(codes.FailedPrecondition, "plugin does not support a configuration interface")
}