Generated plugins (acceptance.json at the root) fail on: HTTP routes not registered through pluginsdk route or a public route reading personal columns; HTML built from unescaped non-constant strings; public POSTs outside route.Form; personal data names in log calls; outbound requests carrying personal data or values the spec does not send to that host. First-party plugins get the same findings as warnings. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"git.dev.alexdunmow.com/block/pluginsdk/plugin"
|
|
"git.dev.alexdunmow.com/block/pluginsdk/route"
|
|
"git.dev.alexdunmow.com/private/quote-requests-a1a5c0/db"
|
|
)
|
|
|
|
func newHTTPHandler(deps plugin.CoreServices) http.Handler {
|
|
setServices(deps)
|
|
r := route.New(pluginName)
|
|
r.Handle(http.MethodPost, "/submit", route.Public, handleSubmit)
|
|
r.Handle(http.MethodGet, "/requests", route.Public, handleList)
|
|
return r
|
|
}
|
|
|
|
func handleSubmit(w http.ResponseWriter, r *http.Request) {
|
|
dbtx, ok := current.Pool.(db.DBTX)
|
|
if !ok {
|
|
http.Error(w, "service unavailable", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
params := db.InsertQuoteRequestParams{
|
|
Name: strings.TrimSpace(r.FormValue("name")),
|
|
Email: strings.TrimSpace(r.FormValue("email")),
|
|
PropertyAddress: strings.TrimSpace(r.FormValue("property_address")),
|
|
RoofIssue: strings.TrimSpace(r.FormValue("roof_issue")),
|
|
}
|
|
if err := db.New(dbtx).InsertQuoteRequest(r.Context(), params); err != nil {
|
|
http.Error(w, "could not save your request", http.StatusInternalServerError)
|
|
}
|
|
}
|
|
|
|
func handleList(w http.ResponseWriter, r *http.Request) {
|
|
rows, err := loadRequests(r)
|
|
if err != nil {
|
|
http.Error(w, "could not load requests", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
_ = json.NewEncoder(w).Encode(rows)
|
|
}
|
|
|
|
func loadRequests(r *http.Request) ([]db.QuoteRequest, error) {
|
|
dbtx, _ := current.Pool.(db.DBTX)
|
|
return db.New(dbtx).ListQuoteRequests(r.Context())
|
|
}
|