This commit is contained in:
9
main.go
9
main.go
@@ -717,16 +717,22 @@ func (s *server) handleNewAccount(ctx context.Context, w http.ResponseWriter, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *server) handleNewOrder(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
func (s *server) handleNewOrder(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
lg := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||||
|
slog.SetDefault(lg)
|
||||||
|
|
||||||
pay, ok := s.verifyJWS(ctx, w, r)
|
pay, ok := s.verifyJWS(ctx, w, r)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
lg.Error("handleNewOrder", "pay", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var req acme.Order
|
var req acme.Order
|
||||||
if err := json.Unmarshal(pay.Data, &req); err != nil {
|
if err := json.Unmarshal(pay.Data, &req); err != nil {
|
||||||
|
lg.Error("handleNewOrder", "json.Unmarshal", err.Error())
|
||||||
http.Error(w, "bad order", 400)
|
http.Error(w, "bad order", 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(req.Identifiers) == 0 {
|
if len(req.Identifiers) == 0 {
|
||||||
|
lg.Error("handleNewOrder", "req.Identifiers", "")
|
||||||
http.Error(w, "missing identifiers", 400)
|
http.Error(w, "missing identifiers", 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -738,6 +744,7 @@ func (s *server) handleNewOrder(ctx context.Context, w http.ResponseWriter, r *h
|
|||||||
// Persist order minimal info (we ignore authz for brevity)
|
// Persist order minimal info (we ignore authz for brevity)
|
||||||
payload, _ := json.Marshal(req)
|
payload, _ := json.Marshal(req)
|
||||||
if _, err := s.db.db.ExecContext(ctx, `INSERT INTO orders(id,payload,status,finalize_url) VALUES (?,?,?,?)`, orderID, payload, acme.StatusPending, finURL); err != nil {
|
if _, err := s.db.db.ExecContext(ctx, `INSERT INTO orders(id,payload,status,finalize_url) VALUES (?,?,?,?)`, orderID, payload, acme.StatusPending, finURL); err != nil {
|
||||||
|
lg.Error("handleNewOrder", "ExecContent", err.Error())
|
||||||
http.Error(w, "db", 500)
|
http.Error(w, "db", 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -759,6 +766,8 @@ func (s *server) handleNewOrder(ctx context.Context, w http.ResponseWriter, r *h
|
|||||||
nonce := uuid.New().String()
|
nonce := uuid.New().String()
|
||||||
_ = s.db.putNonce(ctx, nonce)
|
_ = s.db.putNonce(ctx, nonce)
|
||||||
|
|
||||||
|
lg.Error("handleNewOrder", "Function", "Final")
|
||||||
|
|
||||||
w.Header().Set("Location", ordURL)
|
w.Header().Set("Location", ordURL)
|
||||||
s.jsonResponse(w, 201, resp, nonce)
|
s.jsonResponse(w, 201, resp, nonce)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user