Skip to content

Commit

Permalink
Init POC
Browse files Browse the repository at this point in the history
  • Loading branch information
biazmoreira committed Sep 18, 2023
1 parent b5b809b commit dcf6297
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 475 deletions.
32 changes: 0 additions & 32 deletions cmd/vault-plugin-scaffolding/main.go

This file was deleted.

13 changes: 13 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hcpvaultengine

import "github.com/mitchellh/cli"

func InitHCPCommand(ui cli.Ui) map[string]cli.CommandFactory {
return map[string]cli.CommandFactory{
"connect": func() (cli.Command, error) {
return &HCPConnectCommand{
Ui: ui,
}, nil
},
}
}
3 changes: 3 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package hcpvaultengine

// TODO
58 changes: 58 additions & 0 deletions connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package hcpvaultengine

import (
"flag"
"fmt"

"github.com/mitchellh/cli"
)

var (
_ cli.Command = (*HCPConnectCommand)(nil)
)

type HCPConnectCommand struct {
Ui cli.Ui

flagNonInteractiveMethod bool

connectHandler ConnectHandler
}

func (c *HCPConnectCommand) Help() string {
//TODO implement me
panic("implement me")
}

func (c *HCPConnectCommand) Run(args []string) int {
f := c.Flags()

if err := f.Parse(args); err != nil {
c.Ui.Error(err.Error())
return 1
}

if c.flagNonInteractiveMethod {
c.connectHandler = &nonInteractiveConnectHandler{}
} else {
c.connectHandler = &interactiveConnectHandler{}
}

authStatus, err := c.connectHandler.Connect(args)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to connect to HCP: %s", err))
return 1
}

return 0
}

func (c *HCPConnectCommand) Synopsis() string {
return "Authenticate to HCP"
}

func (c *HCPConnectCommand) Flags() *flag.FlagSet {
mainSet := flag.NewFlagSet("", flag.ContinueOnError)
mainSet.Var(&boolValue{target: &c.flagNonInteractiveMethod}, "non-interactive", "")
return mainSet
}
27 changes: 27 additions & 0 deletions connect_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hcpvaultengine

type AuthStatus struct {
Token string //should this be encrypted? how?
}

var (
_ ConnectHandler = (*interactiveConnectHandler)(nil)
_ ConnectHandler = (*nonInteractiveConnectHandler)(nil)
)

type ConnectHandler interface {
// should we parse this before [during the Run function common flag parsin] into a struct that's specific to the different handlers?
Connect(args []string) (AuthStatus, error)
}

type interactiveConnectHandler struct{}

func (h *interactiveConnectHandler) Connect(args []string) (AuthStatus, error) {
return AuthStatus{}, nil
}

type nonInteractiveConnectHandler struct{}

func (h *nonInteractiveConnectHandler) Connect(args []string) (AuthStatus, error) {
return AuthStatus{}, nil
}
21 changes: 21 additions & 0 deletions flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hcpvaultengine

import "strconv"

type boolValue struct {
target *bool
}

func (v *boolValue) String() string {
return strconv.FormatBool(*v.target)
}

func (v *boolValue) Set(s string) error {
value, err := strconv.ParseBool(s)
if err != nil {
return err
}

*v.target = value
return nil
}
50 changes: 4 additions & 46 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,59 +1,17 @@
module github.com/hashicorp/vault-plugin-scaffolding

go 1.20
go 1.21

require (
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/vault/api v1.9.2
github.com/hashicorp/vault/sdk v0.9.1
)
require github.com/mitchellh/cli v1.0.0

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/frankban/quicktest v1.14.2 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-kms-wrapping/v2 v2.0.8 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.8 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/mlock v0.1.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.8.0 // indirect
github.com/posener/complete v1.1.1 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)
Loading

0 comments on commit dcf6297

Please sign in to comment.