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

Commit

Permalink
Merge pull request #257 from secrethub/release/v0.36.0
Browse files Browse the repository at this point in the history
Release v0.36.0
  • Loading branch information
SimonBarendse authored Mar 2, 2020
2 parents 896efa2 + 1d29286 commit 2391c1e
Show file tree
Hide file tree
Showing 13 changed files with 1,131 additions and 679 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- run: make test
verify-goreleaser:
docker:
- image: goreleaser/goreleaser:v0.117
- image: goreleaser/goreleaser:v0.127
steps:
- checkout
- run: goreleaser check
Expand Down
6 changes: 4 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ archives:
checksum:
name_template: "secrethub-{{ .Tag }}-checksums.txt"

release:
draft: true

brews:
- name: secrethub-cli
ids:
Expand All @@ -77,7 +80,7 @@ scoop:
license: Apache-2.0

nfpms:
- name_template: "secrethub-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
- file_name_template: "secrethub-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
builds:
- without-bin-dir
vendor: SecretHub
Expand All @@ -96,4 +99,3 @@ nfpms:
scripts:
postinstall: "scripts/post-install.sh"
postremove: "scripts/post-remove.sh"

1 change: 1 addition & 0 deletions internals/secrethub/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (app *App) registerCommands() {
NewAccountCommand(app.io, app.clientFactory.NewClient, app.credentialStore).Register(app.cli)
NewCredentialCommand(app.io, app.clientFactory, app.credentialStore).Register(app.cli)
NewConfigCommand(app.io, app.credentialStore).Register(app.cli)
NewEnvCommand(app.io, app.clientFactory.NewClient).Register(app.cli)

// Commands
NewInitCommand(app.io, app.clientFactory.NewUnauthenticatedClient, app.clientFactory.NewClientWithCredentials, app.credentialStore).Register(app.cli)
Expand Down
28 changes: 28 additions & 0 deletions internals/secrethub/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package secrethub

import (
"github.com/secrethub/secrethub-cli/internals/cli/ui"
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
)

// EnvCommand handles operations regarding environment variables.
type EnvCommand struct {
io ui.IO
newClient newClientFunc
}

// NewEnvCommand creates a new EnvCommand.
func NewEnvCommand(io ui.IO, newClient newClientFunc) *EnvCommand {
return &EnvCommand{
io: io,
newClient: newClient,
}
}

// Register registers the command and its sub-commands on the provided Registerer.
func (cmd *EnvCommand) Register(r command.Registerer) {
clause := r.Command("env", "[BETA] Manage environment variables.").Hidden()
clause.HelpLong("This command is hidden because it is still in beta. Future versions may break.")
NewEnvReadCommand(cmd.io, cmd.newClient).Register(clause)
NewEnvListCommand(cmd.io).Register(clause)
}
51 changes: 51 additions & 0 deletions internals/secrethub/env_ls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package secrethub

import (
"fmt"

"github.com/secrethub/secrethub-cli/internals/cli/ui"
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
)

// EnvListCommand is a command to list all environment variable keys set in the process of `secrethub run`.
type EnvListCommand struct {
io ui.IO
environment *environment
}

// NewEnvListCommand creates a new EnvListCommand.
func NewEnvListCommand(io ui.IO) *EnvListCommand {
return &EnvListCommand{
io: io,
environment: newEnvironment(io),
}
}

// Register adds a CommandClause and it's args and flags to a Registerer.
func (cmd *EnvListCommand) Register(r command.Registerer) {
clause := r.Command("ls", "[BETA] List environment variable names that will be populated with secrets.")
clause.HelpLong("This command is hidden because it is still in beta. Future versions may break.")
clause.Alias("list")

cmd.environment.register(clause)

command.BindAction(clause, cmd.Run)
}

// Run executes the command.
func (cmd *EnvListCommand) Run() error {
env, err := cmd.environment.env()
if err != nil {
return err
}

for key, value := range env {
// For now only environment variables in which a secret is loaded are printed.
// TODO: Make this behavior configurable.
if value.containsSecret() {
fmt.Fprintln(cmd.io.Stdout(), key)
}
}

return nil
}
60 changes: 60 additions & 0 deletions internals/secrethub/env_read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package secrethub

import (
"fmt"

"github.com/secrethub/secrethub-cli/internals/cli/ui"
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
)

// EnvReadCommand is a command to read the value of a single environment variable.
type EnvReadCommand struct {
io ui.IO
newClient newClientFunc
environment *environment
key string
}

// NewEnvReadCommand creates a new EnvReadCommand.
func NewEnvReadCommand(io ui.IO, newClient newClientFunc) *EnvReadCommand {
return &EnvReadCommand{
io: io,
newClient: newClient,
environment: newEnvironment(io),
}
}

// Register adds a CommandClause and it's args and flags to a Registerer.
func (cmd *EnvReadCommand) Register(r command.Registerer) {
clause := r.Command("read", "[BETA] Read the value of a single environment variable.")
clause.HelpLong("This command is hidden because it is still in beta. Future versions may break.")
clause.Arg("key", "the key of the environment variable to read").StringVar(&cmd.key)

cmd.environment.register(clause)

command.BindAction(clause, cmd.Run)
}

// Run executes the command.
func (cmd *EnvReadCommand) Run() error {
env, err := cmd.environment.env()
if err != nil {
return err
}

value, found := env[cmd.key]
if !found {
return fmt.Errorf("no environment variable with that key is set")
}

secretReader := newSecretReader(cmd.newClient)

res, err := value.resolve(secretReader)
if err != nil {
return err
}

fmt.Fprintln(cmd.io.Stdout(), res)

return nil
}
Loading

0 comments on commit 2391c1e

Please sign in to comment.