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

Commit eecbb0b

Browse files
authored
Merge pull request #251 from secrethub/release/v0.35.0
Release v0.35.0
2 parents 549b444 + d4a1f86 commit eecbb0b

9 files changed

Lines changed: 401 additions & 28 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
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:

.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: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,6 @@ brews:
6565
homepage: https://secrethub.io
6666
description: Command-line interface for SecretHub
6767

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-
8168
scoop:
8269
name: secrethub-cli
8370
bucket:

go.mod

Lines changed: 1 addition & 1 deletion
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

internals/cli/env.go

Lines changed: 2 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 {

internals/secrethub/inject.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type InjectCommand struct {
3434
useClipboard bool
3535
clearClipboardAfter time.Duration
3636
clipper clip.Clipper
37+
osEnv []string
3738
newClient newClientFunc
3839
templateVars map[string]string
3940
templateVersion string
@@ -44,6 +45,7 @@ type InjectCommand struct {
4445
func NewInjectCommand(io ui.IO, newClient newClientFunc) *InjectCommand {
4546
return &InjectCommand{
4647
clipper: clip.NewClipboard(),
48+
osEnv: os.Environ(),
4749
clearClipboardAfter: defaultClearClipboardAfter,
4850
io: io,
4951
newClient: newClient,
@@ -99,7 +101,7 @@ func (cmd *InjectCommand) Run() error {
99101
}
100102
}
101103

102-
osEnv, _ := parseKeyValueStringsToMap(os.Environ())
104+
osEnv, _ := parseKeyValueStringsToMap(cmd.osEnv)
103105

104106
var templateVariableReader tpl.VariableReader
105107
templateVariableReader, err = newVariableReader(osEnv, cmd.templateVars)

internals/secrethub/printenv.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package secrethub
22

33
import (
4+
"os"
5+
46
"github.com/secrethub/secrethub-cli/internals/cli"
57
"github.com/secrethub/secrethub-cli/internals/cli/ui"
68
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
@@ -10,20 +12,22 @@ import (
1012
type PrintEnvCommand struct {
1113
app *cli.App
1214
io ui.IO
15+
osEnv func() []string
1316
verbose bool
1417
}
1518

1619
// NewPrintEnvCommand creates a new PrintEnvCommand.
1720
func NewPrintEnvCommand(app *cli.App, io ui.IO) *PrintEnvCommand {
1821
return &PrintEnvCommand{
19-
app: app,
20-
io: io,
22+
app: app,
23+
io: io,
24+
osEnv: os.Environ,
2125
}
2226
}
2327

2428
// Run prints out debug statements about all environment variables.
2529
func (cmd *PrintEnvCommand) Run() error {
26-
err := cmd.app.PrintEnv(cmd.io.Stdout(), cmd.verbose)
30+
err := cmd.app.PrintEnv(cmd.io.Stdout(), cmd.verbose, cmd.osEnv)
2731
if err != nil {
2832
return err
2933
}

internals/secrethub/run.go

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const (
4949
// templateVarEnvVarPrefix is used to prefix environment variables
5050
// that should be used as template variables.
5151
templateVarEnvVarPrefix = "SECRETHUB_VAR_"
52+
// prefix of the values of environment variables that will be
53+
// substituted with secrets
54+
secretReferencePrefix = "secrethub://"
5255
)
5356

5457
// RunCommand runs a program and passes environment variables to it that are
@@ -57,6 +60,7 @@ const (
5760
type RunCommand struct {
5861
command []string
5962
io ui.IO
63+
osEnv []string
6064
envar map[string]string
6165
envFile string
6266
templateVars map[string]string
@@ -73,6 +77,7 @@ type RunCommand struct {
7377
func NewRunCommand(io ui.IO, newClient newClientFunc) *RunCommand {
7478
return &RunCommand{
7579
io: io,
80+
osEnv: os.Environ(),
7681
envar: make(map[string]string),
7782
templateVars: make(map[string]string),
7883
newClient: newClient,
@@ -110,6 +115,11 @@ func (cmd *RunCommand) Run() error {
110115
// Parse
111116
envSources := []EnvSource{}
112117

118+
osEnv, passthroughEnv := parseKeyValueStringsToMap(cmd.osEnv)
119+
120+
referenceEnv := newReferenceEnv(osEnv)
121+
envSources = append(envSources, referenceEnv)
122+
113123
// TODO: Validate the flags when parsing by implementing the Flag interface for EnvFlags.
114124
flagSource, err := NewEnvFlags(cmd.envar)
115125
if err != nil {
@@ -129,11 +139,6 @@ func (cmd *RunCommand) Run() error {
129139
}
130140
}
131141

132-
osEnv, passthroughEnv := parseKeyValueStringsToMap(os.Environ())
133-
if err != nil {
134-
return err
135-
}
136-
137142
if cmd.envFile != "" {
138143
templateVariableReader, err := newVariableReader(osEnv, cmd.templateVars)
139144
if err != nil {
@@ -233,14 +238,14 @@ func (cmd *RunCommand) Run() error {
233238
}
234239
}
235240

236-
maskedStdout := masker.NewMaskedWriter(os.Stdout, valuesToMask, maskString, cmd.maskingTimeout)
241+
maskedStdout := masker.NewMaskedWriter(cmd.io.Stdout(), valuesToMask, maskString, cmd.maskingTimeout)
237242
maskedStderr := masker.NewMaskedWriter(os.Stderr, valuesToMask, maskString, cmd.maskingTimeout)
238243

239244
command := exec.Command(cmd.command[0], cmd.command[1:]...)
240245
command.Env = append(passthroughEnv, mapToKeyValueStrings(environment)...)
241246
command.Stdin = os.Stdin
242247
if cmd.noMasking {
243-
command.Stdout = os.Stdout
248+
command.Stdout = cmd.io.Stdout()
244249
command.Stderr = os.Stderr
245250
} else {
246251
command.Stdout = maskedStdout
@@ -422,6 +427,44 @@ func ReadEnvFile(filepath string, varReader tpl.VariableReader, parser tpl.Parse
422427
}, nil
423428
}
424429

430+
// referenceEnv is an environment with secrets configured with the
431+
// secrethub:// syntax in the os environment variables.
432+
type referenceEnv struct {
433+
envVars map[string]string
434+
}
435+
436+
// newReferenceEnv returns an environment with secrets configured in the
437+
// os environment with the secrethub:// syntax.
438+
func newReferenceEnv(osEnv map[string]string) *referenceEnv {
439+
envVars := make(map[string]string)
440+
for key, value := range osEnv {
441+
if strings.HasPrefix(value, secretReferencePrefix) {
442+
envVars[key] = strings.TrimPrefix(value, secretReferencePrefix)
443+
}
444+
}
445+
return &referenceEnv{
446+
envVars: envVars,
447+
}
448+
}
449+
450+
// Env returns a map of key value pairs with the secrets configured with the
451+
// secrethub:// syntax.
452+
func (env *referenceEnv) Env(_ map[string]string, secretReader tpl.SecretReader) (map[string]string, error) {
453+
envVarsWithSecrets := make(map[string]string)
454+
for key, path := range env.envVars {
455+
secret, err := secretReader.ReadSecret(path)
456+
if err != nil {
457+
return nil, err
458+
}
459+
envVarsWithSecrets[key] = secret
460+
}
461+
return envVarsWithSecrets, nil
462+
}
463+
464+
func (env *referenceEnv) Secrets() []string {
465+
return nil
466+
}
467+
425468
// EnvFile contains an environment that is read from a file.
426469
type EnvFile struct {
427470
path string

0 commit comments

Comments
 (0)