Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import "errors"

var (
ErrEncKeyNotFound = errors.New("encryption key not found")
ErrIssuerNotFound = errors.New("issuer not found")
)
22 changes: 21 additions & 1 deletion pki.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package vault

import (
"errors"
"github.com/hashicorp/vault/api"
"net/http"
"strings"
)

type PKI struct {
Service
}
Expand Down Expand Up @@ -252,7 +259,7 @@ func (k *PKI) ReadIssuer(issuerName string) (*PKIReadIssuerResponse, error) {
}, response, nil,
)
if err != nil {
return nil, err
return nil, k.mapError(err)
}

return response, nil
Expand Down Expand Up @@ -287,3 +294,16 @@ func (k *PKI) RevokeIssuer(issuerName string) (*PKIRevokeIssuerResponse, error)

return response, nil
}

func (k *PKI) mapError(err error) error {
resErr := &api.ResponseError{}
if errors.As(err, &resErr) {
if resErr.StatusCode == http.StatusInternalServerError {
if strings.Contains(err.Error(), "unable to find PKI issuer for reference") {
return ErrIssuerNotFound
}
}
}

return err
}
Loading