-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (62 loc) · 1.69 KB
/
main.go
File metadata and controls
75 lines (62 loc) · 1.69 KB
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
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/DevLabFoundry/configmanager-plugin-awsparamstr/impl"
"github.com/DevLabFoundry/configmanager/v3/config"
"github.com/DevLabFoundry/configmanager/v3/tokenstore"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
)
type implIface interface {
Value(token string, metadata []byte) (string, error)
}
type TokenStorePlugin struct {
impl implIface
}
func (ts TokenStorePlugin) Value(key string, metadata []byte) (string, error) {
return ts.impl.Value(key, metadata)
}
var (
Version string = "0.0.1"
Revision string = "1111aaaa"
)
func main() {
versionFlag := flag.Bool("version", false, "plugin version")
flag.Parse()
if *versionFlag {
fmt.Printf("Version: %s-%s\n", Version, Revision)
os.Exit(0)
}
// log set up
log := hclog.New(hclog.DefaultOptions)
log.SetLevel(hclog.LevelFromString("error"))
if val, ok := os.LookupEnv(config.CONFIGMANAGER_LOG); ok && len(val) > 0 {
if logLevel := hclog.LevelFromString(val); logLevel != hclog.NoLevel {
log.SetLevel(logLevel)
}
}
// initialize the implementation
i, err := impl.NewParamStore(context.Background(), log)
if err != nil {
log.Error("error", err)
os.Exit(1)
}
// initializing the service
ts := TokenStorePlugin{impl: i}
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: tokenstore.Handshake,
Plugins: map[string]plugin.Plugin{
"configmanager_token_store": &tokenstore.GRPCPlugin{Impl: ts},
},
VersionedPlugins: map[int]plugin.PluginSet{
1: {
"configmanager_token_store": &tokenstore.GRPCPlugin{Impl: ts},
},
},
// A non-nil value here enables gRPC serving for this plugin...
GRPCServer: plugin.DefaultGRPCServer,
})
}