[acme db interface] wip

This commit is contained in:
max furman 2021-03-04 23:14:56 -08:00
parent 80a6640103
commit 116869ebc5
4 changed files with 17 additions and 16 deletions

View file

@ -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)
}

View file

@ -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.

View file

@ -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)

View file

@ -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
}