Skip to content

Commit

Permalink
replaced juju/errors with pkg/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dissoupov committed Oct 12, 2021
1 parent a58d793 commit 6b8cabb
Show file tree
Hide file tree
Showing 91 changed files with 557 additions and 629 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
UnitTest:
strategy:
matrix:
go-version: [1.16.x]
go-version: [1.17.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
Expand Down
4 changes: 2 additions & 2 deletions audit/log/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"path/filepath"

"github.com/go-phorce/dolly/audit"
"github.com/juju/errors"
"github.com/pkg/errors"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)

// New return a new instance of an Auditor that writes audit entries to a local log file
func New(fileprefix, directory string, maxAgeDays int, maxSizeMb int) (audit.Auditor, error) {
if err := os.MkdirAll(directory, 0755); err != nil {
return nil, errors.Trace(err)
return nil, errors.WithStack(err)
}
res := fileAuditor{
fileWriter: lumberjack.Logger{
Expand Down
4 changes: 2 additions & 2 deletions cmd/dollypki/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xlog"
"github.com/go-phorce/dolly/xpki/cryptoprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// ReturnCode is the type that your command returns, these map to standard process return codes
Expand Down Expand Up @@ -87,7 +87,7 @@ func (cli *Cli) EnsureCryptoProvider() error {
var err error
cli.crypto, err = cryptoprov.Load(*cli.flags.hsmConfig, nil)
if err != nil {
return errors.Annotate(err, "unable to initialize crypto providers")
return errors.WithMessage(err, "unable to initialize crypto providers")
}

return nil
Expand Down
18 changes: 9 additions & 9 deletions cmd/dollypki/csr/gencert.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/cli"
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xpki/csrprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// GenCertFlags specifies flags for GenCert command
Expand Down Expand Up @@ -85,7 +85,7 @@ func GenCert(c ctl.Control, p interface{}) error {
// Load CSR
csrf, err := cli.ReadStdin(*flags.CsrProfile)
if err != nil {
return errors.Annotate(err, "read CSR profile")
return errors.WithMessage(err, "read CSR profile")
}

req := csrprov.CertificateRequest{
Expand All @@ -95,7 +95,7 @@ func GenCert(c ctl.Control, p interface{}) error {

err = json.Unmarshal(csrf, &req)
if err != nil {
return errors.Annotate(err, "invalid CSR")
return errors.WithMessage(err, "invalid CSR")
}

if req.CA != nil {
Expand All @@ -105,7 +105,7 @@ func GenCert(c ctl.Control, p interface{}) error {
// Load ca-config
cacfg, err := cfsslconfig.LoadFile(*flags.CAConfig)
if err != nil {
return errors.Annotate(err, "ca-config")
return errors.WithMessage(err, "ca-config")
}
if cacfg.Signing == nil {
return errors.New("missing signing policy in ca-config")
Expand All @@ -117,13 +117,13 @@ func GenCert(c ctl.Control, p interface{}) error {
// ensure that signer can be created before the key is generated
s, _, err := csrprov.NewLocalCASignerFromFile(cryptoprov, *flags.CA, *flags.CAKey, cacfg.Signing)
if err != nil {
return errors.Annotate(err, "create signer")
return errors.WithMessage(err, "create signer")
}

var key, csrPEM []byte
csrPEM, key, _, _, err = prov.ProcessCsrRequest(&req)
if err != nil {
return errors.Annotate(err, "ProcessRequest")
return errors.WithMessage(err, "ProcessRequest")
}

signReq := signer.SignRequest{
Expand All @@ -140,15 +140,15 @@ func GenCert(c ctl.Control, p interface{}) error {

err = cli.WriteFile(baseName+".pem", cert, 0664)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
err = cli.WriteFile(baseName+".csr", csrPEM, 0664)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
err = cli.WriteFile(baseName+"-key.pem", key, 0600)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
}

Expand Down
20 changes: 10 additions & 10 deletions cmd/dollypki/csr/genkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/cli"
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xpki/csrprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// GenKeyFlags specifies flags for GenKey command
Expand Down Expand Up @@ -56,7 +56,7 @@ func GenKey(c ctl.Control, p interface{}) error {

csrf, err := cli.ReadStdin(*flags.CsrProfile)
if err != nil {
return errors.Annotate(err, "read CSR profile")
return errors.WithMessage(err, "read CSR profile")
}

req := csrprov.CertificateRequest{
Expand All @@ -66,14 +66,14 @@ func GenKey(c ctl.Control, p interface{}) error {

err = json.Unmarshal(csrf, &req)
if err != nil {
return errors.Annotate(err, "invalid CSR")
return errors.WithMessage(err, "invalid CSR")
}

if *flags.Initca {
var key, csrPEM, cert []byte
cert, csrPEM, key, err = prov.NewRoot(&req)
if err != nil {
return errors.Annotate(err, "init CA")
return errors.WithMessage(err, "init CA")
}

if *flags.Output == "" {
Expand All @@ -83,15 +83,15 @@ func GenKey(c ctl.Control, p interface{}) error {

err = cli.WriteFile(baseName+".pem", cert, 0664)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
err = cli.WriteFile(baseName+".csr", csrPEM, 0664)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
err = cli.WriteFile(baseName+"-key.pem", key, 0600)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
}
} else {
Expand All @@ -103,7 +103,7 @@ func GenKey(c ctl.Control, p interface{}) error {
csrPEM, key, _, _, err = prov.ProcessCsrRequest(&req)
if err != nil {
key = nil
return errors.Annotate(err, "ProcessCsrRequest")
return errors.WithMessage(err, "ProcessCsrRequest")
}

if *flags.Output == "" {
Expand All @@ -113,11 +113,11 @@ func GenKey(c ctl.Control, p interface{}) error {

err = cli.WriteFile(baseName+".csr", csrPEM, 0664)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
err = cli.WriteFile(baseName+"-key.pem", key, 0600)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/dollypki/csr/signcert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/cli"
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xpki/csrprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// SignCertFlags specifies flags for SignCert command
Expand Down Expand Up @@ -67,13 +67,13 @@ func SignCert(c ctl.Control, p interface{}) error {
// Load CSR
csrPEM, err := cli.ReadStdin(*flags.Csr)
if err != nil {
return errors.Annotate(err, "read CSR")
return errors.WithMessage(err, "read CSR")
}

// Load ca-config
cacfg, err := cfsslconfig.LoadFile(*flags.CAConfig)
if err != nil {
return errors.Annotate(err, "ca-config")
return errors.WithMessage(err, "ca-config")
}
if cacfg.Signing == nil {
return errors.New("missing signing policy in ca-config")
Expand All @@ -89,7 +89,7 @@ func SignCert(c ctl.Control, p interface{}) error {

s, _, err := csrprov.NewLocalCASignerFromFile(cryptoprov, *flags.CA, *flags.CAKey, cacfg.Signing)
if err != nil {
return errors.Annotate(err, "create signer")
return errors.WithMessage(err, "create signer")
}

signReq := signer.SignRequest{
Expand All @@ -106,11 +106,11 @@ func SignCert(c ctl.Control, p interface{}) error {

err = cli.WriteFile(baseName+".pem", cert, 0664)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
err = cli.WriteFile(baseName+".csr", csrPEM, 0664)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/dollypki/hsm/genkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/cli"
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xpki/csrprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// GenKeyFlags specifies flags for GenKey command
Expand Down Expand Up @@ -86,17 +86,17 @@ func GenKey(c ctl.Control, p interface{}) error {
req := csr.NewKeyRequest(prefixKeyLabel(*flags.Label), *flags.Algo, *flags.Size, purpose)
prv, err := req.Generate()
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}

keyID, _, err := crypto.IdentifyKey(prv)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}

uri, key, err := crypto.ExportKey(keyID)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}

if key == nil {
Expand All @@ -108,7 +108,7 @@ func GenKey(c ctl.Control, p interface{}) error {
} else {
err = cli.WriteFile(*flags.Output, key, 0600)
if err != nil {
return errors.Trace(err)
return errors.WithStack(err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/dollypki/hsm/keyinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/cli"
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xpki/cryptoprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// KeyInfoFlags specifies flags for the key info action
Expand Down
4 changes: 2 additions & 2 deletions cmd/dollypki/hsm/lskey.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/cli"
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xpki/cryptoprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// LsKeyFlags specifies flags for the Keys action
Expand Down Expand Up @@ -78,7 +78,7 @@ func Keys(c ctl.Control, p interface{}) error {
return nil
})
if err != nil {
return errors.Annotatef(err, "failed to list keys on slot %d", slotID)
return errors.WithMessagef(err, "failed to list keys on slot %d", slotID)
}

if *flags.Prefix != "" && count == 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/dollypki/hsm/mockhsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/hsm"
"github.com/go-phorce/dolly/cmd/dollypki/testsuite"
"github.com/go-phorce/dolly/xpki/cryptoprov"
"github.com/juju/errors"
"github.com/pkg/errors"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down
8 changes: 4 additions & 4 deletions cmd/dollypki/hsm/rmkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/cli"
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xpki/cryptoprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// RmKeyFlags specifies flags for the delete key action
Expand Down Expand Up @@ -90,7 +90,7 @@ func RmKey(c ctl.Control, p interface{}) error {
return nil
})
if err != nil {
return errors.Annotatef(err, "failed to list keys on slot %d", slotID)
return errors.WithMessagef(err, "failed to list keys on slot %d", slotID)
}

if len(keysToDestroy) == 0 {
Expand All @@ -111,7 +111,7 @@ func RmKey(c ctl.Control, p interface{}) error {
} else {
isConfirmed, err := ctl.AskForConfirmation(out, c.Reader(), "WARNING: Destroyed keys can not be recovered. Type Y to continue or N to cancel.")
if err != nil {
return errors.Annotatef(err, "unable to get a confirmation to destroy keys")
return errors.WithMessagef(err, "unable to get a confirmation to destroy keys")
}

if !isConfirmed {
Expand Down Expand Up @@ -143,7 +143,7 @@ func destroyKeys(c ctl.Control, keyProv cryptoprov.KeyManager, slotID uint, keys
func destroyKey(c ctl.Control, keyProv cryptoprov.KeyManager, slotID uint, keyID string) error {
err := keyProv.DestroyKeyPairOnSlot(slotID, keyID)
if err != nil {
return errors.Annotatef(err, "unable to destroy key %q on slot %d", keyID, slotID)
return errors.WithMessagef(err, "unable to destroy key %q on slot %d", keyID, slotID)
}
fmt.Fprintf(c.Writer(), "destroyed key: %s\n", keyID)
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/dollypki/hsm/slots.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-phorce/dolly/cmd/dollypki/cli"
"github.com/go-phorce/dolly/ctl"
"github.com/go-phorce/dolly/xpki/cryptoprov"
"github.com/juju/errors"
"github.com/pkg/errors"
)

// Slots shows hsm slots
Expand All @@ -24,7 +24,7 @@ func Slots(c ctl.Control, _ interface{}) error {
return nil
})
if err != nil {
return errors.Annotate(err, "unable to list slots")
return errors.WithMessage(err, "unable to list slots")
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions ctl/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/go-phorce/dolly/xhttp/marshal"
"github.com/go-phorce/dolly/xlog"
"github.com/juju/errors"
"github.com/pkg/errors"
)

var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly", "ctl")
Expand Down Expand Up @@ -132,7 +132,7 @@ func (ctl *Ctl) ReturnCode() ReturnCode {
// Fail the execution and return error
func (ctl *Ctl) Fail(msg string, err error) error {
ctl.rc = RCFailed
logger.Errorf("message=%q, err=[%s]", msg, errors.ErrorStack(err))
logger.Errorf("message=%q, err=[%+v]", msg, err)
return err
}

Expand Down Expand Up @@ -175,7 +175,7 @@ var newLine = []byte("\n")
func WriteJSON(out io.Writer, value interface{}) error {
json, err := marshal.EncodeBytes(marshal.PrettyPrint, value)
if err != nil {
return errors.Annotate(err, "failed to encode")
return errors.WithMessage(err, "failed to encode")
}
out.Write(json)

Expand Down
Loading

0 comments on commit 6b8cabb

Please sign in to comment.