get.porter.sh/porter@v1.3.0/pkg/storage/plugins/mongodb_docker/plugin.go (about)

     1  package mongodb_docker
     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  // PluginKey is the identifier of the internal mongodb run in docker plugin.
    14  const PluginKey = plugins.PluginInterface + ".porter.mongodb-docker"
    15  
    16  // PluginConfig supported by the mongodb-docker plugin as defined in porter.yaml
    17  type PluginConfig struct {
    18  	Port     string `mapstructure:"port,omitempty"`
    19  	Database string `mapstructure:"database,omitempty"`
    20  
    21  	// Timeout in seconds
    22  	Timeout int `mapstructure:"timeout,omitempty"`
    23  }
    24  
    25  // NewPlugin creates an instance of the storage.porter.mongodb-docker plugin
    26  func NewPlugin(c *portercontext.Context, rawCfg interface{}) (plugin.Plugin, error) {
    27  	cfg := PluginConfig{
    28  		Port:     "27018",
    29  		Database: "porter",
    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  	store := NewStore(c, cfg)
    37  	return pluginstore.NewPlugin(c, store), nil
    38  }