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

Commit 2391c1e

Browse files
Merge pull request #257 from secrethub/release/v0.36.0
Release v0.36.0
2 parents 896efa2 + 1d29286 commit 2391c1e

13 files changed

Lines changed: 1131 additions & 679 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

.goreleaser.yml

Lines changed: 4 additions & 2 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:
@@ -77,7 +80,7 @@ scoop:
7780
license: Apache-2.0
7881

7982
nfpms:
80-
- name_template: "secrethub-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
83+
- file_name_template: "secrethub-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
8184
builds:
8285
- without-bin-dir
8386
vendor: SecretHub
@@ -96,4 +99,3 @@ nfpms:
9699
scripts:
97100
postinstall: "scripts/post-install.sh"
98101
postremove: "scripts/post-remove.sh"
99-

internals/secrethub/app.go

Lines changed: 1 addition & 0 deletions
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)

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+
}

internals/secrethub/env_read.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
// EnvReadCommand is a command to read the value of a single environment variable.
11+
type EnvReadCommand struct {
12+
io ui.IO
13+
newClient newClientFunc
14+
environment *environment
15+
key string
16+
}
17+
18+
// NewEnvReadCommand creates a new EnvReadCommand.
19+
func NewEnvReadCommand(io ui.IO, newClient newClientFunc) *EnvReadCommand {
20+
return &EnvReadCommand{
21+
io: io,
22+
newClient: newClient,
23+
environment: newEnvironment(io),
24+
}
25+
}
26+
27+
// Register adds a CommandClause and it's args and flags to a Registerer.
28+
func (cmd *EnvReadCommand) Register(r command.Registerer) {
29+
clause := r.Command("read", "[BETA] Read the value of a single environment variable.")
30+
clause.HelpLong("This command is hidden because it is still in beta. Future versions may break.")
31+
clause.Arg("key", "the key of the environment variable to read").StringVar(&cmd.key)
32+
33+
cmd.environment.register(clause)
34+
35+
command.BindAction(clause, cmd.Run)
36+
}
37+
38+
// Run executes the command.
39+
func (cmd *EnvReadCommand) Run() error {
40+
env, err := cmd.environment.env()
41+
if err != nil {
42+
return err
43+
}
44+
45+
value, found := env[cmd.key]
46+
if !found {
47+
return fmt.Errorf("no environment variable with that key is set")
48+
}
49+
50+
secretReader := newSecretReader(cmd.newClient)
51+
52+
res, err := value.resolve(secretReader)
53+
if err != nil {
54+
return err
55+
}
56+
57+
fmt.Fprintln(cmd.io.Stdout(), res)
58+
59+
return nil
60+
}

0 commit comments

Comments
 (0)