@@ -154,8 +154,10 @@ func (cs ConsulStorage) Load(key string) ([]byte, error) {
154
154
155
155
kv , _ , err := cs .ConsulClient .KV ().Get (cs .prefixKey (key ), & consul.QueryOptions {RequireConsistent : true })
156
156
if err != nil {
157
- return nil , errors .Wrapf (err , "unable to obtain data for %s" , cs .prefixKey (key ))
158
- } else if kv == nil {
157
+ return nil , certmagic .ErrNotExist (errors .Wrapf (err , "unable to obtain data for %s" , cs .prefixKey (key )))
158
+ }
159
+
160
+ if kv == nil {
159
161
return nil , certmagic .ErrNotExist (errors .Errorf ("key %s does not exist" , cs .prefixKey (key )))
160
162
}
161
163
@@ -174,8 +176,10 @@ func (cs ConsulStorage) Delete(key string) error {
174
176
// first obtain existing keypair
175
177
kv , _ , err := cs .ConsulClient .KV ().Get (cs .prefixKey (key ), & consul.QueryOptions {RequireConsistent : true })
176
178
if err != nil {
177
- return errors .Wrapf (err , "unable to obtain data for %s" , cs .prefixKey (key ))
178
- } else if kv == nil {
179
+ return certmagic .ErrNotExist (errors .Wrapf (err , "unable to obtain data for %s" , cs .prefixKey (key )))
180
+ }
181
+
182
+ if kv == nil {
179
183
return certmagic .ErrNotExist (err )
180
184
}
181
185
@@ -205,7 +209,7 @@ func (cs ConsulStorage) List(prefix string, recursive bool) ([]string, error) {
205
209
// get a list of all keys at prefix
206
210
keys , _ , err := cs .ConsulClient .KV ().Keys (cs .prefixKey (prefix ), "" , & consul.QueryOptions {RequireConsistent : true })
207
211
if err != nil {
208
- return keysFound , err
212
+ return keysFound , certmagic . ErrNotExist ( errors . Wrapf ( err , "no keys at %s" , prefix ))
209
213
}
210
214
211
215
if len (keys ) == 0 {
@@ -245,7 +249,8 @@ func (cs ConsulStorage) Stat(key string) (certmagic.KeyInfo, error) {
245
249
kv , _ , err := cs .ConsulClient .KV ().Get (cs .prefixKey (key ), & consul.QueryOptions {RequireConsistent : true })
246
250
if err != nil {
247
251
return certmagic.KeyInfo {}, errors .Errorf ("unable to obtain data for %s" , cs .prefixKey (key ))
248
- } else if kv == nil {
252
+ }
253
+ if kv == nil {
249
254
return certmagic.KeyInfo {}, certmagic .ErrNotExist (errors .Errorf ("key %s does not exist" , cs .prefixKey (key )))
250
255
}
251
256
@@ -287,6 +292,7 @@ func (cs *ConsulStorage) createConsulClient() error {
287
292
if err != nil {
288
293
return errors .Wrap (err , "unable to create Consul client" )
289
294
}
295
+
290
296
if _ , err := consulClient .Agent ().NodeName (); err != nil {
291
297
return errors .Wrap (err , "unable to ping Consul" )
292
298
}
0 commit comments