mcp and ucp
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/cart"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/promotions"
|
||||
promotionmcp "git.k6n.net/mats/go-cart-actor/pkg/promotions/mcp"
|
||||
"git.k6n.net/mats/go-cart-actor/internal/ucp"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/proxy"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/voucher"
|
||||
"git.k6n.net/mats/go-redis-inventory/pkg/inventory"
|
||||
@@ -66,6 +67,26 @@ func normalizeListenAddr(v string) string {
|
||||
return ":" + v
|
||||
}
|
||||
|
||||
// loadUCPCartSigner loads the UCP ECDSA signing key from the path specified in
|
||||
// the UCP_SIGNING_KEY_PATH environment variable. Returns nil if unset or unreadable.
|
||||
func loadUCPCartSigner() *ucp.SigningConfig {
|
||||
path := os.Getenv("UCP_SIGNING_KEY_PATH")
|
||||
if path == "" {
|
||||
return nil
|
||||
}
|
||||
pemData, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Printf("ucp signing: cannot read key %s: %v", path, err)
|
||||
return nil
|
||||
}
|
||||
cfg, err := ucp.NewSigningConfigFromPEM(pemData, "k6n-ecdsa-2026")
|
||||
if err != nil {
|
||||
log.Printf("ucp signing: invalid key at %s: %v", path, err)
|
||||
return nil
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func getCountryFromHost(host string) string {
|
||||
if strings.Contains(strings.ToLower(host), "-no") {
|
||||
return "no"
|
||||
@@ -278,6 +299,15 @@ func main() {
|
||||
mux.Handle("/mcp", promotionMCP.Handler())
|
||||
mux.Handle("/mcp/", promotionMCP.Handler())
|
||||
|
||||
// UCP REST adapter — Universal Commerce Protocol
|
||||
cartUCP := ucp.CartHandler(pool)
|
||||
if signer := loadUCPCartSigner(); signer != nil {
|
||||
cartUCP = ucp.WithSigning(cartUCP, signer)
|
||||
log.Print("ucp signing enabled")
|
||||
}
|
||||
mux.Handle("/ucp/v1/carts", cartUCP)
|
||||
mux.Handle("/ucp/v1/carts/", cartUCP)
|
||||
|
||||
// Stateless promotion evaluation: POST a (possibly partial) eval context and
|
||||
// get back the resulting totals plus the applied/pending effect breakdown,
|
||||
// without creating or mutating a real cart.
|
||||
|
||||
Reference in New Issue
Block a user