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

Commit d5e091a

Browse files
authored
Merge pull request #345 from secrethub/release/v0.41.0
Release v0.41.0
2 parents 4a10069 + ca1b6db commit d5e091a

19 files changed

Lines changed: 966 additions & 142 deletions

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<br/>
55

66
<p align="center">
7-
<a href="https://secrethub.io/docs/start/getting-started/"><img alt="Get Started" src="https://secrethub.io/img/buttons/github/get-started.png?v1" height="28" /></a>
7+
<a href="https://signup.secrethub.io/"><img alt="Get Started" src="https://secrethub.io/img/buttons/github/get-started.png?v1" height="28" /></a>
88
<a href="https://secrethub.io/docs/reference/cli/"><img alt="View Docs" src="https://secrethub.io/img/buttons/github/view-docs.png?v2" height="28" /></a>
99
</p>
1010
<br/>
@@ -21,10 +21,6 @@ The SecretHub CLI provides the command-line interface to interact with the Secre
2121

2222
> [SecretHub][secrethub] is a secrets management tool that works for every engineer. Securely provision passwords and keys throughout your entire stack with just a few lines of code.
2323
24-
## Get started
25-
26-
Follow the [Getting Started Guide][getting-started] to quickly get up and running with SecretHub :rocket:
27-
2824
## Usage
2925

3026
Below you can find a selection of some of the most-used SecretHub commands. Run `secrethub --help` or the [CLI reference docs][cli-reference-docs] for a complete list of all commands.

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ require (
1717
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
1818
github.com/pkg/errors v0.9.1 // indirect
1919
github.com/secrethub/demo-app v0.1.0
20-
github.com/secrethub/secrethub-go v0.30.0
20+
github.com/secrethub/secrethub-go v0.31.0
2121
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
2222
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
23-
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
2423
golang.org/x/sys v0.0.0-20200501052902-10377860bb8e
2524
golang.org/x/text v0.3.2
2625
google.golang.org/api v0.26.0
27-
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84
2826
gopkg.in/yaml.v2 v2.2.2
2927
gotest.tools v2.2.0+incompatible
3028
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ github.com/secrethub/secrethub-go v0.29.1-0.20200707154958-5e5602145597 h1:uC9OD
178178
github.com/secrethub/secrethub-go v0.29.1-0.20200707154958-5e5602145597/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
179179
github.com/secrethub/secrethub-go v0.30.0 h1:Nh1twPDwPbYQj/cYc1NG+j7sv76LZiXLPovyV83tZj0=
180180
github.com/secrethub/secrethub-go v0.30.0/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
181+
github.com/secrethub/secrethub-go v0.31.0 h1:0KoG0KHBOa5knkvf3K0f6sKuPSQ5VGPXLD4ttC9Eul8=
182+
github.com/secrethub/secrethub-go v0.31.0/go.mod h1:ZIco8Y0G0Pi0Vb7pQROjvEKgSreZiRMLhAbzWUneUSQ=
181183
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
182184
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
183185
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=

internals/cli/filemode/filemode.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package filemode
33

44
import (
5+
"fmt"
56
"os"
67
"strconv"
78

@@ -47,7 +48,7 @@ func (m *FileMode) Set(value string) error {
4748

4849
// String implements the flag.Value interface.
4950
func (m FileMode) String() string {
50-
return string(m)
51+
return fmt.Sprintf("%#o", m.FileMode().Perm())
5152
}
5253

5354
// FileMode returns the file mode as an os.FileMode.

internals/cli/masker/stream.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package masker
33
import (
44
"bytes"
55
"io"
6+
"io/ioutil"
67
"sync"
78
"time"
89
)
@@ -64,31 +65,32 @@ func (s *stream) flush(n int) error {
6465

6566
if exists {
6667
// Get any unprocessed bytes before this match to the destination.
67-
beforeMatch := s.buf.upToIndex(i)
68-
69-
_, err := s.dest.Write(beforeMatch)
68+
bytesBeforeMatch, err := s.buf.writeUpToIndex(s.dest, i)
7069
if err != nil {
7170
return err
7271
}
7372

7473
// Only write the redaction text if there were bytes between this match and the previous match
7574
// or this is the first flush for the buffer.
76-
if len(beforeMatch) > 0 || s.buf.currentIndex == 0 {
75+
if bytesBeforeMatch > 0 || s.buf.currentIndex == 0 {
7776
_, err = s.dest.Write([]byte("<redacted by SecretHub>"))
7877
if err != nil {
7978
return err
8079
}
8180
}
8281

8382
// Drop all bytes until the end of the mask.
84-
_ = s.buf.upToIndex(i + int64(length))
83+
_, err = s.buf.writeUpToIndex(ioutil.Discard, i+int64(length))
84+
if err != nil {
85+
return err
86+
}
8587

8688
delete(s.matches, i)
8789
}
8890
}
8991

9092
// Write all bytes after the last match.
91-
_, err := s.dest.Write(s.buf.upToIndex(endIndex))
93+
_, err := s.buf.writeUpToIndex(s.dest, endIndex)
9294
if err != nil {
9395
return err
9496
}
@@ -109,16 +111,17 @@ func (b *indexedBuffer) write(p []byte) (n int, err error) {
109111
return b.buffer.Write(p)
110112
}
111113

112-
// upToIndex pops and returns all bytes in the buffer up to the given index.
113-
// If all bytes up to this given index have already been returned previously, an empty slice is returned.
114-
func (b *indexedBuffer) upToIndex(index int64) []byte {
114+
// writeUpToIndex pops all bytes in the buffer up to the given index and writes them to the given writer.
115+
// The number of bytes written and any errors encountered are returned
116+
func (b *indexedBuffer) writeUpToIndex(w io.Writer, index int64) (int, error) {
115117
b.mutex.Lock()
116118
defer b.mutex.Unlock()
117119

118120
if index < b.currentIndex {
119-
return []byte{}
121+
return 0, nil
120122
}
121123
n := int(index - b.currentIndex)
122124
b.currentIndex = index
123-
return b.buffer.Next(n)
125+
bufferSlice := b.buffer.Next(n)
126+
return w.Write(bufferSlice)
124127
}

internals/demo/init.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ func (cmd *InitCommand) Run() error {
6464
}
6565

6666
_, err = client.Repos().Create(repoPath)
67-
if err == api.ErrRepoAlreadyExists && cmd.repo == "" {
68-
return fmt.Errorf("demo repo %s already exists, use --repo to specify another repo to use", repoPath)
67+
if err == api.ErrRepoAlreadyExists {
68+
demoRepo, err := cmd.isDemoRepo(client, repoPath)
69+
if err != nil {
70+
return err
71+
}
72+
if demoRepo {
73+
return nil
74+
}
75+
return fmt.Errorf("repo %s already exists and is not a demo repo, use --repo to specify another repo to use", repoPath)
6976
} else if err != nil {
7077
return err
7178
}
@@ -89,3 +96,34 @@ func (cmd *InitCommand) Run() error {
8996

9097
return nil
9198
}
99+
100+
// isDemoRepo checks whether the repo on the given path is a demo repository.
101+
// It returns true iff the repository contains exactly two secrets named username and password.
102+
func (cmd *InitCommand) isDemoRepo(client secrethub.ClientInterface, repoPath string) (bool, error) {
103+
repo, err := client.Repos().Get(repoPath)
104+
if err != nil {
105+
return false, err
106+
}
107+
if repo.SecretCount != 2 {
108+
return false, nil
109+
}
110+
111+
usernamePath := secretpath.Join(repoPath, "username")
112+
exists, err := client.Secrets().Exists(usernamePath)
113+
if err != nil {
114+
return false, err
115+
}
116+
if !exists {
117+
return false, nil
118+
}
119+
120+
passwordPath := secretpath.Join(repoPath, "password")
121+
exists, err = client.Secrets().Exists(passwordPath)
122+
if err != nil {
123+
return false, err
124+
}
125+
if !exists {
126+
return false, nil
127+
}
128+
return true, nil
129+
}

internals/secrethub/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func NewApp() *App {
7979
io := ui.NewUserIO()
8080
store := NewCredentialConfig(io)
8181
help := "The SecretHub command-line interface is a unified tool to manage your infrastructure secrets with SecretHub.\n\n" +
82+
"If you do not yet have a SecretHub account, go here to create one:\n\n" +
83+
" https://signup.secrethub.io/\n\n" +
8284
"For a step-by-step introduction, check out:\n\n" +
8385
" https://secrethub.io/docs/getting-started/\n\n" +
8486
"To get help, see:\n\n" +

internals/secrethub/credential_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
// Errors
1313
var (
14-
ErrCredentialNotExist = errMain.Code("credential_not_exist").Error("could not find credential file. Run `secrethub signup` to create an account.")
14+
ErrCredentialNotExist = errMain.Code("credential_not_exist").Error("could not find credential file. Go to https://signup.secrethub.io/ to create an account or run `secrethub init` to use an already existing account on this machine.")
1515
)
1616

1717
// CredentialConfig handles the configuration necessary for local credentials.

internals/secrethub/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ func (cmd *EnvCommand) Register(r command.Registerer) {
2424
clause := r.Command("env", "[BETA] Manage environment variables.").Hidden()
2525
clause.HelpLong("This command is hidden because it is still in beta. Future versions may break.")
2626
NewEnvReadCommand(cmd.io, cmd.newClient).Register(clause)
27-
NewEnvListCommand(cmd.io).Register(clause)
27+
NewEnvListCommand(cmd.io, cmd.newClient).Register(clause)
2828
}

internals/secrethub/env_ls.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ type EnvListCommand struct {
1414
}
1515

1616
// NewEnvListCommand creates a new EnvListCommand.
17-
func NewEnvListCommand(io ui.IO) *EnvListCommand {
17+
func NewEnvListCommand(io ui.IO, newClient newClientFunc) *EnvListCommand {
1818
return &EnvListCommand{
1919
io: io,
20-
environment: newEnvironment(io),
20+
environment: newEnvironment(io, newClient),
2121
}
2222
}
2323

0 commit comments

Comments
 (0)