Skip to content

Commit

Permalink
delete lease if cloudflare returns 404
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinschoonover committed Jan 22, 2022
1 parent 43646ec commit 0c7fd4d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions secret_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package cloudflare

import (
"context"
"errors"
"fmt"
"net/http"
"time"

"github.com/cloudflare/cloudflare-go"
Expand Down Expand Up @@ -96,6 +98,11 @@ func (b *backend) secretTokenRevoke(ctx context.Context, req *logical.Request, d
b.Logger().Info(fmt.Sprintf("Revoking cloudflare token (%s)...", id))
err = c.DeleteAPIToken(ctx, id.(string))
if err != nil {
var responseError *cloudflare.APIRequestError
// If cloudflare returns 404 that means the token is already deleted
if errors.As(err, &responseError) && responseError.HTTPStatusCode() == http.StatusNotFound {
return nil, nil
}
return logical.ErrorResponse(fmt.Sprintf("failed to revoke cloudflare token (%s). err: %s", id, err)), nil
}

Expand Down

0 comments on commit 0c7fd4d

Please sign in to comment.