Procházet zdrojové kódy

[acme db interface] wip

max furman před 5 roky
rodič
revize
116869ebc5
4 změnil soubory, kde provedl 17 přidání a 16 odebrání
  1. 9 8
      acme/api/account.go
  2. 5 5
      acme/api/linker.go
  3. 1 1
      acme/api/order.go
  4. 2 2
      acme/db/nosql/order.go

+ 9 - 8
acme/api/account.go

@@ -65,7 +65,8 @@ func (u *UpdateAccountRequest) Validate() error {
 
 
 // NewAccount is the handler resource for creating new ACME accounts.
 // NewAccount is the handler resource for creating new ACME accounts.
 func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) {
 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 {
 	if err != nil {
 		api.WriteError(w, err)
 		api.WriteError(w, err)
 		return
 		return
@@ -97,7 +98,7 @@ func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) {
 				"account does not exist"))
 				"account does not exist"))
 			return
 			return
 		}
 		}
-		jwk, err := jwkFromContext(r.Context())
+		jwk, err := jwkFromContext(ctx)
 		if err != nil {
 		if err != nil {
 			api.WriteError(w, err)
 			api.WriteError(w, err)
 			return
 			return
@@ -108,7 +109,7 @@ func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) {
 			Contact: nar.Contact,
 			Contact: nar.Contact,
 			Status:  acme.StatusValid,
 			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"))
 			api.WriteError(w, acme.WrapErrorISE(err, "error creating account"))
 			return
 			return
 		}
 		}
@@ -126,12 +127,13 @@ func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) {
 
 
 // GetUpdateAccount is the api for updating an ACME account.
 // GetUpdateAccount is the api for updating an ACME account.
 func (h *Handler) GetUpdateAccount(w http.ResponseWriter, r *http.Request) {
 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 {
 	if err != nil {
 		api.WriteError(w, err)
 		api.WriteError(w, err)
 		return
 		return
 	}
 	}
-	payload, err := payloadFromContext(r.Context())
+	payload, err := payloadFromContext(ctx)
 	if err != nil {
 	if err != nil {
 		api.WriteError(w, err)
 		api.WriteError(w, err)
 		return
 		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).
 		// in the ACME spec (https://tools.ietf.org/html/rfc8555#section-7.3.2).
 		acc.Status = uar.Status
 		acc.Status = uar.Status
 		acc.Contact = uar.Contact
 		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"))
 			api.WriteError(w, acme.WrapErrorISE(err, "error updating account"))
 			return
 			return
 		}
 		}
@@ -164,8 +166,7 @@ func (h *Handler) GetUpdateAccount(w http.ResponseWriter, r *http.Request) {
 
 
 	h.linker.LinkAccount(ctx, acc)
 	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)
 	api.JSON(w, acc)
 }
 }
 
 

+ 5 - 5
acme/api/linker.go

@@ -136,9 +136,9 @@ func (l LinkType) String() string {
 
 
 // LinkOrder sets the ACME links required by an ACME order.
 // LinkOrder sets the ACME links required by an ACME order.
 func (l *Linker) LinkOrder(ctx context.Context, o *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)
 	o.FinalizeURL = l.GetLink(ctx, FinalizeLinkType, true, o.ID)
 	if o.CertificateID != "" {
 	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.
 // LinkAccount sets the ACME links required by an ACME account.
 func (l *Linker) LinkAccount(ctx context.Context, acc *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.
 // LinkChallenge sets the ACME links required by an ACME account.
 func (l *Linker) LinkChallenge(ctx context.Context, ch *acme.Challenge) {
 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.
 // LinkAuthorization sets the ACME links required by an ACME account.

+ 1 - 1
acme/api/order.go

@@ -119,7 +119,7 @@ func (h *Handler) NewOrder(w http.ResponseWriter, r *http.Request) {
 		return
 		return
 	}
 	}
 
 
-	h.linker.Link(ctx, o)
+	h.linker.LinkOrder(ctx, o)
 
 
 	w.Header().Set("Location", h.linker.GetLink(ctx, OrderLinkType, true, o.ID))
 	w.Header().Set("Location", h.linker.GetLink(ctx, OrderLinkType, true, o.ID))
 	api.JSONStatus(w, o, http.StatusCreated)
 	api.JSONStatus(w, o, http.StatusCreated)

+ 2 - 2
acme/db/nosql/order.go

@@ -203,8 +203,8 @@ func (oids orderIDs) save(db nosql.DB, old orderIDs, accID string) error {
 	case err != nil:
 	case err != nil:
 		return errors.Wrapf(err, "error storing order IDs for account %s", accID)
 		return errors.Wrapf(err, "error storing order IDs for account %s", accID)
 	case !swapped:
 	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:
 	default:
 		return nil
 		return nil
 	}
 	}