| Conditions | 2 |
| Total Lines | 106 |
| Code Lines | 100 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | package cmd |
||
| 49 | func NewServeCommand() *cobra.Command { |
||
| 50 | command := &cobra.Command{ |
||
| 51 | Use: "serve", |
||
| 52 | Short: "serve the Permify server", |
||
| 53 | RunE: serve(), |
||
| 54 | Args: cobra.NoArgs, |
||
| 55 | } |
||
| 56 | |||
| 57 | conf := config.DefaultConfig() |
||
| 58 | f := command.Flags() |
||
| 59 | f.StringP("config", "c", "", "config file (default is $HOME/.permify.yaml)") |
||
| 60 | f.Bool("http-enabled", conf.Server.HTTP.Enabled, "switch option for HTTP server") |
||
| 61 | f.String("account-id", conf.AccountID, "account id") |
||
| 62 | f.Int64("server-rate-limit", conf.Server.RateLimit, "the maximum number of requests the server should handle per second") |
||
| 63 | f.String("server-name-override", conf.Server.NameOverride, "server name override") |
||
| 64 | f.String("grpc-port", conf.Server.GRPC.Port, "port that GRPC server run on") |
||
| 65 | f.Bool("grpc-tls-enabled", conf.Server.GRPC.TLSConfig.Enabled, "switch option for GRPC tls server") |
||
| 66 | f.String("grpc-tls-key-path", conf.Server.GRPC.TLSConfig.KeyPath, "GRPC tls key path") |
||
| 67 | f.String("grpc-tls-cert-path", conf.Server.GRPC.TLSConfig.CertPath, "GRPC tls certificate path") |
||
| 68 | f.String("http-port", conf.Server.HTTP.Port, "HTTP port address") |
||
| 69 | f.Bool("http-tls-enabled", conf.Server.HTTP.TLSConfig.Enabled, "switch option for HTTP tls server") |
||
| 70 | f.String("http-tls-key-path", conf.Server.HTTP.TLSConfig.KeyPath, "HTTP tls key path") |
||
| 71 | f.String("http-tls-cert-path", conf.Server.HTTP.TLSConfig.CertPath, "HTTP tls certificate path") |
||
| 72 | f.StringSlice("http-cors-allowed-origins", conf.Server.HTTP.CORSAllowedOrigins, "CORS allowed origins for http gateway") |
||
| 73 | f.StringSlice("http-cors-allowed-headers", conf.Server.HTTP.CORSAllowedHeaders, "CORS allowed headers for http gateway") |
||
| 74 | f.Bool("profiler-enabled", conf.Profiler.Enabled, "switch option for profiler") |
||
| 75 | f.String("profiler-port", conf.Profiler.Port, "profiler port address") |
||
| 76 | f.String("log-level", conf.Log.Level, "set log verbosity ('info', 'debug', 'error', 'warning')") |
||
| 77 | f.String("log-output", conf.Log.Output, "logger output valid values json, text") |
||
| 78 | f.Bool("log-enabled", conf.Log.Enabled, "logger exporter enabled") // Log exporter toggle |
||
| 79 | f.String("log-exporter", conf.Log.Exporter, "can be; otlp. (integrated metric tools)") |
||
| 80 | f.String("log-endpoint", conf.Log.Endpoint, "export uri for logs") |
||
| 81 | f.Bool("log-insecure", conf.Log.Insecure, "use https or http for logs") |
||
| 82 | f.String("log-urlpath", conf.Log.Urlpath, "allow to set url path for otlp exporter") |
||
| 83 | f.StringSlice("log-headers", conf.Log.Headers, "allows setting custom headers for the log exporter in key-value pairs") |
||
| 84 | f.String("log-protocol", conf.Log.Protocol, "allows setting the communication protocol for the log exporter, with options http or grpc") |
||
| 85 | f.Bool("authn-enabled", conf.Authn.Enabled, "enable server authentication") |
||
| 86 | f.String("authn-method", conf.Authn.Method, "server authentication method") |
||
| 87 | f.StringSlice("authn-preshared-keys", conf.Authn.Preshared.Keys, "preshared key/keys for server authentication") |
||
| 88 | f.String("authn-oidc-issuer", conf.Authn.Oidc.Issuer, "issuer identifier of the OpenID Connect Provider") |
||
| 89 | f.String("authn-oidc-audience", conf.Authn.Oidc.Audience, "intended audience of the OpenID Connect token") |
||
| 90 | f.Duration("authn-oidc-refresh-interval", conf.Authn.Oidc.RefreshInterval, "refresh interval for the OpenID Connect configuration") |
||
| 91 | f.Duration("authn-oidc-backoff-interval", conf.Authn.Oidc.BackoffInterval, "backoff interval for the OpenID Connect configuration") |
||
| 92 | f.Duration("authn-oidc-backoff-frequency", conf.Authn.Oidc.BackoffFrequency, "backoff frequency for the OpenID Connect configuration") |
||
| 93 | f.Int("authn-oidc-backoff-max-retries", conf.Authn.Oidc.BackoffMaxRetries, "defines the maximum number of retries for the OpenID Connect configuration") |
||
| 94 | f.StringSlice("authn-oidc-valid-methods", conf.Authn.Oidc.ValidMethods, "list of valid JWT signing methods for OpenID Connect") |
||
| 95 | f.Bool("tracer-enabled", conf.Tracer.Enabled, "switch option for tracing") |
||
| 96 | f.String("tracer-exporter", conf.Tracer.Exporter, "can be; jaeger, signoz, zipkin or otlp. (integrated tracing tools)") |
||
| 97 | f.String("tracer-endpoint", conf.Tracer.Endpoint, "export uri for tracing data") |
||
| 98 | f.Bool("tracer-insecure", conf.Tracer.Insecure, "use https or http for tracer data, only used for otlp exporter or signoz") |
||
| 99 | f.String("tracer-urlpath", conf.Tracer.Urlpath, "allow to set url path for otlp exporter") |
||
| 100 | f.StringSlice("tracer-headers", conf.Tracer.Headers, "allows setting custom headers for the tracer exporter in key-value pairs") |
||
| 101 | f.String("tracer-protocol", conf.Tracer.Protocol, "allows setting the communication protocol for the tracer exporter, with options http or grpc") |
||
| 102 | f.Bool("meter-enabled", conf.Meter.Enabled, "switch option for metric") |
||
| 103 | f.String("meter-exporter", conf.Meter.Exporter, "can be; otlp. (integrated metric tools)") |
||
| 104 | f.String("meter-endpoint", conf.Meter.Endpoint, "export uri for metric data") |
||
| 105 | f.Bool("meter-insecure", conf.Meter.Insecure, "use https or http for metric data") |
||
| 106 | f.String("meter-urlpath", conf.Meter.Urlpath, "allow to set url path for otlp exporter") |
||
| 107 | f.StringSlice("meter-headers", conf.Meter.Headers, "allows setting custom headers for the metric exporter in key-value pairs") |
||
| 108 | f.Int("meter-interval", conf.Meter.Interval, "allows to set metrics to be pushed in certain time interval") |
||
| 109 | f.String("meter-protocol", conf.Meter.Protocol, "allows setting the communication protocol for the meter exporter, with options http or grpc") |
||
| 110 | f.Bool("service-circuit-breaker", conf.Service.CircuitBreaker, "switch option for service circuit breaker") |
||
| 111 | f.Bool("service-watch-enabled", conf.Service.Watch.Enabled, "switch option for watch service") |
||
| 112 | f.Int64("service-schema-cache-number-of-counters", conf.Service.Schema.Cache.NumberOfCounters, "schema service cache number of counters") |
||
| 113 | f.String("service-schema-cache-max-cost", conf.Service.Schema.Cache.MaxCost, "schema service cache max cost") |
||
| 114 | f.Int("service-permission-bulk-limit", conf.Service.Permission.BulkLimit, "bulk operations limit") |
||
| 115 | f.Int("service-permission-concurrency-limit", conf.Service.Permission.ConcurrencyLimit, "concurrency limit") |
||
| 116 | f.Int64("service-permission-cache-number-of-counters", conf.Service.Permission.Cache.NumberOfCounters, "permission service cache number of counters") |
||
| 117 | f.String("service-permission-cache-max-cost", conf.Service.Permission.Cache.MaxCost, "permission service cache max cost") |
||
| 118 | f.String("database-engine", conf.Database.Engine, "data source. e.g. postgres, memory") |
||
| 119 | f.String("database-uri", conf.Database.URI, "uri of your data source to store relation tuples and schema") |
||
| 120 | f.String("database-writer-uri", conf.Database.Writer.URI, "writer uri of your data source to store relation tuples and schema") |
||
| 121 | f.String("database-reader-uri", conf.Database.Reader.URI, "reader uri of your data source to store relation tuples and schema") |
||
| 122 | f.Bool("database-auto-migrate", conf.Database.AutoMigrate, "auto migrate database tables") |
||
| 123 | f.Int("database-max-connections", conf.Database.MaxConnections, "maximum number of connections in the pool") |
||
| 124 | f.Int("database-max-open-connections", conf.Database.MaxOpenConnections, "deprecated: use database-max-connections instead. maximum number of parallel connections that can be made to the database at any time") |
||
| 125 | f.Int("database-max-idle-connections", conf.Database.MaxIdleConnections, "deprecated: use database-min-connections instead. maximum number of idle connections that can be made to the database at any time") |
||
| 126 | f.Int("database-min-connections", conf.Database.MinConnections, "minimum number of connections in the pool") |
||
| 127 | f.Int("database-min-idle-connections", conf.Database.MinIdleConnections, "minimum number of idle connections in the pool") |
||
| 128 | f.Duration("database-max-connection-lifetime", conf.Database.MaxConnectionLifetime, "maximum amount of time a connection may be reused") |
||
| 129 | f.Duration("database-max-connection-idle-time", conf.Database.MaxConnectionIdleTime, "maximum amount of time a connection may be idle") |
||
| 130 | f.Duration("database-health-check-period", conf.Database.HealthCheckPeriod, "period between health checks on idle connections") |
||
| 131 | f.Duration("database-max-connection-lifetime-jitter", conf.Database.MaxConnectionLifetimeJitter, "jitter added to max_connection_lifetime to prevent all connections from expiring at once") |
||
| 132 | f.Duration("database-connect-timeout", conf.Database.ConnectTimeout, "maximum time to wait when establishing a new connection") |
||
| 133 | f.Int("database-max-data-per-write", conf.Database.MaxDataPerWrite, "sets the maximum amount of data per write operation to the database") |
||
| 134 | f.Int("database-max-retries", conf.Database.MaxRetries, "defines the maximum number of retries for database operations in case of failure") |
||
| 135 | f.Int("database-watch-buffer-size", conf.Database.WatchBufferSize, "specifies the buffer size for database watch operations, impacting how many changes can be queued") |
||
| 136 | f.Bool("database-garbage-collection-enabled", conf.Database.GarbageCollection.Enabled, "use database garbage collection for expired relationships and attributes") |
||
| 137 | f.Duration("database-garbage-collection-interval", conf.Database.GarbageCollection.Interval, "interval for database garbage collection") |
||
| 138 | f.Duration("database-garbage-collection-timeout", conf.Database.GarbageCollection.Timeout, "timeout for database garbage collection") |
||
| 139 | f.Duration("database-garbage-collection-window", conf.Database.GarbageCollection.Window, "window for database garbage collection") |
||
| 140 | f.Bool("distributed-enabled", conf.Distributed.Enabled, "enable distributed") |
||
| 141 | f.String("distributed-address", conf.Distributed.Address, "distributed address") |
||
| 142 | f.String("distributed-port", conf.Distributed.Port, "distributed port") |
||
| 143 | f.Int("distributed-partition-count", conf.Distributed.PartitionCount, "number of partitions for distributed hashing") |
||
| 144 | f.Int("distributed-replication-factor", conf.Distributed.ReplicationFactor, "number of replicas for distributed hashing") |
||
| 145 | f.Float64("distributed-load", conf.Distributed.Load, "load factor for distributed hashing") |
||
| 146 | f.Int("distributed-picker-width", conf.Distributed.PickerWidth, "picker width for distributed hashing") |
||
| 147 | // Silence usage on error |
||
| 148 | command.SilenceUsage = true // Suppress usage on errors |
||
| 149 | // Register flags |
||
| 150 | command.PreRun = func(cmd *cobra.Command, args []string) { |
||
| 151 | flags.RegisterServeFlags(f) |
||
| 152 | } |
||
| 153 | |||
| 154 | return command |
||
| 155 | } |
||
| 576 |