serviceregistry

package
v0.11.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2025 License: BSD-3-Clause-Clear Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBRegister added in v0.3.0

type DBRegister struct {
	// Required is a flag that indicates whether the service requires a database connection.
	Required bool
	// Migrations is an embedded filesystem that contains the Goose SQL migrations for the service.
	// This is required to support the `migrate` command or the `runMigrations` configuration option.
	// More information on Goose can be found at https://github.com/pressly/goose
	Migrations *embed.FS
}

DBRegister is a struct that holds the information needed to register a service with a database

type HandlerServer

type HandlerServer func(ctx context.Context, mux *runtime.ServeMux) error

type IService added in v0.4.27

type IService interface {
	IsDBRequired() bool
	DBMigrations() *embed.FS
	GetNamespace() string
	GetVersion() string
	GetServiceDesc() *grpc.ServiceDesc
	Start(ctx context.Context, params RegistrationParams) error
	IsStarted() bool
	Shutdown() error
	RegisterConfigUpdateHook(ctx context.Context, hookAppender func(config.ChangeHook)) error
	RegisterConnectRPCServiceHandler(context.Context, *server.ConnectRPC) error
	RegisterGRPCGatewayHandler(context.Context, *runtime.ServeMux, *grpc.ClientConn) error
	RegisterHTTPHandlers(context.Context, *runtime.ServeMux) error
}

type ModeName added in v0.10.0

type ModeName string

ModeName represents a typed mode identifier

const (
	ModeALL       ModeName = "all"
	ModeCore      ModeName = "core"
	ModeKAS       ModeName = "kas"
	ModeERS       ModeName = "entityresolution"
	ModeEssential ModeName = "essential"
)

func ParseModesWithNegation added in v0.10.0

func ParseModesWithNegation(modes []string) ([]ModeName, []string, error)

ParseModesWithNegation parses mode strings and separates included and excluded services

func (ModeName) String added in v0.10.0

func (m ModeName) String() string

String returns the string representation of ModeName

type Namespace added in v0.4.18

type Namespace struct {
	Mode     string
	Version  string
	Services []IService
}

namespace represents a namespace in the service registry.

func (Namespace) IsEnabled added in v0.10.0

func (n Namespace) IsEnabled(configuredModes []string) bool

IsEnabled checks if this namespace should be enabled based on configured modes. Returns true if any of the configured modes match this namespace's mode, or if "all" mode is configured, or if this namespace is "essential".

type NamespaceInfo added in v0.10.0

type NamespaceInfo struct {
	Name      string
	Namespace *Namespace
}

type OnConfigUpdateHook added in v0.5.3

type OnConfigUpdateHook func(context.Context, config.ServiceConfig) error

Allow services to implement handling for config changes as direced by caller

type RegisterFunc

type RegisterFunc[S any] func(RegistrationParams) (impl S, HandlerServer HandlerServer)

type RegistrationParams

type RegistrationParams struct {
	// Config scoped to the service config. Since the main config contains all the service configs,
	// which could have need-to-know information we don't want to expose it to all services.
	Config config.ServiceConfig
	// Security exposes platform-wide security overrides.
	Security *config.SecurityConfig
	// OTDF is the OpenTDF server that can be used to interact with the OpenTDFServer instance.
	OTDF *server.OpenTDFServer
	// DBClient is the database client that can be used to interact with the database. This client
	// is scoped to the service namespace and will not be shared with other service namespaces.
	DBClient *db.Client
	// SDK is the OpenTDF SDK that can be used to interact with the OpenTDF SDK. This is useful for
	// gRPC Inter Process Communication (IPC) between services. This ensures the services are
	// communicating with each other by contract as well as supporting the various deployment models
	// that OpenTDF supports.
	SDK *sdk.SDK
	// Logger is the logger that can be used to log messages. This logger is scoped to the service
	Logger *logger.Logger
	trace.Tracer

	// NewCacheClient is a function that can be used to create a new cache instance for the service
	NewCacheClient func(cache.Options) (*cache.Cache, error)

	// KeyManagerFactories are the registered key manager factories that can be used to create
	// key managers for the service to use.
	// Prefer KeyManagerCtxFactories
	// EXPERIMENTAL
	KeyManagerFactories []trust.NamedKeyManagerFactory

	// KeyManagerCtxFactories are the registered key manager context factories that can be used to create
	// key managers for the service to use.
	// EXPERIMENTAL
	KeyManagerCtxFactories []trust.NamedKeyManagerCtxFactory

	// RegisterWellKnownConfig is a function that can be used to register a well-known configuration
	WellKnownConfig func(namespace string, config any) error
	// RegisterReadinessCheck is a function that can be used to register a readiness check for the
	// service. This is useful for services that need to perform some initialization before they are
	// ready to serve requests. This function should be called in the RegisterFunc function.
	RegisterReadinessCheck func(namespace string, check func(context.Context) error) error
}

RegistrationParams is a struct that holds the parameters needed to register a service with the service registry. These parameters are passed to the RegisterFunc function defined in the Registration struct.

type Registry added in v0.4.18

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

Registry represents a service registry with namespaces and their registration order.

func NewServiceRegistry added in v0.4.18

func NewServiceRegistry() *Registry

NewServiceRegistry creates a new instance of the service registry.

func (*Registry) GetNamespace added in v0.4.18

func (reg *Registry) GetNamespace(namespace string) (*Namespace, error)

GetNamespace returns the namespace with the given name from the service registry.

func (*Registry) GetNamespaces added in v0.10.0

func (reg *Registry) GetNamespaces() []NamespaceInfo

GetNamespaces returns all namespaces in the registry

func (*Registry) RegisterService added in v0.4.18

func (reg *Registry) RegisterService(svc IService, mode ModeName) error

RegisterService registers a service in the service registry. It takes an serviceregistry.IService and a mode string as parameters. The IService implementation contains information about the service to be registered, such as the namespace and service description. The mode string specifies the mode in which the service should be registered. It returns an error if the service is already registered in the specified namespace.

func (*Registry) RegisterServicesFromConfiguration added in v0.10.0

func (reg *Registry) RegisterServicesFromConfiguration(modes []string, configurations []ServiceConfiguration) ([]string, error)

RegisterServicesFromConfiguration handles service registration using declarative configuration with negation support.

func (*Registry) Shutdown added in v0.4.18

func (reg *Registry) Shutdown()

Shutdown stops all the registered services in the reverse order of registration. If a service is started and has a Close method, the Close method will be called.

type Service

type Service[S any] struct {

	// Started is a flag that indicates whether the service has been started
	Started bool
	// Close is a function that can be called to close the service
	Close func()
	// Service Options
	ServiceOptions[S]
	// contains filtered or unexported fields
}

Service is a struct that holds the registration information for a service as well as the state of the service within the instance of the platform.

func (Service[S]) DBMigrations added in v0.4.27

func (s Service[S]) DBMigrations() *embed.FS

func (Service[S]) GetNamespace added in v0.4.27

func (s Service[S]) GetNamespace() string

func (Service[S]) GetServiceDesc added in v0.4.27

func (s Service[S]) GetServiceDesc() *grpc.ServiceDesc

func (Service[S]) GetVersion added in v0.5.3

func (s Service[S]) GetVersion() string

func (Service[S]) IsDBRequired added in v0.4.27

func (s Service[S]) IsDBRequired() bool

func (Service[S]) IsStarted added in v0.4.27

func (s Service[S]) IsStarted() bool

func (Service[S]) RegisterConfigUpdateHook added in v0.5.3

func (s Service[S]) RegisterConfigUpdateHook(ctx context.Context, hookAppender func(config.ChangeHook)) error

RegisterConfigUpdateHook appends a registered service's onConfigUpdateHook to any watching config loaders.

func (Service[S]) RegisterConnectRPCServiceHandler added in v0.4.27

func (s Service[S]) RegisterConnectRPCServiceHandler(_ context.Context, connectRPC *server.ConnectRPC) error

func (Service[S]) RegisterGRPCGatewayHandler deprecated added in v0.4.27

func (s Service[S]) RegisterGRPCGatewayHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

Deprecated: RegisterConnectRPCServiceHandler is deprecated and should not be used going forward. We will be looking onto other alternatives like bufconnect to replace this. RegisterConnectRPCServiceHandler registers an HTTP server with the service. It takes a context, a ServeMux, and an implementation function as parameters. If the service did not register a handler, it returns an error.

func (*Service[S]) RegisterHTTPHandlers deprecated added in v0.4.27

func (s *Service[S]) RegisterHTTPHandlers(ctx context.Context, mux *runtime.ServeMux) error

Deprecated: RegisterHTTPServer is deprecated and should not be used going forward. We will be looking onto other alternatives like bufconnect to replace this. RegisterHTTPServer registers an HTTP server with the service. It takes a context, a ServeMux, and an implementation function as parameters. If the service did not register a handler, it returns an error.

func (Service[S]) Shutdown added in v0.4.27

func (s Service[S]) Shutdown() error

func (*Service[S]) Start added in v0.4.18

func (s *Service[S]) Start(ctx context.Context, params RegistrationParams) error

Start starts the service and performs necessary initialization steps. It returns an error if the service is already started or if there is an issue running database migrations.

type ServiceConfigError added in v0.10.0

type ServiceConfigError struct {
	Type    string
	Mode    string
	Service string
	Message string
}

ServiceConfigError represents errors in service configuration

func (*ServiceConfigError) Error added in v0.10.0

func (e *ServiceConfigError) Error() string

type ServiceConfiguration added in v0.10.0

type ServiceConfiguration struct {
	Name     ServiceName
	Modes    []ModeName
	Services []IService
}

ServiceConfiguration represents a service with its associated modes and implementations.

type ServiceName added in v0.10.0

type ServiceName interface {
	String() string
}

type ServiceOptions added in v0.4.27

type ServiceOptions[S any] struct {
	// Namespace is the namespace of the service. One or more gRPC services can be registered under
	// the same namespace.
	Namespace string
	// Version is the major version of the service according to the protocol buffer definition.
	Version string
	// ServiceDesc is the gRPC service descriptor. For non-gRPC services, this can be mocked out,
	// but at minimum, the ServiceName field must be set
	ServiceDesc *grpc.ServiceDesc
	// OnConfigUpdate is a hook to handle in-service actions when config changes
	OnConfigUpdate OnConfigUpdateHook
	// RegisterFunc is the function that will be called to register the service
	RegisterFunc RegisterFunc[S]

	// ConnectRPCServiceHandler is the function that will be called to register the service with the
	ConnectRPCFunc func(S, ...connect.HandlerOption) (string, http.Handler)
	// Deprecated: Registers a gRPC service with the gRPC gateway
	GRPCGatewayFunc func(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error
	// DB is optional and used to register the service with a database
	DB DBRegister
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL