2024-12-16 15:29:54 -05:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
|
"github.com/medama-io/go-useragent"
|
|
|
|
|
"github.com/onsonr/sonr/crypto/mpc"
|
|
|
|
|
"github.com/onsonr/sonr/internal/config/hway"
|
2024-12-18 15:53:45 -05:00
|
|
|
"github.com/onsonr/sonr/internal/models/drivers/hwayorm"
|
2024-12-16 15:29:54 -05:00
|
|
|
"github.com/onsonr/sonr/pkg/common"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GatewayContext struct {
|
|
|
|
|
echo.Context
|
|
|
|
|
agent useragent.UserAgent
|
|
|
|
|
id string
|
2024-12-18 15:53:45 -05:00
|
|
|
dbq *hwayorm.Queries
|
2024-12-16 15:29:54 -05:00
|
|
|
ipfsClient common.IPFS
|
|
|
|
|
tokenStore common.IPFSTokenStore
|
|
|
|
|
stagedEnclaves map[string]mpc.Enclave
|
|
|
|
|
grpcAddr string
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-18 15:53:45 -05:00
|
|
|
func UseGateway(env hway.Hway, ipc common.IPFS, db *hwayorm.Queries) echo.MiddlewareFunc {
|
2024-12-16 15:29:54 -05:00
|
|
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
|
|
|
return func(c echo.Context) error {
|
|
|
|
|
ua := useragent.NewParser()
|
|
|
|
|
ctx := &GatewayContext{
|
2024-12-18 15:53:45 -05:00
|
|
|
agent: ua.Parse(c.Request().UserAgent()),
|
2024-12-16 15:29:54 -05:00
|
|
|
Context: c,
|
2024-12-18 15:53:45 -05:00
|
|
|
dbq: db,
|
2024-12-16 15:29:54 -05:00
|
|
|
ipfsClient: ipc,
|
|
|
|
|
grpcAddr: env.GetSonrGrpcUrl(),
|
|
|
|
|
tokenStore: common.NewUCANStore(ipc),
|
|
|
|
|
}
|
|
|
|
|
return next(ctx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|