From f9ae875f9d09e699d461a70e5cb4fd76d2e1c6a1 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Mon, 20 Dec 2021 14:30:01 +0100 Subject: [PATCH] Use short if-style statements --- acme/api/account.go | 3 +-- acme/db/nosql/account.go | 3 +-- authority/admin/api/acme.go | 12 ++++-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/acme/api/account.go b/acme/api/account.go index a917b0e0..658c40a8 100644 --- a/acme/api/account.go +++ b/acme/api/account.go @@ -297,8 +297,7 @@ func (h *Handler) validateExternalAccountBinding(ctx context.Context, nar *NewAc } var payloadJWK *jose.JSONWebKey - err = json.Unmarshal(payload, &payloadJWK) - if err != nil { + if err = json.Unmarshal(payload, &payloadJWK); err != nil { return nil, acme.WrapError(acme.ErrorMalformedType, err, "error unmarshaling payload into jwk") } diff --git a/acme/db/nosql/account.go b/acme/db/nosql/account.go index 9464e9a4..ca51e8ba 100644 --- a/acme/db/nosql/account.go +++ b/acme/db/nosql/account.go @@ -251,8 +251,7 @@ func (db *DB) DeleteExternalAccountKey(ctx context.Context, provisionerName, key return errors.Wrapf(err, "error deleting ACME EAB Key Reference with Key ID %s and reference %s", keyID, dbeak.Reference) } } - err = db.db.Del(externalAccountKeyTable, []byte(keyID)) - if err != nil { + if err = db.db.Del(externalAccountKeyTable, []byte(keyID)); err != nil { return errors.Wrapf(err, "error deleting ACME EAB Key with Key ID %s", keyID) } return nil diff --git a/authority/admin/api/acme.go b/authority/admin/api/acme.go index 39aeed49..48e81ecc 100644 --- a/authority/admin/api/acme.go +++ b/authority/admin/api/acme.go @@ -102,8 +102,7 @@ func (h *Handler) CreateExternalAccountKey(w http.ResponseWriter, r *http.Reques k, err := h.acmeDB.GetExternalAccountKeyByReference(r.Context(), prov, reference) // retrieving an EAB key from DB results in an error if it doesn't exist, which is what we're looking for, // but other errors can also happen. Return early if that happens; continuing if it was acme.ErrNotFound. - shouldWriteError := err != nil && !errors.Is(err, acme.ErrNotFound) - if shouldWriteError { + if shouldWriteError := err != nil && !errors.Is(err, acme.ErrNotFound); shouldWriteError { api.WriteError(w, admin.WrapErrorISE(err, "could not lookup external account key by reference")) return } @@ -164,16 +163,14 @@ func (h *Handler) GetExternalAccountKeys(w http.ResponseWriter, r *http.Request) limit int ) - cursor, limit, err = api.ParseCursor(r) - if err != nil { + if cursor, limit, err = api.ParseCursor(r); err != nil { api.WriteError(w, admin.WrapError(admin.ErrorBadRequestType, err, "error parsing cursor and limit from query params")) return } if reference != "" { - key, err = h.acmeDB.GetExternalAccountKeyByReference(r.Context(), prov, reference) - if err != nil { + if key, err = h.acmeDB.GetExternalAccountKeyByReference(r.Context(), prov, reference); err != nil { api.WriteError(w, admin.WrapErrorISE(err, "error retrieving external account key with reference '%s'", reference)) return } @@ -181,8 +178,7 @@ func (h *Handler) GetExternalAccountKeys(w http.ResponseWriter, r *http.Request) keys = []*acme.ExternalAccountKey{key} } } else { - keys, nextCursor, err = h.acmeDB.GetExternalAccountKeys(r.Context(), prov, cursor, limit) - if err != nil { + if keys, nextCursor, err = h.acmeDB.GetExternalAccountKeys(r.Context(), prov, cursor, limit); err != nil { api.WriteError(w, admin.WrapErrorISE(err, "error retrieving external account keys")) return }