server

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: Apache-2.0 Imports: 64 Imported by: 3

Documentation

Overview

Code generated by github.com/ecordell/optgen. DO NOT EDIT.

Index

Constants

View Source
const (
	DefaultMiddlewareRequestID = "requestid"
	DefaultMiddlewareLog       = "log"
	DefaultMiddlewareGRPCLog   = "grpclog"
	DefaultMiddlewareOTelGRPC  = "otelgrpc"
	DefaultMiddlewareGRPCAuth  = "grpcauth"
	DefaultMiddlewareGRPCProm  = "grpcprom"

	DefaultInternalMiddlewareDispatch       = "dispatch"
	DefaultInternalMiddlewareDatastore      = "datastore"
	DefaultInternalMiddlewareConsistency    = "consistency"
	DefaultInternalMiddlewareServerSpecific = "servicespecific"
	DefaultInternalMiddlewareServerVersion  = "serverversion"
)

Variables

View Source
var DisableTelemetryHandler *prometheus.Registry

Functions

func DefaultDispatchMiddleware

func DefaultDispatchMiddleware(logger zerolog.Logger, authFunc grpcauth.AuthFunc, ds datastore.Datastore) ([]grpc.UnaryServerInterceptor, []grpc.StreamServerInterceptor)

DefaultDispatchMiddleware generates the default middleware chain used for the internal dispatch SpiceDB gRPC API

func DefaultPreRunE

func DefaultPreRunE(programName string) cobrautil.CobraRunFunc

DefaultPreRunE sets up viper, zerolog, and OpenTelemetry flag handling for a command.

func MetricsHandler

func MetricsHandler(telemetryRegistry *prometheus.Registry) http.Handler

MetricsHandler sets up an HTTP server that handles serving Prometheus metrics and pprof endpoints.

func RegisterCacheFlags added in v1.13.0

func RegisterCacheFlags(flags *pflag.FlagSet, flagPrefix string, config, defaults *CacheConfig)

RegisterCacheFlags registers flags used to configure SpiceDB's various caches.

func ServeExample

func ServeExample(programName string) string

ServeExample creates an example usage string with the provided program name.

Types

type CacheConfig

type CacheConfig struct {
	Name        string
	MaxCost     string
	NumCounters int64
	Metrics     bool
	Enabled     bool
	// contains filtered or unexported fields
}

CacheConfig defines the configuration various SpiceDB caches.

func (*CacheConfig) Complete

func (cc *CacheConfig) Complete() (cache.Cache, error)

Complete translates the CLI cache config into a cache config.

func (*CacheConfig) WithQuantization added in v1.16.2

func (cc *CacheConfig) WithQuantization(window time.Duration) *CacheConfig

WithQuantization configures a cache such that all entries are given a TTL that will expire safely outside of the quantization window.

type Config

type Config struct {
	// API config
	GRPCServer                        util.GRPCServerConfig
	GRPCAuthFunc                      grpc_auth.AuthFunc
	DispatchHashringReplicationFactor uint16
	PresharedKey                      []string
	ShutdownGracePeriod               time.Duration
	DisableVersionResponse            bool

	// GRPC Gateway config
	HTTPGateway                    util.HTTPServerConfig
	HTTPGatewayUpstreamAddr        string
	HTTPGatewayUpstreamTLSCertPath string
	HTTPGatewayCorsEnabled         bool
	HTTPGatewayCorsAllowedOrigins  []string

	// Datastore
	DatastoreConfig datastorecfg.Config
	Datastore       datastore.Datastore

	// Namespace cache
	NamespaceCacheConfig CacheConfig

	// Schema options
	SchemaPrefixesRequired bool

	// Dispatch options
	DispatchServer                 util.GRPCServerConfig
	DispatchMaxDepth               uint32
	GlobalDispatchConcurrencyLimit uint16
	DispatchConcurrencyLimits      graph.ConcurrencyLimits
	DispatchUpstreamAddr           string
	DispatchUpstreamCAPath         string
	DispatchUpstreamTimeout        time.Duration
	DispatchClientMetricsEnabled   bool
	DispatchClientMetricsPrefix    string
	DispatchClusterMetricsEnabled  bool
	DispatchClusterMetricsPrefix   string
	Dispatcher                     dispatch.Dispatcher

	DispatchCacheConfig        CacheConfig
	ClusterDispatchCacheConfig CacheConfig

	// API Behavior
	DisableV1SchemaAPI       bool
	V1SchemaAdditiveOnly     bool
	MaximumUpdatesPerWrite   uint16
	MaximumPreconditionCount uint16
	MaxCaveatContextSize     int

	// Additional Services
	DashboardAPI util.HTTPServerConfig
	MetricsAPI   util.HTTPServerConfig

	// Middleware for grpc API
	MiddlewareModification []MiddlewareModification

	// Middleware for internal dispatch API
	DispatchUnaryMiddleware     []grpc.UnaryServerInterceptor
	DispatchStreamingMiddleware []grpc.StreamServerInterceptor

	// Telemetry
	SilentlyDisableTelemetry bool
	TelemetryCAOverridePath  string
	TelemetryEndpoint        string
	TelemetryInterval        time.Duration
}

func ConfigWithOptions

func ConfigWithOptions(c *Config, opts ...ConfigOption) *Config

ConfigWithOptions configures an existing Config with the passed in options set

func NewConfigWithOptions

func NewConfigWithOptions(opts ...ConfigOption) *Config

NewConfigWithOptions creates a new Config with the passed in options set

func (*Config) Complete

func (c *Config) Complete(ctx context.Context) (RunnableServer, error)

Complete validates the config and fills out defaults. if there is no error, a completedServerConfig (with limited options for mutation) is returned.

func (*Config) ToOption

func (c *Config) ToOption() ConfigOption

ToOption returns a new ConfigOption that sets the values from the passed in Config

type ConfigOption

type ConfigOption func(c *Config)

func SetDispatchStreamingMiddleware

func SetDispatchStreamingMiddleware(dispatchStreamingMiddleware []grpc.StreamServerInterceptor) ConfigOption

SetDispatchStreamingMiddleware returns an option that can set DispatchStreamingMiddleware on a Config

func SetDispatchUnaryMiddleware

func SetDispatchUnaryMiddleware(dispatchUnaryMiddleware []grpc.UnaryServerInterceptor) ConfigOption

SetDispatchUnaryMiddleware returns an option that can set DispatchUnaryMiddleware on a Config

func SetHTTPGatewayCorsAllowedOrigins

func SetHTTPGatewayCorsAllowedOrigins(hTTPGatewayCorsAllowedOrigins []string) ConfigOption

SetHTTPGatewayCorsAllowedOrigins returns an option that can set HTTPGatewayCorsAllowedOrigins on a Config

func SetMiddlewareModification added in v1.16.0

func SetMiddlewareModification(middlewareModification []MiddlewareModification) ConfigOption

SetMiddlewareModification returns an option that can set MiddlewareModification on a Config

func SetPresharedKey added in v1.7.0

func SetPresharedKey(presharedKey []string) ConfigOption

SetPresharedKey returns an option that can set PresharedKey on a Config

func WithClusterDispatchCacheConfig

func WithClusterDispatchCacheConfig(clusterDispatchCacheConfig CacheConfig) ConfigOption

WithClusterDispatchCacheConfig returns an option that can set ClusterDispatchCacheConfig on a Config

func WithDashboardAPI

func WithDashboardAPI(dashboardAPI util.HTTPServerConfig) ConfigOption

WithDashboardAPI returns an option that can set DashboardAPI on a Config

func WithDatastore

func WithDatastore(datastore datastore1.Datastore) ConfigOption

WithDatastore returns an option that can set Datastore on a Config

func WithDatastoreConfig

func WithDatastoreConfig(datastoreConfig datastore.Config) ConfigOption

WithDatastoreConfig returns an option that can set DatastoreConfig on a Config

func WithDisableV1SchemaAPI

func WithDisableV1SchemaAPI(disableV1SchemaAPI bool) ConfigOption

WithDisableV1SchemaAPI returns an option that can set DisableV1SchemaAPI on a Config

func WithDisableVersionResponse added in v1.8.0

func WithDisableVersionResponse(disableVersionResponse bool) ConfigOption

WithDisableVersionResponse returns an option that can set DisableVersionResponse on a Config

func WithDispatchCacheConfig

func WithDispatchCacheConfig(dispatchCacheConfig CacheConfig) ConfigOption

WithDispatchCacheConfig returns an option that can set DispatchCacheConfig on a Config

func WithDispatchClientMetricsEnabled added in v1.17.0

func WithDispatchClientMetricsEnabled(dispatchClientMetricsEnabled bool) ConfigOption

WithDispatchClientMetricsEnabled returns an option that can set DispatchClientMetricsEnabled on a Config

func WithDispatchClientMetricsPrefix

func WithDispatchClientMetricsPrefix(dispatchClientMetricsPrefix string) ConfigOption

WithDispatchClientMetricsPrefix returns an option that can set DispatchClientMetricsPrefix on a Config

func WithDispatchClusterMetricsEnabled added in v1.17.0

func WithDispatchClusterMetricsEnabled(dispatchClusterMetricsEnabled bool) ConfigOption

WithDispatchClusterMetricsEnabled returns an option that can set DispatchClusterMetricsEnabled on a Config

func WithDispatchClusterMetricsPrefix added in v1.6.0

func WithDispatchClusterMetricsPrefix(dispatchClusterMetricsPrefix string) ConfigOption

WithDispatchClusterMetricsPrefix returns an option that can set DispatchClusterMetricsPrefix on a Config

func WithDispatchConcurrencyLimits added in v1.16.0

func WithDispatchConcurrencyLimits(dispatchConcurrencyLimits graph.ConcurrencyLimits) ConfigOption

WithDispatchConcurrencyLimits returns an option that can set DispatchConcurrencyLimits on a Config

func WithDispatchHashringReplicationFactor added in v1.18.1

func WithDispatchHashringReplicationFactor(dispatchHashringReplicationFactor uint16) ConfigOption

WithDispatchHashringReplicationFactor returns an option that can set DispatchHashringReplicationFactor on a Config

func WithDispatchMaxDepth

func WithDispatchMaxDepth(dispatchMaxDepth uint32) ConfigOption

WithDispatchMaxDepth returns an option that can set DispatchMaxDepth on a Config

func WithDispatchServer

func WithDispatchServer(dispatchServer util.GRPCServerConfig) ConfigOption

WithDispatchServer returns an option that can set DispatchServer on a Config

func WithDispatchStreamingMiddleware

func WithDispatchStreamingMiddleware(dispatchStreamingMiddleware grpc.StreamServerInterceptor) ConfigOption

WithDispatchStreamingMiddleware returns an option that can append DispatchStreamingMiddlewares to Config.DispatchStreamingMiddleware

func WithDispatchUnaryMiddleware

func WithDispatchUnaryMiddleware(dispatchUnaryMiddleware grpc.UnaryServerInterceptor) ConfigOption

WithDispatchUnaryMiddleware returns an option that can append DispatchUnaryMiddlewares to Config.DispatchUnaryMiddleware

func WithDispatchUpstreamAddr

func WithDispatchUpstreamAddr(dispatchUpstreamAddr string) ConfigOption

WithDispatchUpstreamAddr returns an option that can set DispatchUpstreamAddr on a Config

func WithDispatchUpstreamCAPath

func WithDispatchUpstreamCAPath(dispatchUpstreamCAPath string) ConfigOption

WithDispatchUpstreamCAPath returns an option that can set DispatchUpstreamCAPath on a Config

func WithDispatchUpstreamTimeout added in v1.16.2

func WithDispatchUpstreamTimeout(dispatchUpstreamTimeout time.Duration) ConfigOption

WithDispatchUpstreamTimeout returns an option that can set DispatchUpstreamTimeout on a Config

func WithDispatcher

func WithDispatcher(dispatcher dispatch.Dispatcher) ConfigOption

WithDispatcher returns an option that can set Dispatcher on a Config

func WithGRPCAuthFunc

func WithGRPCAuthFunc(gRPCAuthFunc auth.AuthFunc) ConfigOption

WithGRPCAuthFunc returns an option that can set GRPCAuthFunc on a Config

func WithGRPCServer

func WithGRPCServer(gRPCServer util.GRPCServerConfig) ConfigOption

WithGRPCServer returns an option that can set GRPCServer on a Config

func WithGlobalDispatchConcurrencyLimit added in v1.16.0

func WithGlobalDispatchConcurrencyLimit(globalDispatchConcurrencyLimit uint16) ConfigOption

WithGlobalDispatchConcurrencyLimit returns an option that can set GlobalDispatchConcurrencyLimit on a Config

func WithHTTPGateway

func WithHTTPGateway(hTTPGateway util.HTTPServerConfig) ConfigOption

WithHTTPGateway returns an option that can set HTTPGateway on a Config

func WithHTTPGatewayCorsAllowedOrigins

func WithHTTPGatewayCorsAllowedOrigins(hTTPGatewayCorsAllowedOrigins string) ConfigOption

WithHTTPGatewayCorsAllowedOrigins returns an option that can append HTTPGatewayCorsAllowedOriginss to Config.HTTPGatewayCorsAllowedOrigins

func WithHTTPGatewayCorsEnabled

func WithHTTPGatewayCorsEnabled(hTTPGatewayCorsEnabled bool) ConfigOption

WithHTTPGatewayCorsEnabled returns an option that can set HTTPGatewayCorsEnabled on a Config

func WithHTTPGatewayUpstreamAddr

func WithHTTPGatewayUpstreamAddr(hTTPGatewayUpstreamAddr string) ConfigOption

WithHTTPGatewayUpstreamAddr returns an option that can set HTTPGatewayUpstreamAddr on a Config

func WithHTTPGatewayUpstreamTLSCertPath

func WithHTTPGatewayUpstreamTLSCertPath(hTTPGatewayUpstreamTLSCertPath string) ConfigOption

WithHTTPGatewayUpstreamTLSCertPath returns an option that can set HTTPGatewayUpstreamTLSCertPath on a Config

func WithMaxCaveatContextSize added in v1.18.0

func WithMaxCaveatContextSize(maxCaveatContextSize int) ConfigOption

WithMaxCaveatContextSize returns an option that can set MaxCaveatContextSize on a Config

func WithMaximumPreconditionCount added in v1.12.0

func WithMaximumPreconditionCount(maximumPreconditionCount uint16) ConfigOption

WithMaximumPreconditionCount returns an option that can set MaximumPreconditionCount on a Config

func WithMaximumUpdatesPerWrite added in v1.12.0

func WithMaximumUpdatesPerWrite(maximumUpdatesPerWrite uint16) ConfigOption

WithMaximumUpdatesPerWrite returns an option that can set MaximumUpdatesPerWrite on a Config

func WithMetricsAPI

func WithMetricsAPI(metricsAPI util.HTTPServerConfig) ConfigOption

WithMetricsAPI returns an option that can set MetricsAPI on a Config

func WithMiddlewareModification added in v1.16.0

func WithMiddlewareModification(middlewareModification MiddlewareModification) ConfigOption

WithMiddlewareModification returns an option that can append MiddlewareModifications to Config.MiddlewareModification

func WithNamespaceCacheConfig

func WithNamespaceCacheConfig(namespaceCacheConfig CacheConfig) ConfigOption

WithNamespaceCacheConfig returns an option that can set NamespaceCacheConfig on a Config

func WithPresharedKey

func WithPresharedKey(presharedKey string) ConfigOption

WithPresharedKey returns an option that can append PresharedKeys to Config.PresharedKey

func WithSchemaPrefixesRequired

func WithSchemaPrefixesRequired(schemaPrefixesRequired bool) ConfigOption

WithSchemaPrefixesRequired returns an option that can set SchemaPrefixesRequired on a Config

func WithShutdownGracePeriod

func WithShutdownGracePeriod(shutdownGracePeriod time.Duration) ConfigOption

WithShutdownGracePeriod returns an option that can set ShutdownGracePeriod on a Config

func WithSilentlyDisableTelemetry added in v1.7.0

func WithSilentlyDisableTelemetry(silentlyDisableTelemetry bool) ConfigOption

WithSilentlyDisableTelemetry returns an option that can set SilentlyDisableTelemetry on a Config

func WithTelemetryCAOverridePath added in v1.7.0

func WithTelemetryCAOverridePath(telemetryCAOverridePath string) ConfigOption

WithTelemetryCAOverridePath returns an option that can set TelemetryCAOverridePath on a Config

func WithTelemetryEndpoint added in v1.7.0

func WithTelemetryEndpoint(telemetryEndpoint string) ConfigOption

WithTelemetryEndpoint returns an option that can set TelemetryEndpoint on a Config

func WithTelemetryInterval added in v1.7.0

func WithTelemetryInterval(telemetryInterval time.Duration) ConfigOption

WithTelemetryInterval returns an option that can set TelemetryInterval on a Config

func WithV1SchemaAdditiveOnly added in v1.15.0

func WithV1SchemaAdditiveOnly(v1SchemaAdditiveOnly bool) ConfigOption

WithV1SchemaAdditiveOnly returns an option that can set V1SchemaAdditiveOnly on a Config

type MiddlewareChain added in v1.16.0

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

MiddlewareChain describes an ordered sequence of middlewares that can be modified with one or more MiddlewareModification. This struct is used to facilitate the creation and modification of gRPC middleware chains

func DefaultMiddleware

func DefaultMiddleware(logger zerolog.Logger, authFunc grpcauth.AuthFunc, enableVersionResponse bool, dispatcher dispatch.Dispatcher, ds datastore.Datastore) (*MiddlewareChain, error)

DefaultMiddleware generates the default middleware chain used for the public SpiceDB gRPC API

func NewMiddlewareChain added in v1.16.0

func NewMiddlewareChain(mw ...ReferenceableMiddleware) (MiddlewareChain, error)

NewMiddlewareChain creates a new middleware chain given zero or more named middlewares. An error will be returned in case validation of the NamedMiddlewares fail.

func (*MiddlewareChain) Names added in v1.16.0

func (mc *MiddlewareChain) Names() *util.Set[string]

Names returns the names of the middlewares in a chain

func (*MiddlewareChain) ToGRPCInterceptors added in v1.16.0

ToGRPCInterceptors generates slices of gRPC interceptors ready to be installed in a server

type MiddlewareModification added in v1.16.0

type MiddlewareModification struct {
	// DependencyMiddlewareName is used to define with respect to which middleware an operation is performed.
	// Dependency is not required for ReplaceAll operation
	DependencyMiddlewareName string

	// Operation describes the type of operation to be performed
	Operation MiddlewareOperation

	// Middlewares are the named middlewares that will be part of this modification
	Middlewares []ReferenceableMiddleware
}

MiddlewareModification describes an operation to modify a MiddlewareChain

type MiddlewareOperation added in v1.16.0

type MiddlewareOperation int

MiddlewareOperation describes the type of operation that will be performed in a MiddlewareModification

const (
	// OperationPrepend adds the middlewares right before the referenced dependency
	OperationPrepend MiddlewareOperation = iota

	// OperationReplace substitutes the referenced dependency with the middlewares of a modification.
	// If replaced with an empty modification, this acts like a deletion
	OperationReplace

	// OperationAppend adds the middlewares right after the referenced dependency
	OperationAppend

	// OperationReplaceAllUnsafe replaces all middlewares in a chain with those in the modification
	// this operation is only meant to be used in tests.
	OperationReplaceAllUnsafe
)

type ReferenceableMiddleware added in v1.16.0

type ReferenceableMiddleware struct {
	Name                string
	Internal            bool
	UnaryMiddleware     grpc.UnaryServerInterceptor
	StreamingMiddleware grpc.StreamServerInterceptor
}

ReferenceableMiddleware represents a middleware in a MiddlewareChain. Middlewares can be referenced by name in MiddlewareModification, for example "append after middleware abc". Internal middlewares can also be referenced for operations like append or prepend, but cannot be referenced for replace operations. Middlewares must always be named.

type RunnableServer

type RunnableServer interface {
	Run(ctx context.Context) error
	GRPCDialContext(ctx context.Context, opts ...grpc.DialOption) (*grpc.ClientConn, error)
	DispatchNetDialContext(ctx context.Context, s string) (net.Conn, error)
}

RunnableServer is a spicedb service set ready to run

Jump to

Keyboard shortcuts

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