Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 549b444

Browse files
Merge pull request #242 from secrethub/release/v0.34.0
Release v0.34.0
2 parents 68abbee + 312855e commit 549b444

22 files changed

Lines changed: 442 additions & 115 deletions

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef
77
github.com/alecthomas/kingpin v0.0.0-20191009151950-9e366cbf24ad
88
github.com/atotto/clipboard v0.1.2
9-
github.com/aws/aws-sdk-go v1.19.38
9+
github.com/aws/aws-sdk-go v1.25.49
1010
github.com/docker/go-units v0.3.3
1111
github.com/fatih/color v1.7.0
1212
github.com/masterzen/winrm v0.0.0-20190308153735-1d17eaf15943
@@ -16,7 +16,7 @@ require (
1616
github.com/mitchellh/mapstructure v1.1.2
1717
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
1818
github.com/secrethub/demo-app v0.1.0
19-
github.com/secrethub/secrethub-go v0.25.0
19+
github.com/secrethub/secrethub-go v0.26.0
2020
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
2121
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a
2222
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzb
1818
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
1919
github.com/aws/aws-sdk-go v1.19.38 h1:WKjobgPO4Ua1ww2NJJl2/zQNreUZxvqmEzwMlRjjm9g=
2020
github.com/aws/aws-sdk-go v1.19.38/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
21+
github.com/aws/aws-sdk-go v1.25.49 h1:j5R2Ey+g8qaiy2NJ9iH+KWzDWS4SjXRCjhc22EeQVE4=
22+
github.com/aws/aws-sdk-go v1.25.49/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
2123
github.com/danieljoos/wincred v1.0.2 h1:zf4bhty2iLuwgjgpraD2E9UbvO+fe54XXGJbOwe23fU=
2224
github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U=
2325
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
@@ -74,6 +76,8 @@ github.com/secrethub/secrethub-cli v0.30.0/go.mod h1:dC0wd40v+iQdV83/0rUrOa01LYq
7476
github.com/secrethub/secrethub-go v0.21.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
7577
github.com/secrethub/secrethub-go v0.25.0 h1:cpYmkLRurrrw6NNE4PagPNDOn7kvY6UMrnnDxrvuI1M=
7678
github.com/secrethub/secrethub-go v0.25.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
79+
github.com/secrethub/secrethub-go v0.26.0 h1:BonMEvD3rdAQyY3L91Ze7Mkq0KXXhB3Esn/cDUq3qYc=
80+
github.com/secrethub/secrethub-go v0.26.0/go.mod h1:Wr4gXWrk8OvBHiCttjLq7wFdKSm07rlEhq5OSYPemtI=
7781
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
7882
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7983
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=

internals/cli/env.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ func (a *App) PrintEnv(w io.Writer, verbose bool) error {
148148
return nil
149149
}
150150

151+
// CheckStrictEnv checks that every environment variable that starts with the app name is recognized by the application.
152+
func (a *App) CheckStrictEnv() error {
153+
for _, envVar := range os.Environ() {
154+
key, _, match := splitVar(a.name, a.separator, envVar)
155+
if match {
156+
key = strings.ToUpper(key)
157+
_, isKnown := a.knownEnvVars[key]
158+
if !(isKnown || a.isExtraEnvVar(key)) {
159+
return fmt.Errorf("environment variable set, but not recognized: %s", key)
160+
}
161+
}
162+
}
163+
return nil
164+
}
165+
151166
// CommandClause represents a command clause in a command0-line application.
152167
type CommandClause struct {
153168
*kingpin.CmdClause

internals/secrethub/acl_check.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"sort"
66
"text/tabwriter"
77

8+
"github.com/secrethub/secrethub-go/pkg/secretpath"
9+
810
"github.com/secrethub/secrethub-cli/internals/cli/ui"
911
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
1012

@@ -38,12 +40,7 @@ func (cmd *ACLCheckCommand) Register(r command.Registerer) {
3840

3941
// Run prints the access level(s) on the given directory.
4042
func (cmd *ACLCheckCommand) Run() error {
41-
client, err := cmd.newClient()
42-
if err != nil {
43-
return err
44-
}
45-
46-
levels, err := client.AccessRules().ListLevels(cmd.path.Value())
43+
levels, err := cmd.listLevels()
4744
if err != nil {
4845
return err
4946
}
@@ -79,3 +76,33 @@ func (cmd *ACLCheckCommand) Run() error {
7976

8077
return nil
8178
}
79+
80+
func (cmd *ACLCheckCommand) listLevels() ([]*api.AccessLevel, error) {
81+
client, err := cmd.newClient()
82+
if err != nil {
83+
return nil, err
84+
}
85+
86+
path := cmd.path.Value()
87+
88+
levels, listLevelsErr := client.AccessRules().ListLevels(path)
89+
if listLevelsErr == nil {
90+
return levels, nil
91+
}
92+
if !api.IsErrNotFound(listLevelsErr) {
93+
return nil, listLevelsErr
94+
}
95+
96+
isSecret, isSecretErr := client.Secrets().Exists(path)
97+
if isSecretErr != nil {
98+
return nil, listLevelsErr
99+
}
100+
if isSecret {
101+
levels, err = client.AccessRules().ListLevels(secretpath.Parent(path))
102+
if err != nil {
103+
return nil, err
104+
}
105+
return levels, nil
106+
}
107+
return nil, listLevelsErr
108+
}

internals/secrethub/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (app *App) registerCommands() {
177177
NewInspectCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
178178
NewAuditCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
179179
NewInjectCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
180-
NewRunCommand(app.clientFactory.NewClient).Register(app.cli)
180+
NewRunCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
181181
NewPrintEnvCommand(app.cli, app.io).Register(app.cli)
182182

183183
// Hidden commands

internals/secrethub/inject.go

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"io/ioutil"
66
"os"
77
"path/filepath"
8-
"strings"
98
"time"
109

10+
"github.com/secrethub/secrethub-cli/internals/secrethub/tpl"
11+
1112
"github.com/secrethub/secrethub-cli/internals/cli/clip"
1213
"github.com/secrethub/secrethub-cli/internals/cli/filemode"
1314
"github.com/secrethub/secrethub-cli/internals/cli/posix"
1415
"github.com/secrethub/secrethub-cli/internals/cli/ui"
15-
"github.com/secrethub/secrethub-cli/internals/cli/validation"
1616
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
1717

1818
"github.com/docker/go-units"
@@ -26,17 +26,18 @@ var (
2626

2727
// InjectCommand is a command to read a secret.
2828
type InjectCommand struct {
29-
outFile string
30-
inFile string
31-
fileMode filemode.FileMode
32-
force bool
33-
io ui.IO
34-
useClipboard bool
35-
clearClipboardAfter time.Duration
36-
clipper clip.Clipper
37-
newClient newClientFunc
38-
templateVars map[string]string
39-
templateVersion string
29+
outFile string
30+
inFile string
31+
fileMode filemode.FileMode
32+
force bool
33+
io ui.IO
34+
useClipboard bool
35+
clearClipboardAfter time.Duration
36+
clipper clip.Clipper
37+
newClient newClientFunc
38+
templateVars map[string]string
39+
templateVersion string
40+
dontPromptMissingTemplateVars bool
4041
}
4142

4243
// NewInjectCommand creates a new InjectCommand.
@@ -67,6 +68,7 @@ func (cmd *InjectCommand) Register(r command.Registerer) {
6768
clause.Flag("file-mode", "Set filemode for the output file if it does not yet exist. Defaults to 0600 (read and write for current user) and is ignored without the --out-file flag.").Default("0600").SetValue(&cmd.fileMode)
6869
clause.Flag("var", "Define the value for a template variable with `VAR=VALUE`, e.g. --var env=prod").Short('v').StringMapVar(&cmd.templateVars)
6970
clause.Flag("template-version", "The template syntax version to be used. The options are v1, v2, latest or auto to automatically detect the version.").Default("auto").StringVar(&cmd.templateVersion)
71+
clause.Flag("no-prompt", "Do not prompt when a template variable is missing and return an error instead.").BoolVar(&cmd.dontPromptMissingTemplateVars)
7072
registerForceFlag(clause).BoolVar(&cmd.force)
7173

7274
command.BindAction(clause, cmd.Run)
@@ -97,25 +99,16 @@ func (cmd *InjectCommand) Run() error {
9799
}
98100
}
99101

100-
templateVars := make(map[string]string)
101-
102102
osEnv, _ := parseKeyValueStringsToMap(os.Environ())
103103

104-
for k, v := range osEnv {
105-
if strings.HasPrefix(k, templateVarEnvVarPrefix) {
106-
k = strings.TrimPrefix(k, templateVarEnvVarPrefix)
107-
templateVars[strings.ToLower(k)] = v
108-
}
109-
}
110-
111-
for k, v := range cmd.templateVars {
112-
templateVars[strings.ToLower(k)] = v
104+
var templateVariableReader tpl.VariableReader
105+
templateVariableReader, err = newVariableReader(osEnv, cmd.templateVars)
106+
if err != nil {
107+
return err
113108
}
114109

115-
for k := range templateVars {
116-
if !validation.IsEnvarNamePosix(k) {
117-
return ErrInvalidTemplateVar(k)
118-
}
110+
if !cmd.dontPromptMissingTemplateVars {
111+
templateVariableReader = newPromptMissingVariableReader(templateVariableReader, cmd.io)
119112
}
120113

121114
parser, err := getTemplateParser(raw, cmd.templateVersion)
@@ -128,7 +121,7 @@ func (cmd *InjectCommand) Run() error {
128121
return err
129122
}
130123

131-
injected, err := template.Evaluate(templateVars, newSecretReader(cmd.newClient))
124+
injected, err := template.Evaluate(templateVariableReader, newSecretReader(cmd.newClient))
132125
if err != nil {
133126
return err
134127
}

internals/secrethub/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ func (cmd *LsCommand) Run() error {
8383
dirPath, err := cmd.path.ToDirPath()
8484
if err == nil {
8585
dirFS, err := client.Dirs().GetTree(dirPath.Value(), 1, false)
86-
if err == api.ErrDirNotFound && dirPath.IsRepoPath() {
86+
if api.IsErrNotFound(err) && dirPath.IsRepoPath() {
8787
return err
88-
} else if err != nil && err != api.ErrDirNotFound {
88+
} else if err != nil && !isErrNotFound(err) {
8989
return err
9090
} else if err == nil {
9191
err = printDir(cmd.io.Stdout(), cmd.quiet, dirFS.RootDir, timeFormatter)
@@ -100,7 +100,7 @@ func (cmd *LsCommand) Run() error {
100100
secretPath, err := cmd.path.ToSecretPath()
101101
if err == nil {
102102
versions, err := client.Secrets().Versions().ListWithoutData(secretPath.Value())
103-
if err == api.ErrSecretNotFound {
103+
if api.IsErrNotFound(err) {
104104
return ErrResourceNotFound(cmd.path)
105105
} else if err != nil {
106106
return err

internals/secrethub/org.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func NewOrgCommand(io ui.IO, newClient newClientFunc) *OrgCommand {
2222
// Register registers the command and its sub-commands on the provided Registerer.
2323
func (cmd *OrgCommand) Register(r command.Registerer) {
2424
clause := r.Command("org", "Manage shared organization workspaces.")
25+
clause.Alias("organization")
26+
clause.Alias("organisation")
27+
clause.Alias("orgs")
28+
clause.Alias("organizations")
29+
clause.Alias("organisations")
2530
NewOrgInitCommand(cmd.io, cmd.newClient).Register(clause)
2631
NewOrgInspectCommand(cmd.io, cmd.newClient).Register(clause)
2732
NewOrgInviteCommand(cmd.io, cmd.newClient).Register(clause)

internals/secrethub/org_list_users.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func NewOrgListUsersCommand(io ui.IO, newClient newClientFunc) *OrgListUsersComm
3131
// Register registers the command, arguments and flags on the provided Registerer.
3232
func (cmd *OrgListUsersCommand) Register(r command.Registerer) {
3333
clause := r.Command("list-users", "List all members of an organization.")
34+
clause.Alias("list-members")
3435
clause.Arg("org-name", "The organization name").Required().SetValue(&cmd.orgName)
3536
registerTimestampFlag(clause).BoolVar(&cmd.useTimestamps)
3637

internals/secrethub/repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ func NewRepoCommand(io ui.IO, newClient newClientFunc) *RepoCommand {
2222
// Register registers the command and its sub-commands on the provided Registerer.
2323
func (cmd *RepoCommand) Register(r command.Registerer) {
2424
clause := r.Command("repo", "Manage repositories.")
25+
clause.Alias("repository")
26+
clause.Alias("repos")
27+
clause.Alias("repositories")
2528
NewRepoInitCommand(cmd.io, cmd.newClient).Register(clause)
2629
NewRepoInspectCommand(cmd.io, cmd.newClient).Register(clause)
2730
NewRepoInviteCommand(cmd.io, cmd.newClient).Register(clause)

0 commit comments

Comments
 (0)