31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package servicekit
|
|
|
|
import (
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
|
)
|
|
|
|
// Identity loads service's certificate from [tls]; nil means plaintext,
|
|
// loopback only.
|
|
func Identity(cfg config.TLS, service string) (*rpctls.Identity, error) {
|
|
return rpctls.Load(cfg.CAFile, cfg.CertDir, service)
|
|
}
|
|
|
|
// StateStoreClient dials the State Store gRPC service as the caller service.
|
|
// 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, cfg config.Config, options ...grpc.DialOption) (*staterpc.Client, func(), error) {
|
|
target, err := cfg.Services.RequireTarget(config.ServiceNameState)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
id, err := Identity(cfg.TLS, caller)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return staterpc.Dial(target, caller, id, append([]grpc.DialOption{staterpc.WaitForPeer}, options...)...)
|
|
}
|