Add 'endpoints' to Gateway to support multiple vhosts#2139
Conversation
📝 WalkthroughSummaryThis PR adds support for multiple endpoints (vhosts) to gateways, enabling them to operate across multiple host/protocol/port combinations. This resolves the need for Event Gateway to support services on different ports and protocols simultaneously (e.g., HTTPS on 8443 for WebSub and WSS on 8444 for WebBroker). ChangesAPI Layer:
Data Model:
Database:
Service Layer:
Handler & Repository:
Tests:
The existing WalkthroughThis pull request introduces gateway endpoint support by adding a new Sequence DiagramsequenceDiagram
participant Client
participant Handler as GatewayHandler
participant Service as GatewayService
participant Repository as GatewayRepo
participant Database
Client->>Handler: CreateGateway(endpoints: [{host, protocol, port}])
Handler->>Handler: Convert api.Endpoint[] to model.Endpoint[]
Handler->>Service: RegisterGateway(..., endpoints)
Service->>Service: Assign endpoints to model.Gateway
Service->>Repository: Create(gateway with endpoints)
Repository->>Repository: Serialize endpoints to JSON
Repository->>Database: INSERT gateways(endpoints, ...)
Database-->>Repository: Success
Repository-->>Service: gateway (loaded with endpoints)
Service->>Service: Convert model.Endpoint[] to api.Endpoint[]
Service-->>Handler: api.GatewayResponse(endpoints: [...])
Handler-->>Client: JSON response with endpoints array
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@platform-api/src/api/generated.go`:
- Around line 462-463: The generated constants Http and Https on type
WebSubAPITransport break source compatibility; restore deprecated aliases named
WebSubAPITransportHttp and WebSubAPITransportHttps by adding a non-generated
file that declares var (or const) WebSubAPITransportHttp =
WebSubAPITransport("http") and WebSubAPITransportHttps =
WebSubAPITransport("https") (or assigns to the existing Http/Https values) with
a deprecation comment, so callers referencing
WebSubAPITransportHttp/WebSubAPITransportHttps continue to compile; reference
the existing WebSubAPITransport type and the generated Http and Https symbols
when locating where to add the aliases.
In `@platform-api/src/internal/service/gateway.go`:
- Around line 490-493: Validate the incoming endpoints slice before
assigning/persisting: in the gateway create/update service methods (the function
taking parameters including orgID, name, displayName, vhost, functionalityType,
properties, endpoints and calling s.validateGatewayInput), iterate over each
model.GatewayEndpoint and enforce required rules (e.g., non-empty Host, Port
within 1–65535, and any other protocol-specific fields you expect), returning a
descriptive error if any endpoint is invalid; perform this validation prior to
any assignment or DB call and apply the same checks in the corresponding update
path (the other handler mentioned around lines 647–649) so invalid endpoint
entries are rejected at the service boundary.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3b7fb5a8-cbf4-4047-a443-19e36f64d006
📒 Files selected for processing (11)
platform-api/src/api/generated.goplatform-api/src/internal/database/schema.postgres.sqlplatform-api/src/internal/database/schema.sqlplatform-api/src/internal/database/schema.sqlite.sqlplatform-api/src/internal/handler/gateway.goplatform-api/src/internal/model/gateway.goplatform-api/src/internal/repository/gateway.goplatform-api/src/internal/service/gateway.goplatform-api/src/internal/service/gateway_endpoints_test.goplatform-api/src/internal/service/gateway_properties_test.goplatform-api/src/resources/openapi.yaml
| Http WebSubAPITransport = "http" | ||
| Https WebSubAPITransport = "https" |
There was a problem hiding this comment.
Preserve backward compatibility for WebSubAPITransport exported constants.
Line 462 and Line 463 expose Http/Https, which is a source-compatible break for callers using WebSubAPITransportHttp/WebSubAPITransportHttps. Please add deprecated aliases (in a non-generated file) or restore enum var names in the OpenAPI generation config to avoid breaking existing consumers.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@platform-api/src/api/generated.go` around lines 462 - 463, The generated
constants Http and Https on type WebSubAPITransport break source compatibility;
restore deprecated aliases named WebSubAPITransportHttp and
WebSubAPITransportHttps by adding a non-generated file that declares var (or
const) WebSubAPITransportHttp = WebSubAPITransport("http") and
WebSubAPITransportHttps = WebSubAPITransport("https") (or assigns to the
existing Http/Https values) with a deprecation comment, so callers referencing
WebSubAPITransportHttp/WebSubAPITransportHttps continue to compile; reference
the existing WebSubAPITransport type and the generated Http and Https symbols
when locating where to add the aliases.
| functionalityType, version string, properties map[string]interface{}, endpoints []model.GatewayEndpoint) (*api.GatewayResponse, error) { | ||
| // 1. Validate inputs | ||
| if err := s.validateGatewayInput(orgID, name, displayName, vhost, functionalityType); err != nil { | ||
| return nil, err |
There was a problem hiding this comment.
Validate endpoint entries before storing them.
endpoints are accepted in create/update flows but are not validated at the service boundary. Add checks (e.g., non-empty host and valid port range) before assigning/persisting to keep stored gateway endpoint data consistent.
Proposed fix
+func validateGatewayEndpoints(endpoints []model.GatewayEndpoint) error {
+ for i, ep := range endpoints {
+ if strings.TrimSpace(ep.Host) == "" {
+ return fmt.Errorf("endpoint[%d].host is required", i)
+ }
+ if ep.Port < 1 || ep.Port > 65535 {
+ return fmt.Errorf("endpoint[%d].port must be between 1 and 65535", i)
+ }
+ }
+ return nil
+}
+
func (s *GatewayService) RegisterGateway(orgID, name, displayName, description, vhost string, isCritical bool,
functionalityType, version string, properties map[string]interface{}, endpoints []model.GatewayEndpoint) (*api.GatewayResponse, error) {
// 1. Validate inputs
if err := s.validateGatewayInput(orgID, name, displayName, vhost, functionalityType); err != nil {
return nil, err
}
+ if err := validateGatewayEndpoints(endpoints); err != nil {
+ return nil, err
+ }
@@
if endpoints != nil {
+ if err := validateGatewayEndpoints(*endpoints); err != nil {
+ return nil, err
+ }
gateway.Endpoints = *endpoints
}Also applies to: 647-649
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@platform-api/src/internal/service/gateway.go` around lines 490 - 493,
Validate the incoming endpoints slice before assigning/persisting: in the
gateway create/update service methods (the function taking parameters including
orgID, name, displayName, vhost, functionalityType, properties, endpoints and
calling s.validateGatewayInput), iterate over each model.GatewayEndpoint and
enforce required rules (e.g., non-empty Host, Port within 1–65535, and any other
protocol-specific fields you expect), returning a descriptive error if any
endpoint is invalid; perform this validation prior to any assignment or DB call
and apply the same checks in the corresponding update path (the other handler
mentioned around lines 647–649) so invalid endpoint entries are rejected at the
service boundary.
- DO NOT MERGE. We have to have a discussion and find out if we are going to get rid of the vhost column, along with a migration. Until that's figured out, we shouldn't merge thisPurpose
httpson 8443wsson 8444 for WebSocket receiverResolves #2128.
Goals