From 116869ebc5ca3bbfa07946caf9cbb8fa842703dc Mon Sep 17 00:00:00 2001 From: max furman Date: Thu, 4 Mar 2021 23:14:56 -0800 Subject: [PATCH] [acme db interface] wip --- acme/api/account.go | 17 +++++++++-------- acme/api/linker.go | 10 +++++----- acme/api/order.go | 2 +- acme/db/nosql/order.go | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/acme/api/account.go b/acme/api/account.go index 16cc1f79..6f2a5f96 100644 --- a/acme/api/account.go +++ b/acme/api/account.go @@ -65,7 +65,8 @@ func (u *UpdateAccountRequest) Validate() error { // NewAccount is the handler resource for creating new ACME accounts. func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) { - payload, err := payloadFromContext(r.Context()) + ctx := r.Context() + payload, err := payloadFromContext(ctx) if err != nil { api.WriteError(w, err) return @@ -97,7 +98,7 @@ func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) { "account does not exist")) return } - jwk, err := jwkFromContext(r.Context()) + jwk, err := jwkFromContext(ctx) if err != nil { api.WriteError(w, err) return @@ -108,7 +109,7 @@ func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) { Contact: nar.Contact, Status: acme.StatusValid, } - if err := h.db.CreateAccount(r.Context(), acc); err != nil { + if err := h.db.CreateAccount(ctx, acc); err != nil { api.WriteError(w, acme.WrapErrorISE(err, "error creating account")) return } @@ -126,12 +127,13 @@ func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) { // GetUpdateAccount is the api for updating an ACME account. func (h *Handler) GetUpdateAccount(w http.ResponseWriter, r *http.Request) { - acc, err := accountFromContext(r.Context()) + ctx := r.Context() + acc, err := accountFromContext(ctx) if err != nil { api.WriteError(w, err) return } - payload, err := payloadFromContext(r.Context()) + payload, err := payloadFromContext(ctx) if err != nil { api.WriteError(w, err) return @@ -156,7 +158,7 @@ func (h *Handler) GetUpdateAccount(w http.ResponseWriter, r *http.Request) { // in the ACME spec (https://tools.ietf.org/html/rfc8555#section-7.3.2). acc.Status = uar.Status acc.Contact = uar.Contact - if err = h.db.UpdateAccount(r.Context(), acc); err != nil { + if err = h.db.UpdateAccount(ctx, acc); err != nil { api.WriteError(w, acme.WrapErrorISE(err, "error updating account")) return } @@ -164,8 +166,7 @@ func (h *Handler) GetUpdateAccount(w http.ResponseWriter, r *http.Request) { h.linker.LinkAccount(ctx, acc) - w.Header().Set("Location", h.linker.GetLink(r.Context(), AccountLinkType, - true, acc.ID)) + w.Header().Set("Location", h.linker.GetLink(ctx, AccountLinkType, true, acc.ID)) api.JSON(w, acc) } diff --git a/acme/api/linker.go b/acme/api/linker.go index dd3b4540..d07271e2 100644 --- a/acme/api/linker.go +++ b/acme/api/linker.go @@ -136,9 +136,9 @@ func (l LinkType) String() string { // LinkOrder sets the ACME links required by an ACME order. func (l *Linker) LinkOrder(ctx context.Context, o *acme.Order) { - o.azURLs = make([]string, len(o.AuthorizationIDs)) - for i, azID := range o.AutohrizationIDs { - o.azURLs[i] = l.GetLink(ctx, AuthzLinkType, true, azID) + o.AuthorizationURLs = make([]string, len(o.AuthorizationIDs)) + for i, azID := range o.AuthorizationIDs { + o.AuthorizationURLs[i] = l.GetLink(ctx, AuthzLinkType, true, azID) } o.FinalizeURL = l.GetLink(ctx, FinalizeLinkType, true, o.ID) if o.CertificateID != "" { @@ -148,12 +148,12 @@ func (l *Linker) LinkOrder(ctx context.Context, o *acme.Order) { // LinkAccount sets the ACME links required by an ACME account. func (l *Linker) LinkAccount(ctx context.Context, acc *acme.Account) { - a.Orders = l.GetLink(ctx, OrdersByAccountLinkType, true, acc.ID) + acc.Orders = l.GetLink(ctx, OrdersByAccountLinkType, true, acc.ID) } // LinkChallenge sets the ACME links required by an ACME account. func (l *Linker) LinkChallenge(ctx context.Context, ch *acme.Challenge) { - a.URL = l.GetLink(ctx, ChallengeLinkType, true, ch.AuthzID, ch.ID) + ch.URL = l.GetLink(ctx, ChallengeLinkType, true, ch.AuthzID, ch.ID) } // LinkAuthorization sets the ACME links required by an ACME account. diff --git a/acme/api/order.go b/acme/api/order.go index 2bf7d2ef..9fe0eb26 100644 --- a/acme/api/order.go +++ b/acme/api/order.go @@ -119,7 +119,7 @@ func (h *Handler) NewOrder(w http.ResponseWriter, r *http.Request) { return } - h.linker.Link(ctx, o) + h.linker.LinkOrder(ctx, o) w.Header().Set("Location", h.linker.GetLink(ctx, OrderLinkType, true, o.ID)) api.JSONStatus(w, o, http.StatusCreated) diff --git a/acme/db/nosql/order.go b/acme/db/nosql/order.go index 2f5ee11b..9e83e7ff 100644 --- a/acme/db/nosql/order.go +++ b/acme/db/nosql/order.go @@ -203,8 +203,8 @@ func (oids orderIDs) save(db nosql.DB, old orderIDs, accID string) error { case err != nil: return errors.Wrapf(err, "error storing order IDs for account %s", accID) case !swapped: - return ServerInternalErr(errors.Errorf("error storing order IDs "+ - "for account %s; order IDs changed since last read", accID)) + return errors.Errorf("error storing order IDs "+ + "for account %s; order IDs changed since last read", accID) default: return nil }