Rejig 404 handling again. (#4264)

Done this way, existing tests pass, and it makes logical sense, so we're
likely to have the least impact like this.
This commit is contained in:
Jeff Mitchell 2018-04-04 04:41:46 -04:00 committed by GitHub
parent 1481dd35b5
commit fe2fa0030f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 13 deletions

View File

@ -51,8 +51,8 @@ func (c *Logical) Read(path string) (*Secret, error) {
defer resp.Body.Close()
}
if resp != nil && resp.StatusCode == 404 {
secret, err := ParseSecret(resp.Body)
switch err {
secret, parseErr := ParseSecret(resp.Body)
switch parseErr {
case nil:
case io.EOF:
return nil, nil
@ -82,8 +82,8 @@ func (c *Logical) List(path string) (*Secret, error) {
defer resp.Body.Close()
}
if resp != nil && resp.StatusCode == 404 {
secret, err := ParseSecret(resp.Body)
switch err {
secret, parseErr := ParseSecret(resp.Body)
switch parseErr {
case nil:
case io.EOF:
return nil, nil
@ -113,8 +113,8 @@ func (c *Logical) Write(path string, data map[string]interface{}) (*Secret, erro
defer resp.Body.Close()
}
if resp != nil && resp.StatusCode == 404 {
secret, err := ParseSecret(resp.Body)
switch err {
secret, parseErr := ParseSecret(resp.Body)
switch parseErr {
case nil:
case io.EOF:
return nil, nil
@ -122,9 +122,8 @@ func (c *Logical) Write(path string, data map[string]interface{}) (*Secret, erro
return nil, err
}
if secret != nil && (len(secret.Warnings) > 0 || len(secret.Data) > 0) {
return secret, nil
return secret, err
}
return nil, nil
}
if err != nil {
return nil, err
@ -144,8 +143,8 @@ func (c *Logical) Delete(path string) (*Secret, error) {
defer resp.Body.Close()
}
if resp != nil && resp.StatusCode == 404 {
secret, err := ParseSecret(resp.Body)
switch err {
secret, parseErr := ParseSecret(resp.Body)
switch parseErr {
case nil:
case io.EOF:
return nil, nil
@ -153,9 +152,8 @@ func (c *Logical) Delete(path string) (*Secret, error) {
return nil, err
}
if secret != nil && (len(secret.Warnings) > 0 || len(secret.Data) > 0) {
return secret, nil
return secret, err
}
return nil, nil
}
if err != nil {
return nil, err

View File

@ -84,8 +84,12 @@ func (c *DeleteCommand) Run(args []string) int {
path := sanitizePath(args[0])
if _, err := client.Logical().Delete(path); err != nil {
secret, err := client.Logical().Delete(path)
if err != nil {
c.UI.Error(fmt.Sprintf("Error deleting %s: %s", path, err))
if secret != nil {
OutputSecret(c.UI, secret)
}
return 2
}

View File

@ -131,6 +131,9 @@ func (c *WriteCommand) Run(args []string) int {
secret, err := client.Logical().Write(path, data)
if err != nil {
c.UI.Error(fmt.Sprintf("Error writing data to %s: %s", path, err))
if secret != nil {
OutputSecret(c.UI, secret)
}
return 2
}
if secret == nil {