get.porter.sh/porter@v1.3.0/pkg/storage/plugins/mongodb/plugin.go (about) 1 package mongodb 2 3 import ( 4 "fmt" 5 6 "get.porter.sh/porter/pkg/portercontext" 7 "get.porter.sh/porter/pkg/storage/plugins" 8 "get.porter.sh/porter/pkg/storage/pluginstore" 9 "github.com/hashicorp/go-plugin" 10 "github.com/mitchellh/mapstructure" 11 ) 12 13 const PluginKey = plugins.PluginInterface + ".porter.mongodb" 14 15 var _ plugins.StorageProtocol = Plugin{} 16 17 type Plugin struct { 18 *Store 19 } 20 21 // PluginConfig are the configuration settings that can be defined for the 22 // mongodb plugin in porter.yaml 23 type PluginConfig struct { 24 URL string `mapstructure:"url"` 25 Timeout int `mapstructure:"timeout,omitempty"` 26 } 27 28 func NewPlugin(c *portercontext.Context, rawCfg interface{}) (plugin.Plugin, error) { 29 cfg := PluginConfig{ 30 Timeout: 10, 31 } 32 if err := mapstructure.Decode(rawCfg, &cfg); err != nil { 33 return nil, fmt.Errorf("error reading plugin configuration: %w", err) 34 } 35 36 impl := NewStore(c, cfg) 37 return pluginstore.NewPlugin(c, impl), nil 38 }