From 0c7fd4d9fd4403aac985ddd62ebc59505b30ba2d Mon Sep 17 00:00:00 2001 From: Kevin Schoonover Date: Sat, 22 Jan 2022 13:35:43 -0800 Subject: [PATCH] delete lease if cloudflare returns 404 --- secret_token.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/secret_token.go b/secret_token.go index df72083..a1cef0e 100644 --- a/secret_token.go +++ b/secret_token.go @@ -2,7 +2,9 @@ package cloudflare import ( "context" + "errors" "fmt" + "net/http" "time" "github.com/cloudflare/cloudflare-go" @@ -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 }