ServiceSpec.Context documented which addresses a service must end up with, but nothing read it, so a typo'd context was accepted and meant nothing. Review caught it as scaffolding that looked load-bearing. RegisterService now validates it: an unknown context, or a hosted (server/both) service registered with no default listen address, panics. Registrations come from this repository's own init(), never from operator input, so an invalid one is a programming error with no caller positioned to handle an error return, and failing at process start beats a service binding where nobody dials. Services.RequireTarget replaces the same check and message hand-written in composeStateStoreClient and composeChatContract. An empty registered default target is what declares a target operator-supplied, so the requirement belongs to the registry rather than to each consumer. It stays a lazy check at composition time rather than becoming load-time validation: a process that never dials a service must still load a configuration that omits it. The review's stated failure mode does not occur. A hosted service with an empty listen does not reach net.Listen as an ephemeral port; resolveServiceListen returns "no listen address" and archied refuses to start. The defect was the inert field, not a silent bind. Refs: archie-core-u23g
31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
package archied
|
|
|
|
import (
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
|
"github.com/samcharles93/archie-core/internal/secret"
|
|
)
|
|
|
|
// composeChatContract dials the standalone archie-gateway, the sole owner of
|
|
// ChatContract, from the daemon's own configuration key. Token resolution is
|
|
// the daemon's (it owns the config keys and the secret registry); the dial
|
|
// itself and the fail-closed non-loopback rule belong to the transport, so
|
|
// they come from gatewayrpc.Dial.
|
|
func composeChatContract(services config.Services, secrets *secret.Registry, options ...grpc.DialOption) (gateway.ChatContract, func(), error) {
|
|
target, err := services.RequireTarget(config.ServiceNameGateway)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
// Assigned through a typed variable rather than returned directly: a
|
|
// direct forward would hand a failed dial's nil *Client back as a
|
|
// non-nil ChatContract interface.
|
|
client, cleanup, err := gatewayrpc.Dial(target, services.ResolvedToken(config.ServiceNameGateway, secrets.Getenv), options...)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return client, cleanup, nil
|
|
}
|