44 "fmt"
55 "os"
66
7+ "github.com/pkg/errors"
8+
79 "github.com/Sirupsen/logrus"
810 vault "github.com/hashicorp/vault/api"
911)
@@ -52,9 +54,9 @@ type Vault struct {
5254 KeyMapping map [string ]string
5355}
5456
55- func (v * Vault ) Secret (path , field string ) string {
57+ func (v * Vault ) Secret (path , field string ) ( string , error ) {
5658 if v .client == nil {
57- return ""
59+ return "" , errors . New ( "no vault client available" )
5860 }
5961 prefixPath := fmt .Sprintf ("%s%s" , v .Prefix , path )
6062 mapped , ok := v .KeyMapping [prefixPath ]
@@ -63,23 +65,14 @@ func (v *Vault) Secret(path, field string) string {
6365 }
6466 sec , err := v .client .Logical ().Read (mapped )
6567 if err != nil {
66- if v .logger != nil {
67- v .logger .WithError (err ).Errorf ("Failed to access Vault path %s" , mapped )
68- }
69- return ""
68+ return "" , errors .Wrapf (err , "failed to access Vault path %s" , mapped )
7069 }
7170 if sec == nil {
72- if v .logger != nil {
73- v .logger .Errorf ("Vault path %s contained no secret" , mapped )
74- }
75- return ""
71+ return "" , errors .Errorf ("Vault path %s contained no secret" , mapped )
7672 }
7773 raw , ok := sec .Data [field ]
7874 if ! ok {
79- if v .logger != nil {
80- v .logger .Errorf ("%s has no field named '%s'" , mapped , field )
81- }
82- return ""
75+ return "" , errors .Errorf ("%s has no field named '%s'" , mapped , field )
8376 }
84- return fmt .Sprintf ("%s" , raw )
77+ return fmt .Sprintf ("%s" , raw ), nil
8578}
0 commit comments