@@ -13,11 +13,8 @@ import (
1313 "github.com/hashicorp/go-plugin"
1414)
1515
16- type implIface interface {
17- Value (token string , metadata []byte ) (string , error )
18- }
1916type TokenStorePlugin struct {
20- impl implIface
17+ impl tokenstore. TokenStore
2118}
2219
2320func (ts TokenStorePlugin ) Value (key string , metadata []byte ) (string , error ) {
@@ -29,20 +26,28 @@ var (
2926 Revision string = "1111aaaa"
3027)
3128
32- func main () {
33-
34- versionFlag := flag .Bool ("version" , false , "plugin version" )
35- flag .Parse ()
29+ func ShowFlag (osArgs []string ) bool {
30+ fs := flag .NewFlagSet ("plugin" , flag .ContinueOnError )
31+ vf := fs .Bool ("version" , false , "plugin version" )
32+ if err := fs .Parse (osArgs ); err != nil {
33+ return false
34+ }
3635
37- if * versionFlag {
36+ if * vf {
3837 fmt .Printf ("Version: %s-%s\n " , Version , Revision )
39- os . Exit ( 0 )
38+ return true
4039 }
40+ return false
41+ }
42+
43+ func PluginSetup () (* impl.ParamStore , error ) {
4144
4245 // log set up
4346 log := hclog .New (hclog .DefaultOptions )
47+
4448 log .SetLevel (hclog .LevelFromString ("error" ))
4549
50+ os .Environ ()
4651 if val , ok := os .LookupEnv (config .CONFIGMANAGER_LOG ); ok && len (val ) > 0 {
4752 if logLevel := hclog .LevelFromString (val ); logLevel != hclog .NoLevel {
4853 log .SetLevel (logLevel )
@@ -52,7 +57,22 @@ func main() {
5257 // initialize the implementation
5358 i , err := impl .NewParamStore (context .Background (), log )
5459 if err != nil {
55- log .Error ("error" , err )
60+ log .Error ("implementation init error" , err , "impl" , "awsparamstr" )
61+ return nil , err
62+ }
63+
64+ return i , nil
65+ }
66+
67+ // main func should only be used for process terminantion
68+ // Inits and serves the plugin
69+ func main () {
70+ if ShowFlag (os .Args [1 :]) {
71+ os .Exit (0 )
72+ }
73+
74+ i , err := PluginSetup ()
75+ if err != nil {
5676 os .Exit (1 )
5777 }
5878
@@ -64,6 +84,7 @@ func main() {
6484 Plugins : map [string ]plugin.Plugin {
6585 "configmanager_token_store" : & tokenstore.GRPCPlugin {Impl : ts },
6686 },
87+ //
6788 VersionedPlugins : map [int ]plugin.PluginSet {
6889 1 : {
6990 "configmanager_token_store" : & tokenstore.GRPCPlugin {Impl : ts },
0 commit comments