github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/services/server.go (about) 1 package services 2 3 import ( 4 "time" 5 6 v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" 7 "github.com/authzed/grpcutil" 8 "google.golang.org/grpc" 9 healthpb "google.golang.org/grpc/health/grpc_health_v1" 10 "google.golang.org/grpc/reflection" 11 12 "github.com/authzed/spicedb/internal/dispatch" 13 "github.com/authzed/spicedb/internal/services/health" 14 v1svc "github.com/authzed/spicedb/internal/services/v1" 15 ) 16 17 // SchemaServiceOption defines the options for enabling or disabling the V1 Schema service. 18 type SchemaServiceOption int 19 20 // WatchServiceOption defines the options for enabling or disabling the V1 Watch service. 21 type WatchServiceOption int 22 23 // CaveatsOption defines the options for enabling or disabling caveats in the V1 services. 24 type CaveatsOption int 25 26 const ( 27 // V1SchemaServiceDisabled indicates that the V1 schema service is disabled. 28 V1SchemaServiceDisabled SchemaServiceOption = 0 29 30 // V1SchemaServiceEnabled indicates that the V1 schema service is enabled. 31 V1SchemaServiceEnabled SchemaServiceOption = 1 32 33 // V1SchemaServiceAdditiveOnly indicates that the V1 schema service is enabled in additive-only 34 // mode for testing. 35 V1SchemaServiceAdditiveOnly SchemaServiceOption = 2 36 37 // WatchServiceDisabled indicates that the V1 watch service is disabled. 38 WatchServiceDisabled WatchServiceOption = 0 39 40 // WatchServiceEnabled indicates that the V1 watch service is enabled. 41 WatchServiceEnabled WatchServiceOption = 1 42 ) 43 44 const ( 45 // OverallServerHealthCheckKey is used for grpc health check requests for the overall system. 46 OverallServerHealthCheckKey = "" 47 ) 48 49 // RegisterGrpcServices registers all services to be exposed on the GRPC server. 50 func RegisterGrpcServices( 51 srv *grpc.Server, 52 healthManager health.Manager, 53 dispatch dispatch.Dispatcher, 54 schemaServiceOption SchemaServiceOption, 55 watchServiceOption WatchServiceOption, 56 permSysConfig v1svc.PermissionsServerConfig, 57 watchHeartbeatDuration time.Duration, 58 ) { 59 healthManager.RegisterReportedService(OverallServerHealthCheckKey) 60 61 v1.RegisterPermissionsServiceServer(srv, v1svc.NewPermissionsServer(dispatch, permSysConfig)) 62 v1.RegisterExperimentalServiceServer(srv, v1svc.NewExperimentalServer(dispatch, permSysConfig)) 63 healthManager.RegisterReportedService(v1.PermissionsService_ServiceDesc.ServiceName) 64 65 if watchServiceOption == WatchServiceEnabled { 66 v1.RegisterWatchServiceServer(srv, v1svc.NewWatchServer(watchHeartbeatDuration)) 67 healthManager.RegisterReportedService(v1.WatchService_ServiceDesc.ServiceName) 68 } 69 70 if schemaServiceOption == V1SchemaServiceEnabled || schemaServiceOption == V1SchemaServiceAdditiveOnly { 71 v1.RegisterSchemaServiceServer(srv, v1svc.NewSchemaServer(schemaServiceOption == V1SchemaServiceAdditiveOnly)) 72 healthManager.RegisterReportedService(v1.SchemaService_ServiceDesc.ServiceName) 73 } 74 75 healthpb.RegisterHealthServer(srv, healthManager.HealthSvc()) 76 reflection.Register(grpcutil.NewAuthlessReflectionInterceptor(srv)) 77 }