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

Commit 81e145b

Browse files
committed
Merge branch 'develop' into feature/generate-password-with-complex-requirements
2 parents db84f6d + 6dda104 commit 81e145b

26 files changed

Lines changed: 1767 additions & 640 deletions

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
test:
44
docker:
5-
- image: circleci/golang:1.12
5+
- image: circleci/golang:1.13
66
steps:
77
- checkout
88
- restore_cache:
@@ -16,7 +16,7 @@ jobs:
1616
- run: make test
1717
verify-goreleaser:
1818
docker:
19-
- image: goreleaser/goreleaser:v0.117
19+
- image: goreleaser/goreleaser:v0.127
2020
steps:
2121
- checkout
2222
- run: goreleaser check

.gitlab-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
release:
2+
trigger: secrethub/operations/cli-releaser
3+
variables:
4+
SECRETHUB_CLI_VERSION: $CI_COMMIT_TAG
5+
only:
6+
- tags

.goreleaser.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ archives:
5252
checksum:
5353
name_template: "secrethub-{{ .Tag }}-checksums.txt"
5454

55+
release:
56+
draft: true
57+
5558
brews:
5659
- name: secrethub-cli
5760
ids:
@@ -65,19 +68,6 @@ brews:
6568
homepage: https://secrethub.io
6669
description: Command-line interface for SecretHub
6770

68-
snapcrafts:
69-
- name: secrethub-cli
70-
builds:
71-
- default
72-
publish: true
73-
summary: Command-line interface for SecretHub
74-
description: SecretHub is a developer tool to help you keep database passwords, API tokens, and other secrets out of IT automation scripts. It enables you to securely share passwords and other secrets with your team and infrastructure.
75-
apps:
76-
secrethub:
77-
plugs:
78-
- home
79-
- network
80-
8171
scoop:
8272
name: secrethub-cli
8373
bucket:
@@ -90,7 +80,7 @@ scoop:
9080
license: Apache-2.0
9181

9282
nfpms:
93-
- name_template: "secrethub-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
83+
- file_name_template: "secrethub-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
9484
builds:
9585
- without-bin-dir
9686
vendor: SecretHub
@@ -109,4 +99,3 @@ nfpms:
10999
scripts:
110100
postinstall: "scripts/post-install.sh"
111101
postremove: "scripts/post-remove.sh"
112-

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/secrethub/secrethub-cli
22

3-
go 1.12
3+
go 1.13
44

55
require (
66
bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef
@@ -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.23.1-0.20200107095959-f2362c5fc32f
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ 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=
2122
github.com/aws/aws-sdk-go v1.25.49/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
2223
github.com/danieljoos/wincred v1.0.2 h1:zf4bhty2iLuwgjgpraD2E9UbvO+fe54XXGJbOwe23fU=
2324
github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U=
@@ -73,10 +74,10 @@ github.com/secrethub/demo-app v0.1.0 h1:HwPPxuiSvx4TBE7Qppzu3A9eHqmsBrIz4Ko8u8pq
7374
github.com/secrethub/demo-app v0.1.0/go.mod h1:ymjm8+WXTSDTFqsGVBNVmHSnwtZMYi7KptHvpo/fLH4=
7475
github.com/secrethub/secrethub-cli v0.30.0/go.mod h1:dC0wd40v+iQdV83/0rUrOa01LYq+8Yj2AtJB1vzh2ao=
7576
github.com/secrethub/secrethub-go v0.21.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
76-
github.com/secrethub/secrethub-go v0.23.1-0.20200107095959-f2362c5fc32f h1:DcbipEDRfHpTES7Zwk7LyDuUUa7r6H8itIL+cUGaDp4=
77-
github.com/secrethub/secrethub-go v0.23.1-0.20200107095959-f2362c5fc32f/go.mod h1:zJp3b1ebz9art/Li1jOxkb+Sn+Dw/Y7+OMOFtNvK5Aw=
7877
github.com/secrethub/secrethub-go v0.25.0 h1:cpYmkLRurrrw6NNE4PagPNDOn7kvY6UMrnnDxrvuI1M=
7978
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=
8081
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
8182
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8283
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=

internals/cli/env.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ func (a *App) isExtraEnvVar(key string) bool {
103103
// of environment variables are not printed out for security reasons. The list
104104
// is limited to variables that are actually set in the environment. Setting
105105
// verbose to true will also include all known variables that are not set.
106-
func (a *App) PrintEnv(w io.Writer, verbose bool) error {
106+
func (a *App) PrintEnv(w io.Writer, verbose bool, osEnv func() []string) error {
107107
tabWriter := tabwriter.NewWriter(w, 0, 4, 4, ' ', 0)
108108
fmt.Fprintf(tabWriter, "%s\t%s\n", "NAME", "STATUS")
109109

110110
envVarStatus := make(map[string]string)
111-
for _, envVar := range os.Environ() {
111+
for _, envVar := range osEnv() {
112112
key, _, match := splitVar(a.name, a.separator, envVar)
113113
key = strings.ToUpper(key)
114114
if match {
@@ -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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (app *App) registerCommands() {
163163
NewAccountCommand(app.io, app.clientFactory.NewClient, app.credentialStore).Register(app.cli)
164164
NewCredentialCommand(app.io, app.clientFactory, app.credentialStore).Register(app.cli)
165165
NewConfigCommand(app.io, app.credentialStore).Register(app.cli)
166+
NewEnvCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
166167

167168
// Commands
168169
NewInitCommand(app.io, app.clientFactory.NewUnauthenticatedClient, app.clientFactory.NewClientWithCredentials, app.credentialStore).Register(app.cli)
@@ -177,7 +178,7 @@ func (app *App) registerCommands() {
177178
NewInspectCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
178179
NewAuditCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
179180
NewInjectCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
180-
NewRunCommand(app.clientFactory.NewClient).Register(app.cli)
181+
NewRunCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
181182
NewPrintEnvCommand(app.cli, app.io).Register(app.cli)
182183

183184
// Hidden commands

internals/secrethub/env.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package secrethub
2+
3+
import (
4+
"github.com/secrethub/secrethub-cli/internals/cli/ui"
5+
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
6+
)
7+
8+
// EnvCommand handles operations regarding environment variables.
9+
type EnvCommand struct {
10+
io ui.IO
11+
newClient newClientFunc
12+
}
13+
14+
// NewEnvCommand creates a new EnvCommand.
15+
func NewEnvCommand(io ui.IO, newClient newClientFunc) *EnvCommand {
16+
return &EnvCommand{
17+
io: io,
18+
newClient: newClient,
19+
}
20+
}
21+
22+
// Register registers the command and its sub-commands on the provided Registerer.
23+
func (cmd *EnvCommand) Register(r command.Registerer) {
24+
clause := r.Command("env", "[BETA] Manage environment variables.").Hidden()
25+
clause.HelpLong("This command is hidden because it is still in beta. Future versions may break.")
26+
NewEnvReadCommand(cmd.io, cmd.newClient).Register(clause)
27+
NewEnvListCommand(cmd.io).Register(clause)
28+
}

internals/secrethub/env_ls.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package secrethub
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/secrethub/secrethub-cli/internals/cli/ui"
7+
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
8+
)
9+
10+
// EnvListCommand is a command to list all environment variable keys set in the process of `secrethub run`.
11+
type EnvListCommand struct {
12+
io ui.IO
13+
environment *environment
14+
}
15+
16+
// NewEnvListCommand creates a new EnvListCommand.
17+
func NewEnvListCommand(io ui.IO) *EnvListCommand {
18+
return &EnvListCommand{
19+
io: io,
20+
environment: newEnvironment(io),
21+
}
22+
}
23+
24+
// Register adds a CommandClause and it's args and flags to a Registerer.
25+
func (cmd *EnvListCommand) Register(r command.Registerer) {
26+
clause := r.Command("ls", "[BETA] List environment variable names that will be populated with secrets.")
27+
clause.HelpLong("This command is hidden because it is still in beta. Future versions may break.")
28+
clause.Alias("list")
29+
30+
cmd.environment.register(clause)
31+
32+
command.BindAction(clause, cmd.Run)
33+
}
34+
35+
// Run executes the command.
36+
func (cmd *EnvListCommand) Run() error {
37+
env, err := cmd.environment.env()
38+
if err != nil {
39+
return err
40+
}
41+
42+
for key, value := range env {
43+
// For now only environment variables in which a secret is loaded are printed.
44+
// TODO: Make this behavior configurable.
45+
if value.containsSecret() {
46+
fmt.Fprintln(cmd.io.Stdout(), key)
47+
}
48+
}
49+
50+
return nil
51+
}

0 commit comments

Comments
 (0)