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 #74 from secrethub/release/v0.19.0
Browse files Browse the repository at this point in the history
Release v0.19.0
  • Loading branch information
jpcoenen authored May 2, 2019
2 parents 437559d + 9c77e82 commit a199cf0
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 120 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.12
steps:
- checkout
- run: make test
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
# Go client for SecretHub

<p align="center">
<a name="secrethub">
<img src="https://secrethub.io/img/secrethub-logo.svg" alt="SecretHub" width="380px"/>
</a>
</p>
<h1 align="center">
<i>Go Client</i>
</h1>

[![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)][godoc]
[![Travis CI](https://travis-ci.org/secrethub/secrethub-go.svg?branch=master)][travis-ci]
[![GolangCI](https://golangci.com/badges/github.com/secrethub/secrethub-go.svg)][golang-ci]
[![Go Report Card](https://goreportcard.com/badge/github.com/secrethub/secrethub-go)][goreportcard]

[SecretHub][secrethub] is a developer tool to help you keep database passwords, API tokens, and other secrets out of IT automation scripts.
[![Version]( https://img.shields.io/github/release/secrethub/secrethub-go.svg)][latest-version]
[![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?logo=discord)][discord]

`secrethub-go` provides a client for various SecretHub APIs.

> [SecretHub][secrethub] is a developer tool to help you keep database passwords, API tokens, and other secrets out of IT automation scripts.
<img src="https://secrethub.io/img/secrethub-gopher.png" alt="Gopher" width="160px"/>

## Installation
## Getting started

### Installation

Install secrethub-go with:

Expand All @@ -34,7 +44,10 @@ import (
)
```

## Documentation
> **Note:** only packages inside the `/pkg` directory should be considered library code that you can use in your projects.
> All other code is not guaranteed to be backwards compatible and may change in the future.
## Examples

For details on all functionality of this library, see the [GoDoc][godoc] documentation.

Expand All @@ -58,18 +71,21 @@ secret, err = client.Secrets().Versions().GetWithData("path/to/secret:latest")
fmt.Println(secret.Data) // prints password123

// Generate a slice of 32 alphanumeric characters.
data, err := randchar.NewGenerator(false).Generate(32)
data, err := randchar.NewGenerator(false).Generate(32)
secret, err = client.Secrets().Write("path/to/secret", data)
```

Note that only packages inside the `/pkg` directory should be considered library code that you can use in your projects. All other code is not guaranteed to be backwards compatible and may change in the future.
> **Note:** to use the SecretHub Go client, you need to provide a credential for your __SecretHub__ account.
> You can create a free developer account by [signing up through the CLI](https://secrethub.io/docs/getting-started/).
>
> After signup, the credential is located at `$HOME/.secrethub/credential` by default.
## Development

Pull requests from the community are welcome.
If you'd like to contribute, please checkout [the contributing guidelines](./CONTRIBUTING.md).

## Test
## Testing

Run all tests:

Expand All @@ -86,6 +102,10 @@ Run a single test:
For any requests, bug or comments, please [open an issue][issues] or [submit a
pull request][pulls].

## Getting help

Come chat with us on [Discord][discord] or email us at [support@secrethub.io](mailto:support@secrethub.io)

## Attributions

["gopher.png"][original-gopher] by [Takuya Ueda][tenntenn] is licensed under [CC BY 3.0][creative-commons-3.0]
Expand All @@ -95,9 +115,11 @@ pull request][pulls].
[tenntenn]: https://twitter.com/tenntenn

[secrethub]: https://secrethub.io
[latest-version]: https://github.com/secrethub/secrethub-go/releases/latest
[issues]: https://github.com/secrethub/secrethub-go/issues/new
[pulls]: https://github.com/secrethub/secrethub-go/pulls
[godoc]: http://godoc.org/github.com/secrethub/secrethub-go
[golang-ci]: https://golangci.com/r/github.com/secrethub/secrethub-go
[goreportcard]: https://goreportcard.com/report/github.com/secrethub/secrethub-go
[travis-ci]: https://travis-ci.org/secrethub/secrethub-go
[discord]: https://discord.gg/EQcE87s
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ module github.com/secrethub/secrethub-go
require (
bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf
github.com/certifi/gocertifi v0.0.0-20190105021004-abcd57078448 // indirect
github.com/docker/go-units v0.3.3
github.com/getsentry/raven-go v0.2.0
github.com/go-chi/chi v4.0.1+incompatible
github.com/google/go-querystring v1.0.0
github.com/kr/pretty v0.1.0 // indirect
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/pkg/errors v0.8.1 // indirect
github.com/satori/go.uuid v1.2.0
golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef h1:Y5Zf3CYdrd
bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef/go.mod h1:ZJR5FpaQx7Bt2bzIV3gBaCInI1+kG949WhNYYlRr8eA=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/certifi/gocertifi v0.0.0-20190105021004-abcd57078448 h1:8tNk6SPXzLDnATTrWoI5Bgw9s/x4uf0kmBpk21NZgI4=
github.com/certifi/gocertifi v0.0.0-20190105021004-abcd57078448/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4=
github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs=
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/go-chi/chi v4.0.1+incompatible h1:RSRC5qmFPtO90t7pTL0DBMNpZFsb/sHF3RXVlDgFisA=
github.com/go-chi/chi v4.0.1+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
Expand All @@ -21,8 +17,6 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3v
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b h1:+/WWzjwW6gidDJnMKWLKLX1gxn7irUTF1fLpQovfQ5M=
Expand Down
3 changes: 2 additions & 1 deletion internals/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ var (
"may only contain (special) letters, apostrophes ('), spaces and dashes (-)",
http.StatusBadRequest,
)
ErrNoPasswordNorCredential = errAPI.Code("no_password_nor_credential").StatusError("either a password or a credential should be supplied", http.StatusBadRequest)
ErrNoPasswordNorCredential = errAPI.Code("no_password_nor_credential").StatusError("either a password or a credential should be supplied", http.StatusBadRequest)
ErrTooManyVerificationRequests = errAPI.Code("too_many_verification_requests").StatusError("another verification email was requested recently, please wait a few minutes before trying again", http.StatusTooManyRequests)
)

// User represents a SecretHub user.
Expand Down
2 changes: 1 addition & 1 deletion internals/auth/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c signer) AddAuthentication(r *http.Request) error {
return errio.Error(err)
}

signature, err := c.key.Sign(message[:])
signature, err := c.key.Sign(message)
if err != nil {
return errio.Error(err)
}
Expand Down
79 changes: 5 additions & 74 deletions internals/errio/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@ import (
"net/http"
"runtime/debug"

"reflect"

raven "github.com/getsentry/raven-go"

logging "github.com/op/go-logging"
"github.com/op/go-logging"
)

var (
log = logging.MustGetLogger("log")
// reportErrorFunc is the function used to report the error. Useful for injection.
reportErrorFunc = sendErrorReport
)

// Namespace is a container for different errors and is
Expand Down Expand Up @@ -137,22 +131,18 @@ func UnexpectedError(err error) PublicError {
return err.(PublicError)
}

eventID := reportErrorFunc(err)

// Log the eventID and stack trace for debugging.
log.Debugf(
"An unexpected error occurred, logged as %s: %v\nStack Trace:%s",
eventID,
"An unexpected error occurred: %v\nStack Trace:%s",
err,
string(debug.Stack()),
)

return PublicError{
Code: "unexpected",
Message: fmt.Sprintf(
"an unexpected error occurred: %v\n\nTry again later or contact support@secrethub.io if the problem persists with error id %s",
"an unexpected error occurred: %v\n\nTry again later or contact support@secrethub.io if the problem persists",
err,
eventID,
),
}
}
Expand All @@ -162,12 +152,9 @@ func UnexpectedStatusError(err error) PublicStatusError {
if isPublicStatusError(err) {
return err.(PublicStatusError)
}
eventID := reportErrorFunc(err)

// Log the eventID and stack trace for debugging.
log.Debugf(
"An unexpected error occurred, logged as %s: %v\nStack Trace:%s",
eventID,
"An unexpected error occurred: %v\nStack Trace:%s",
err,
string(debug.Stack()),
)
Expand All @@ -176,20 +163,13 @@ func UnexpectedStatusError(err error) PublicStatusError {
PublicError: PublicError{
Code: "unexpected",
Message: fmt.Sprintf(
"an unexpected server error occurred. Try again later or contact support@secrethub.io if the problem persists with error id %s",
eventID,
"an unexpected server error occurred. Try again later or contact support@secrethub.io if the problem persists",
),
},
StatusCode: http.StatusInternalServerError,
}
}

// sendErrorReport captures the stack trace and sends the error report to sentry.io.
func sendErrorReport(err error) string {
eventID, _ := CaptureError(err, nil)
return eventID
}

// PublicError is a wrapper around an error code and a error message.
// This allows clear error messaging and trace ability.
type PublicError struct {
Expand Down Expand Up @@ -260,52 +240,3 @@ func Wrap(base PublicStatusError, errs ...error) PublicStatusError {

return base
}

// typer is an interface that can be used to retrieve the type of an error
type typer interface {
Type() string
}

// NewException returns a *raven.Exception for an error from this package.
// In contrary to raven.NewException, this function tries to retrieve the error type from the typer interface.
func NewException(err error, stacktrace *raven.Stacktrace) *raven.Exception {
msg := err.Error()

var t string
typer, isTyper := err.(typer)
if isTyper {
t = typer.Type()
} else {
t = reflect.TypeOf(err).String()
}

ex := &raven.Exception{
Stacktrace: stacktrace,
Value: msg,
Type: t,
}
return ex
}

// CaptureError captures an error and sends it to Sentry.
func CaptureError(err error, tags map[string]string) (string, chan error) {
client := raven.DefaultClient
packet := raven.NewPacket(
err.Error(),
NewException(
err,
raven.GetOrNewStacktrace(err, 1, 3, client.IncludePaths()),
),
)

return client.Capture(packet, tags)
}

// CaptureErrorAndWait captures an error and sends it to Sentry and wait for that process to be finished.
func CaptureErrorAndWait(err error, tags map[string]string) string {
eventID, ch := CaptureError(err, tags)
if eventID != "" {
<-ch
}
return eventID
}
24 changes: 2 additions & 22 deletions internals/errio/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ var (
Message: "some test error",
},
}
data = []byte(`{"error":{"code":"test","message":"some test error"}}`)
errorMessage = "test_error"
reportedError = "not_reported"
data = []byte(`{"error":{"code":"test","message":"some test error"}}`)
errorMessage = "test_error"
)

func TestMarshal(t *testing.T) {
Expand Down Expand Up @@ -73,9 +72,6 @@ func TestExpectedError(t *testing.T) {
}

func TestUnexpectedError(t *testing.T) {
reportedError = "not_reported"
reportErrorFunc = reportErrorTest

unexpected := go_errors.New(errorMessage)
err := Error(unexpected)

Expand All @@ -92,16 +88,9 @@ func TestUnexpectedError(t *testing.T) {
if len(customError.Message) == 0 {
t.Error("returned error does not contain a message")
}

if reportedError != errorMessage {
t.Error("unexpected error was not reported")
}
}

func TestUnexpectedStatusError(t *testing.T) {
reportedError = "not_reported"
reportErrorFunc = reportErrorTest

unexpected := go_errors.New(errorMessage)
err := StatusError(unexpected)

Expand All @@ -122,13 +111,4 @@ func TestUnexpectedStatusError(t *testing.T) {
if len(statusError.Message) == 0 {
t.Error("returned error does not contain a message")
}

if reportedError != errorMessage {
t.Error("unexpected error was not reported")
}
}

func reportErrorTest(err error) string {
reportedError = err.Error()
return "IMPLEMENT INJECT"
}
2 changes: 1 addition & 1 deletion pkg/secrethub/client_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package secrethub

// ClientVersion is the current version of the client
// Do not edit this unless you know what you're doing.
const ClientVersion = "v0.17.0"
const ClientVersion = "v0.19.0"
10 changes: 7 additions & 3 deletions pkg/secrethub/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
)

var (
// DefaultCredentialParser defines the default parser for credentials.
DefaultCredentialParser = NewCredentialParser(DefaultCredentialDecoders)
// DefaultCredentialDecoders defines the default list of supported decoders.
DefaultCredentialDecoders = []CredentialDecoder{RSAPrivateKeyDecoder{}}
// DefaultCredentialEncoding defines the default encoding used for encoding credential segments.
Expand Down Expand Up @@ -59,10 +61,12 @@ type Credential interface {
// NewCredential is a shorthand function to decode a credential string and optionally
// decrypt it with a passphrase. When an encrypted credential is given, the passphrase
// cannot be empty.
//
// Note that when you want to customize the process of parsing and decoding/decrypting
// a credential (e.g. to prompt only for a passphrase when the credential is encrypted),
// it is recommended you use a CredentialParser instead (e.g. DefaultCredentialParser).
func NewCredential(credential string, passphrase string) (Credential, error) {
parser := NewCredentialParser(DefaultCredentialDecoders)

encoded, err := parser.Parse(credential)
encoded, err := DefaultCredentialParser.Parse(credential)
if err != nil {
return nil, errio.Error(err)
}
Expand Down

0 comments on commit a199cf0

Please sign in to comment.