22 lines
976 B
Go
22 lines
976 B
Go
package servicekit
|
|
|
|
import (
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
|
"github.com/samcharles93/archie-core/internal/secret"
|
|
)
|
|
|
|
// StateStoreClient dials the State Store gRPC service as the caller service.
|
|
// 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 staterpc.Dial. Calls wait for the State Store rather than fail while it
|
|
// is down, so boot order between services does not matter.
|
|
func StateStoreClient(caller string, services config.Services, secrets *secret.Registry) (*staterpc.Client, func(), error) {
|
|
target, err := services.RequireTarget(config.ServiceNameState)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return staterpc.Dial(target, caller, services.ResolvedToken(config.ServiceNameState, secrets.Getenv), staterpc.WaitForPeer)
|
|
}
|