Files
ca/Documentation/api/server_service_shared.md
dissoupovandGitHub 27e411997c Added integration tests (#16)
* Refactor Backend service

* Added integration tests
2026-10-23 18:02:39 -05:00

3.6 KiB

shared

import "github.com/effective-security/trustyca/server/service/shared"

Package shared contains the helpers that several services use.

BackendLocator returns the backend service (privpb.Backend) that the CA service forwards every call to and the AIA its OCSP requests: the one of the same process when porto discovery has a privpb.BackendServer, else a client of the backend listener created on the first call with the named service client.

backend := shared.NewBackendLocator(server.Discovery, factory, client.ClientNameCA, config.BackendServerName)
srv, err := backend.Backend()
if err != nil {
	return err
}
res, err := srv.SignCertificate(ctx, req)

Index

type BackendLocator

BackendLocator returns the backend the CA service forwards every call to, and the AIA its OCSP requests (DESIGN.md section 2.1): the backend service of the same process when discovery has one, else a client of the backend listener dialed with the named service client. The lookup runs on the first call, never at startup, because the gRPC client blocks until the backend is reachable and the listeners start in any order; a failure is returned and the next call tries again. The backend found is kept until Close. A BackendLocator is safe for concurrent use.

type BackendLocator struct {
    // contains filtered or unexported fields
}

func NewBackendLocator

func NewBackendLocator(disco func() discovery.Discovery, clients client.Factory, clientName, server string) *BackendLocator

NewBackendLocator returns the locator of the backend: disco returns the discovery of the process, or nil; clients dials the listener named server with the client named clientName when the process has no backend. Either may be nil.

func NewStaticBackendLocator

func NewStaticBackendLocator(srv privpb.BackendServer) *BackendLocator

NewStaticBackendLocator returns a locator that always returns srv, for a service wired to its backend explicitly

func (*BackendLocator) Backend

func (l *BackendLocator) Backend() (privpb.BackendServer, error)

Backend returns the backend: the one of the process, called directly with the context of the caller, or a client of the backend listener

func (*BackendLocator) Close

func (l *BackendLocator) Close() error

Close closes the client of a remote backend; the next call of Backend looks the backend up again

Generated by gomarkdoc