Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ go 1.13

require (
bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef
cloud.google.com/go v0.57.0 // indirect
github.com/alecthomas/kingpin v1.3.8-0.20200323085623-b6657d9477a6
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf
github.com/atotto/clipboard v0.1.2
github.com/aws/aws-sdk-go v1.25.49
github.com/docker/go-units v0.3.3
Expand All @@ -16,10 +18,12 @@ require (
github.com/mitchellh/mapstructure v1.1.2
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/secrethub/demo-app v0.1.0
github.com/secrethub/secrethub-go v0.28.0
github.com/secrethub/secrethub-go v0.27.1-0.20200603102047-1a4e50eafb91
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
golang.org/x/text v0.3.0
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/sys v0.0.0-20200501052902-10377860bb8e
golang.org/x/text v0.3.2
google.golang.org/api v0.25.0 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
gopkg.in/yaml.v2 v2.2.2
)
300 changes: 298 additions & 2 deletions go.sum

Large diffs are not rendered by default.

38 changes: 32 additions & 6 deletions internals/cli/ui/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,28 @@ func (o Option) String() string {
return o.Display
}

func ChooseDynamicOptionsValidate(io IO, question string, getOptions func() ([]Option, bool, error), optionName string, validateFunc func(string) error) (string, error) {
r, w, err := io.Prompts()
if err != nil {
return "", err
}

if optionName == "" {
optionName = "option"
}

s := selecter{
r: r,
w: w,
getOptions: getOptions,
question: question,
addOwn: true,
validateFunc: validateFunc,
optionName: optionName,
}
return s.run()
}

func ChooseDynamicOptions(io IO, question string, getOptions func() ([]Option, bool, error), addOwn bool, optionName string) (string, error) {
r, w, err := io.Prompts()
if err != nil {
Expand All @@ -294,12 +316,13 @@ func ChooseDynamicOptions(io IO, question string, getOptions func() ([]Option, b
}

type selecter struct {
r io.Reader
w io.Writer
getOptions func() ([]Option, bool, error)
question string
addOwn bool
optionName string
r io.Reader
w io.Writer
getOptions func() ([]Option, bool, error)
validateFunc func(string) error
question string
addOwn bool
optionName string

done bool
options []Option
Expand Down Expand Up @@ -359,6 +382,9 @@ func (s *selecter) process() (string, error) {
choice, err := strconv.Atoi(in)
if err != nil || choice < 1 || choice > len(s.options) {
if s.addOwn {
if s.validateFunc != nil {
return in, s.validateFunc(in)
}
return in, nil
}

Expand Down
2 changes: 2 additions & 0 deletions internals/secrethub/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (f *clientFactory) NewClient() (secrethub.ClientInterface, error) {
switch strings.ToLower(f.identityProvider) {
case "aws":
credentialProvider = credentials.UseAWS()
case "gcp":
credentialProvider = credentials.UseGCPServiceAccount()
case "key":
credentialProvider = f.store.Provider()
default:
Expand Down
1 change: 1 addition & 0 deletions internals/secrethub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewServiceCommand(io ui.IO, newClient newClientFunc) *ServiceCommand {
func (cmd *ServiceCommand) Register(r command.Registerer) {
clause := r.Command("service", "Manage service accounts.")
NewServiceAWSCommand(cmd.io, cmd.newClient).Register(clause)
NewServiceGCPCommand(cmd.io, cmd.newClient).Register(clause)
NewServiceDeployCommand(cmd.io).Register(clause)
NewServiceInitCommand(cmd.io, cmd.newClient).Register(clause)
NewServiceLsCommand(cmd.io, cmd.newClient).Register(clause)
Expand Down
27 changes: 27 additions & 0 deletions internals/secrethub/service_gcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package secrethub

import (
"github.com/secrethub/secrethub-cli/internals/cli/ui"
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
)

// ServiceGCPCommand handles GCP services.
type ServiceGCPCommand struct {
io ui.IO
newClient newClientFunc
}

// NewServiceGCPCommand creates a new ServiceGCPCommand.
func NewServiceGCPCommand(io ui.IO, newClient newClientFunc) *ServiceGCPCommand {
return &ServiceGCPCommand{
io: io,
newClient: newClient,
}
}

// Register registers the command and its sub-commands on the provided Registerer.
func (cmd *ServiceGCPCommand) Register(r command.Registerer) {
clause := r.Command("gcp", "Manage GCP service accounts.").Hidden()
NewServiceGCPInitCommand(cmd.io, cmd.newClient).Register(clause)
NewServiceGCPLsCommand(cmd.io, cmd.newClient).Register(clause)
}
Loading