github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/cmd/testing.go (about) 1 package cmd 2 3 import ( 4 "context" 5 6 "github.com/spf13/cobra" 7 8 "github.com/authzed/spicedb/pkg/cmd/server" 9 "github.com/authzed/spicedb/pkg/cmd/termination" 10 "github.com/authzed/spicedb/pkg/cmd/testserver" 11 "github.com/authzed/spicedb/pkg/cmd/util" 12 ) 13 14 func RegisterTestingFlags(cmd *cobra.Command, config *testserver.Config) { 15 util.RegisterGRPCServerFlags(cmd.Flags(), &config.GRPCServer, "grpc", "gRPC", ":50051", true) 16 util.RegisterGRPCServerFlags(cmd.Flags(), &config.ReadOnlyGRPCServer, "readonly-grpc", "read-only gRPC", ":50052", true) 17 18 util.RegisterHTTPServerFlags(cmd.Flags(), &config.HTTPGateway, "http", "http", ":8443", false) 19 util.RegisterHTTPServerFlags(cmd.Flags(), &config.ReadOnlyHTTPGateway, "readonly-http", "read-only HTTP", ":8444", false) 20 21 cmd.Flags().StringSliceVar(&config.LoadConfigs, "load-configs", []string{}, "configuration yaml files to load") 22 23 // Flags for API behavior 24 cmd.Flags().Uint16Var(&config.MaximumUpdatesPerWrite, "write-relationships-max-updates-per-call", 1000, "maximum number of updates allowed for WriteRelationships calls") 25 cmd.Flags().Uint16Var(&config.MaximumPreconditionCount, "update-relationships-max-preconditions-per-call", 1000, "maximum number of preconditions allowed for WriteRelationships and DeleteRelationships calls") 26 cmd.Flags().IntVar(&config.MaxCaveatContextSize, "max-caveat-context-size", 4096, "maximum allowed size of request caveat context in bytes. A value of zero or less means no limit") 27 cmd.Flags().IntVar(&config.MaxRelationshipContextSize, "max-relationship-context-size", 25000, "maximum allowed size of the context to be stored in a relationship") 28 cmd.Flags().Uint32Var(&config.MaxReadRelationshipsLimit, "max-read-relationships-limit", 1000, "maximum number of relationships that can be read in a single request") 29 cmd.Flags().Uint32Var(&config.MaxDeleteRelationshipsLimit, "max-delete-relationships-limit", 1000, "maximum number of relationships that can be deleted in a single request") 30 cmd.Flags().Uint32Var(&config.MaxLookupResourcesLimit, "max-lookup-resources-limit", 1000, "maximum number of resources that can be looked up in a single request") 31 cmd.Flags().Uint32Var(&config.MaxBulkExportRelationshipsLimit, "max-bulk-export-relationships-limit", 10_000, "maximum number of relationships that can be exported in a single request") 32 } 33 34 func NewTestingCommand(programName string, config *testserver.Config) *cobra.Command { 35 return &cobra.Command{ 36 Use: "serve-testing", 37 Short: "test server with an in-memory datastore", 38 Long: "An in-memory spicedb server which serves completely isolated datastores per client-supplied auth token used.", 39 PreRunE: server.DefaultPreRunE(programName), 40 RunE: termination.PublishError(func(cmd *cobra.Command, args []string) error { 41 signalctx := SignalContextWithGracePeriod( 42 context.Background(), 43 0, 44 ) 45 srv, err := config.Complete() 46 if err != nil { 47 return err 48 } 49 return srv.Run(signalctx) 50 }), 51 } 52 }