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

Commit 9e957d0

Browse files
committed
Change osEnv to slice instead of function
1 parent f7dd9b1 commit 9e957d0

3 files changed

Lines changed: 8 additions & 18 deletions

File tree

internals/secrethub/inject.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type InjectCommand struct {
3434
useClipboard bool
3535
clearClipboardAfter time.Duration
3636
clipper clip.Clipper
37-
osEnv func() []string
37+
osEnv []string
3838
newClient newClientFunc
3939
templateVars map[string]string
4040
templateVersion string
@@ -45,7 +45,7 @@ type InjectCommand struct {
4545
func NewInjectCommand(io ui.IO, newClient newClientFunc) *InjectCommand {
4646
return &InjectCommand{
4747
clipper: clip.NewClipboard(),
48-
osEnv: os.Environ,
48+
osEnv: os.Environ(),
4949
clearClipboardAfter: defaultClearClipboardAfter,
5050
io: io,
5151
newClient: newClient,
@@ -101,7 +101,7 @@ func (cmd *InjectCommand) Run() error {
101101
}
102102
}
103103

104-
osEnv, _ := parseKeyValueStringsToMap(cmd.osEnv())
104+
osEnv, _ := parseKeyValueStringsToMap(cmd.osEnv)
105105

106106
var templateVariableReader tpl.VariableReader
107107
templateVariableReader, err = newVariableReader(osEnv, cmd.templateVars)

internals/secrethub/run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const (
6060
type RunCommand struct {
6161
command []string
6262
io ui.IO
63-
osEnv func() []string
63+
osEnv []string
6464
envar map[string]string
6565
envFile string
6666
templateVars map[string]string
@@ -77,7 +77,7 @@ type RunCommand struct {
7777
func NewRunCommand(io ui.IO, newClient newClientFunc) *RunCommand {
7878
return &RunCommand{
7979
io: io,
80-
osEnv: os.Environ,
80+
osEnv: os.Environ(),
8181
envar: make(map[string]string),
8282
templateVars: make(map[string]string),
8383
newClient: newClient,
@@ -115,7 +115,7 @@ func (cmd *RunCommand) Run() error {
115115
// Parse
116116
envSources := []EnvSource{}
117117

118-
osEnv, passthroughEnv := parseKeyValueStringsToMap(cmd.osEnv())
118+
osEnv, passthroughEnv := parseKeyValueStringsToMap(cmd.osEnv)
119119

120120
referenceEnv := newReferenceEnv(osEnv)
121121
envSources = append(envSources, referenceEnv)

internals/secrethub/run_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,11 @@ func TestRunCommand_Run(t *testing.T) {
458458
}{
459459
"success, no secrets": {
460460
command: RunCommand{
461-
osEnv: func() []string { return []string{} },
462461
command: []string{"echo", "test"},
463462
},
464463
},
465464
"missing secret": {
466465
command: RunCommand{
467-
osEnv: func() []string { return []string{} },
468466
command: []string{"echo", "test"},
469467
envar: map[string]string{
470468
"missing": "path/to/unexisting/secret",
@@ -486,7 +484,6 @@ func TestRunCommand_Run(t *testing.T) {
486484
},
487485
"missing secret ignored": {
488486
command: RunCommand{
489-
osEnv: func() []string { return []string{} },
490487
command: []string{"echo", "test"},
491488
envar: map[string]string{
492489
"missing": "path/to/unexisting/secret",
@@ -508,7 +505,6 @@ func TestRunCommand_Run(t *testing.T) {
508505
},
509506
"repo does not exist ignored": {
510507
command: RunCommand{
511-
osEnv: func() []string { return []string{} },
512508
command: []string{"echo", "test"},
513509
envar: map[string]string{
514510
"missing": "unexisting/repo/secret",
@@ -530,7 +526,6 @@ func TestRunCommand_Run(t *testing.T) {
530526
},
531527
"invalid template var: start with a number": {
532528
command: RunCommand{
533-
osEnv: func() []string { return []string{} },
534529
envFile: "secrethub.env",
535530
templateVars: map[string]string{
536531
"0foo": "value",
@@ -541,7 +536,6 @@ func TestRunCommand_Run(t *testing.T) {
541536
},
542537
"invalid template var: illegal character": {
543538
command: RunCommand{
544-
osEnv: func() []string { return []string{} },
545539
envFile: "secrethub.env",
546540
templateVars: map[string]string{
547541
"foo@bar": "value",
@@ -552,9 +546,7 @@ func TestRunCommand_Run(t *testing.T) {
552546
},
553547
"os env secret not found": {
554548
command: RunCommand{
555-
osEnv: func() []string {
556-
return []string{"TEST=secrethub://nonexistent/secret/path"}
557-
},
549+
osEnv: []string{"TEST=secrethub://nonexistent/secret/path"},
558550
command: []string{"echo", "test"},
559551
newClient: func() (secrethub.ClientInterface, error) {
560552
return fakeclient.Client{
@@ -572,9 +564,7 @@ func TestRunCommand_Run(t *testing.T) {
572564
},
573565
"os env secret not found ignored": {
574566
command: RunCommand{
575-
osEnv: func() []string {
576-
return []string{"TEST=secrethub://nonexistent/secret/path"}
577-
},
567+
osEnv: []string{"TEST=secrethub://nonexistent/secret/path"},
578568
ignoreMissingSecrets: true,
579569
command: []string{"echo", "test"},
580570
newClient: func() (secrethub.ClientInterface, error) {

0 commit comments

Comments
 (0)