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) {
|
||||
lg := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||
slog.SetDefault(lg)
|
||||
|
||||
pay, ok := s.verifyJWS(ctx, w, r)
|
||||
if !ok {
|
||||
lg.Error("handleNewOrder", "pay", "")
|
||||
return
|
||||
}
|
||||
var req acme.Order
|
||||
if err := json.Unmarshal(pay.Data, &req); err != nil {
|
||||
lg.Error("handleNewOrder", "json.Unmarshal", err.Error())
|
||||
http.Error(w, "bad order", 400)
|
||||
return
|
||||
}
|
||||
if len(req.Identifiers) == 0 {
|
||||
lg.Error("handleNewOrder", "req.Identifiers", "")
|
||||
http.Error(w, "missing identifiers", 400)
|
||||
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)
|
||||
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 {
|
||||
lg.Error("handleNewOrder", "ExecContent", err.Error())
|
||||
http.Error(w, "db", 500)
|
||||
return
|
||||
}
|
||||
@@ -759,6 +766,8 @@ func (s *server) handleNewOrder(ctx context.Context, w http.ResponseWriter, r *h
|
||||
nonce := uuid.New().String()
|
||||
_ = s.db.putNonce(ctx, nonce)
|
||||
|
||||
lg.Error("handleNewOrder", "Function", "Final")
|
||||
|
||||
w.Header().Set("Location", ordURL)
|
||||
s.jsonResponse(w, 201, resp, nonce)
|
||||
}
|
||||
|
Reference in New Issue
Block a user