Skip to content

Commit

Permalink
📝 Add implementation details
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-drprasad committed May 11, 2020
1 parent 244e720 commit efd772d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
15 changes: 7 additions & 8 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"fmt"
"errors"
"os"

"github.com/dev-drprasad/porter-hashicorp-plugins/pkg"
Expand All @@ -13,18 +13,17 @@ var runCmd = &cobra.Command{
Short: "Run the plugin and listen for client connections.",
Args: cobra.ExactValidArgs(1),
ValidArgs: []string{pkg.VaultPluginInterface},
Run: func(cmd *cobra.Command, args []string) {
p.Run(args)
RunE: func(cmd *cobra.Command, args []string) error {
return p.Run(args)
},
PreRun: func(cmd *cobra.Command, args []string) {
PreRunE: func(cmd *cobra.Command, args []string) error {
si, err := os.Stdin.Stat()
if err != nil {
fmt.Fprint(p.Err, "could not get stdin info")
os.Exit(1)
return errors.New("could not get stdin info")
}
if (si.Mode() & os.ModeCharDevice) == os.ModeCharDevice {
fmt.Fprintf(p.Err, "This binary is a Porter plugin. It is not meant to be executed directly.")
os.Exit(126)
return errors.New("this binary is a Porter plugin. It is not meant to be executed directly")
}
return nil
},
}
26 changes: 15 additions & 11 deletions pkg/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func New() *PluginBox {
}
}

func (p *PluginBox) Run(args []string) {
func (p *PluginBox) Run(args []string) error {
if err := json.NewDecoder(p.In).Decode(&p.Config); err != nil {
fmt.Fprint(p.Err, errors.Wrapf(err, "could not unmarshal config from input"))
return errors.Wrapf(err, "could not unmarshal config from input")
}

var plugin plugin.Plugin
Expand All @@ -49,23 +49,27 @@ func (p *PluginBox) Run(args []string) {
}

if plugin == nil {
fmt.Fprintf(p.Err, "invalid plugin interface specified: %q", key)
return
return errors.New(fmt.Sprintf("invalid plugin interface specified: %q", key))
}

parts := strings.Split(key, ".")
selectedInterface := parts[0]
plugins.Serve(selectedInterface, plugin)

return nil
}

func (p *PluginBox) PrintVersion(opts version.Options) error {
metadata := pkgmgmt.Metadata{
Name: "hashicorp",
VersionInfo: pkgmgmt.VersionInfo{
Version: Version,
Commit: Commit,
Author: "REDDY PRASAD (@dev-drprasad)",
metadata := plugins.Metadata{
Metadata: pkgmgmt.Metadata{
Name: "hashicorp",
VersionInfo: pkgmgmt.VersionInfo{
Version: Version,
Commit: Commit,
Author: "REDDY PRASAD (@dev-drprasad)",
},
},
Implementations: []plugins.Implementation{
{Type: "secrets", Name: "vault"},
},
}

Expand Down

0 comments on commit efd772d

Please sign in to comment.