-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
96 lines (79 loc) · 2.07 KB
/
main.go
File metadata and controls
96 lines (79 loc) · 2.07 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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 TokenStorePlugin struct {
impl tokenstore.TokenStore
}
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 ShowFlag(osArgs []string) bool {
fs := flag.NewFlagSet("plugin", flag.ContinueOnError)
vf := fs.Bool("version", false, "plugin version")
if err := fs.Parse(osArgs); err != nil {
return false
}
if *vf {
fmt.Printf("Version: %s-%s\n", Version, Revision)
return true
}
return false
}
func PluginSetup() (*impl.ParamStore, error) {
// log set up
log := hclog.New(hclog.DefaultOptions)
log.SetLevel(hclog.LevelFromString("error"))
os.Environ()
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("implementation init error", err, "impl", "awsparamstr")
return nil, err
}
return i, nil
}
// main func should only be used for process terminantion
// Inits and serves the plugin
func main() {
if ShowFlag(os.Args[1:]) {
os.Exit(0)
}
i, err := PluginSetup()
if err != nil {
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,
})
}