From 8563053360b99bbfaf773741087103edb2892757 Mon Sep 17 00:00:00 2001 From: Tolga Ozen Date: Sun, 31 Mar 2024 00:44:37 +0300 Subject: [PATCH 1/2] fix: flag parsing error in command initialization --- pkg/cmd/ast.go | 7 +++- pkg/cmd/config.go | 79 +++++++++++++++++++++++++++++++++++---- pkg/cmd/coverage.go | 9 ++++- pkg/cmd/flags/ast.go | 7 +--- pkg/cmd/flags/coverage.go | 9 +---- pkg/cmd/flags/serve.go | 70 +--------------------------------- pkg/cmd/serve.go | 74 ++++++++++++++++++++++++++++++++++-- 7 files changed, 163 insertions(+), 92 deletions(-) diff --git a/pkg/cmd/ast.go b/pkg/cmd/ast.go index d48b52cab..16f2f76c4 100644 --- a/pkg/cmd/ast.go +++ b/pkg/cmd/ast.go @@ -26,7 +26,12 @@ func NewGenerateASTCommand() *cobra.Command { Args: cobra.ExactArgs(1), } - flags.RegisterAstFlags(command) + f := command.Flags() + f.Bool("pretty", false, "If set to true, produces a human-readable output of the AST.") + + command.PreRun = func(cmd *cobra.Command, args []string) { + flags.RegisterAstFlags(f) + } return command } diff --git a/pkg/cmd/config.go b/pkg/cmd/config.go index 6d8541fff..581a14961 100644 --- a/pkg/cmd/config.go +++ b/pkg/cmd/config.go @@ -5,26 +5,91 @@ import ( "os" "strings" - "github.com/Permify/permify/internal/config" - "github.com/Permify/permify/pkg/cmd/flags" - "github.com/gookit/color" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" "github.com/spf13/viper" + + "github.com/Permify/permify/internal/config" + "github.com/Permify/permify/pkg/cmd/flags" ) func NewConfigCommand() *cobra.Command { - cmd := &cobra.Command{ + command := &cobra.Command{ Use: "config", - Short: "Inspect permify configuration and environment variables", + Short: "inspect permify configuration and environment variables", RunE: conf(), Args: cobra.NoArgs, } - flags.RegisterServeFlags(cmd) + conf := config.DefaultConfig() + f := command.Flags() + f.StringP("config", "c", "", "config file (default is $HOME/.permify.yaml)") + f.Bool("http-enabled", conf.Server.HTTP.Enabled, "switch option for HTTP server") + f.String("account-id", conf.AccountID, "account id") + f.Int64("server-rate-limit", conf.Server.RateLimit, "the maximum number of requests the server should handle per second") + f.String("grpc-port", conf.Server.GRPC.Port, "port that GRPC server run on") + f.Bool("grpc-tls-enabled", conf.Server.GRPC.TLSConfig.Enabled, "switch option for GRPC tls server") + f.String("grpc-tls-key-path", conf.Server.GRPC.TLSConfig.KeyPath, "GRPC tls key path") + f.String("grpc-tls-cert-path", conf.Server.GRPC.TLSConfig.CertPath, "GRPC tls certificate path") + f.String("http-port", conf.Server.HTTP.Port, "HTTP port address") + f.Bool("http-tls-enabled", conf.Server.HTTP.TLSConfig.Enabled, "switch option for HTTP tls server") + f.String("http-tls-key-path", conf.Server.HTTP.TLSConfig.KeyPath, "HTTP tls key path") + f.String("http-tls-cert-path", conf.Server.HTTP.TLSConfig.CertPath, "HTTP tls certificate path") + f.StringSlice("http-cors-allowed-origins", conf.Server.HTTP.CORSAllowedOrigins, "CORS allowed origins for http gateway") + f.StringSlice("http-cors-allowed-headers", conf.Server.HTTP.CORSAllowedHeaders, "CORS allowed headers for http gateway") + f.Bool("profiler-enabled", conf.Profiler.Enabled, "switch option for profiler") + f.String("profiler-port", conf.Profiler.Port, "profiler port address") + f.String("log-level", conf.Log.Level, "real time logs of authorization. Permify uses zerolog as a logger") + f.String("log-output", conf.Log.Output, "logger output valid values json, text") + f.Bool("authn-enabled", conf.Authn.Enabled, "enable server authentication") + f.String("authn-method", conf.Authn.Method, "server authentication method") + f.StringSlice("authn-preshared-keys", conf.Authn.Preshared.Keys, "preshared key/keys for server authentication") + f.String("authn-oidc-issuer", conf.Authn.Oidc.Issuer, "issuer identifier of the OpenID Connect Provider") + f.String("authn-oidc-audience", conf.Authn.Oidc.Audience, "intended audience of the OpenID Connect token") + f.Duration("authn-oidc-refresh-interval", conf.Authn.Oidc.RefreshInterval, "refresh interval for the OpenID Connect configuration") + f.StringSlice("authn-oidc-valid-methods", conf.Authn.Oidc.ValidMethods, "list of valid JWT signing methods for OpenID Connect") + f.Bool("tracer-enabled", conf.Tracer.Enabled, "switch option for tracing") + f.String("tracer-exporter", conf.Tracer.Exporter, "can be; jaeger, signoz, zipkin or otlp. (integrated tracing tools)") + f.String("tracer-endpoint", conf.Tracer.Endpoint, "export uri for tracing data") + f.Bool("tracer-insecure", conf.Tracer.Insecure, "use https or http for tracer data, only used for otlp exporter or signoz") + f.String("tracer-urlpath", conf.Tracer.URLPath, "allow to set url path for otlp exporter") + f.Bool("meter-enabled", conf.Meter.Enabled, "switch option for metric") + f.String("meter-exporter", conf.Meter.Exporter, "can be; otlp. (integrated metric tools)") + f.String("meter-endpoint", conf.Meter.Endpoint, "export uri for metric data") + f.Bool("meter-insecure", conf.Meter.Insecure, "use https or http for metric data") + f.String("meter-urlpath", conf.Meter.URLPath, "allow to set url path for otlp exporter") + f.Bool("service-circuit-breaker", conf.Service.CircuitBreaker, "switch option for service circuit breaker") + f.Bool("service-watch-enabled", conf.Service.Watch.Enabled, "switch option for watch service") + f.Int64("service-schema-cache-number-of-counters", conf.Service.Schema.Cache.NumberOfCounters, "schema service cache number of counters") + f.String("service-schema-cache-max-cost", conf.Service.Schema.Cache.MaxCost, "schema service cache max cost") + f.Int("service-permission-bulk-limit", conf.Service.Permission.BulkLimit, "bulk operations limit") + f.Int("service-permission-concurrency-limit", conf.Service.Permission.ConcurrencyLimit, "concurrency limit") + f.Int64("service-permission-cache-number-of-counters", conf.Service.Permission.Cache.NumberOfCounters, "permission service cache number of counters") + f.String("service-permission-cache-max-cost", conf.Service.Permission.Cache.MaxCost, "permission service cache max cost") + f.String("database-engine", conf.Database.Engine, "data source. e.g. postgres, memory") + f.String("database-uri", conf.Database.URI, "uri of your data source to store relation tuples and schema") + f.Bool("database-auto-migrate", conf.Database.AutoMigrate, "auto migrate database tables") + f.Int("database-max-open-connections", conf.Database.MaxOpenConnections, "maximum number of parallel connections that can be made to the database at any time") + f.Int("database-max-idle-connections", conf.Database.MaxIdleConnections, "maximum number of idle connections that can be made to the database at any time") + f.Duration("database-max-connection-lifetime", conf.Database.MaxConnectionLifetime, "maximum amount of time a connection may be reused") + f.Duration("database-max-connection-idle-time", conf.Database.MaxConnectionIdleTime, "maximum amount of time a connection may be idle") + f.Int("database-max-data-per-write", conf.Database.MaxDataPerWrite, "sets the maximum amount of data per write operation to the database") + f.Int("database-max-retries", conf.Database.MaxRetries, "defines the maximum number of retries for database operations in case of failure") + f.Int("database-watch-buffer-size", conf.Database.WatchBufferSize, "specifies the buffer size for database watch operations, impacting how many changes can be queued") + f.Bool("database-garbage-collection-enabled", conf.Database.GarbageCollection.Enabled, "use database garbage collection for expired relationships and attributes") + f.Duration("database-garbage-collection-interval", conf.Database.GarbageCollection.Interval, "interval for database garbage collection") + f.Duration("database-garbage-collection-timeout", conf.Database.GarbageCollection.Timeout, "timeout for database garbage collection") + f.Duration("database-garbage-collection-window", conf.Database.GarbageCollection.Window, "window for database garbage collection") + f.Bool("distributed-enabled", conf.Distributed.Enabled, "enable distributed") + f.String("distributed-address", conf.Distributed.Address, "distributed address") + f.String("distributed-port", conf.Distributed.Port, "distributed port") + + command.PreRun = func(cmd *cobra.Command, args []string) { + flags.RegisterServeFlags(f) + } - return cmd + return command } func conf() func(cmd *cobra.Command, args []string) error { diff --git a/pkg/cmd/coverage.go b/pkg/cmd/coverage.go index ca6ade469..b6b289da2 100644 --- a/pkg/cmd/coverage.go +++ b/pkg/cmd/coverage.go @@ -24,8 +24,15 @@ func NewCoverageCommand() *cobra.Command { Args: cobra.ExactArgs(1), } + f := command.Flags() + f.Int("coverage-relationships", 0, "the min coverage for relationships") + f.Int("coverage-attributes", 0, "the min coverage for attributes") + f.Int("coverage-assertions", 0, "the min coverage for assertions") + // register flags for coverage - flags.RegisterCoverageFlags(command) + command.PreRun = func(cmd *cobra.Command, args []string) { + flags.RegisterCoverageFlags(f) + } return command } diff --git a/pkg/cmd/flags/ast.go b/pkg/cmd/flags/ast.go index d72b5d476..efaf494b0 100644 --- a/pkg/cmd/flags/ast.go +++ b/pkg/cmd/flags/ast.go @@ -1,15 +1,12 @@ package flags import ( - "github.com/spf13/cobra" + "github.com/spf13/pflag" "github.com/spf13/viper" ) // RegisterAstFlags registers ast flags. -func RegisterAstFlags(cmd *cobra.Command) { - flags := cmd.Flags() - - flags.Bool("pretty", false, "If set to true, produces a human-readable output of the AST.") +func RegisterAstFlags(flags *pflag.FlagSet) { if err := viper.BindPFlag("pretty", flags.Lookup("pretty")); err != nil { panic(err) } diff --git a/pkg/cmd/flags/coverage.go b/pkg/cmd/flags/coverage.go index 5c89d7185..4c2c83e11 100644 --- a/pkg/cmd/flags/coverage.go +++ b/pkg/cmd/flags/coverage.go @@ -1,25 +1,20 @@ package flags import ( - "github.com/spf13/cobra" + "github.com/spf13/pflag" "github.com/spf13/viper" ) // RegisterCoverageFlags registers coverage flags. -func RegisterCoverageFlags(cmd *cobra.Command) { - flags := cmd.Flags() - - flags.Int("coverage-relationships", 0, "the min coverage for relationships") +func RegisterCoverageFlags(flags *pflag.FlagSet) { if err := viper.BindPFlag("coverage-relationships", flags.Lookup("coverage-relationships")); err != nil { panic(err) } - flags.Int("coverage-attributes", 0, "the min coverage for attributes") if err := viper.BindPFlag("coverage-attributes", flags.Lookup("coverage-attributes")); err != nil { panic(err) } - flags.Int("coverage-assertions", 0, "the min coverage for assertions") if err := viper.BindPFlag("coverage-assertions", flags.Lookup("coverage-assertions")); err != nil { panic(err) } diff --git a/pkg/cmd/flags/serve.go b/pkg/cmd/flags/serve.go index d4238986e..1afec3c61 100644 --- a/pkg/cmd/flags/serve.go +++ b/pkg/cmd/flags/serve.go @@ -1,27 +1,19 @@ package flags import ( - "github.com/spf13/cobra" + "github.com/spf13/pflag" "github.com/spf13/viper" - - "github.com/Permify/permify/internal/config" ) // RegisterServeFlags - Define and registers permify CLI flags -func RegisterServeFlags(cmd *cobra.Command) { - conf := config.DefaultConfig() - +func RegisterServeFlags(flags *pflag.FlagSet) { var err error - flags := cmd.Flags() - // Config File - flags.StringP("config", "c", "", "config file (default is $HOME/.permify.yaml)") if err = viper.BindPFlag("config.file", flags.Lookup("config")); err != nil { panic(err) } - flags.String("account-id", conf.AccountID, "account id") if err = viper.BindPFlag("account_id", flags.Lookup("account-id")); err != nil { panic(err) } @@ -30,7 +22,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // Server - flags.Int64("server-rate-limit", conf.Server.RateLimit, "the maximum number of requests the server should handle per second") if err = viper.BindPFlag("server.rate_limit", flags.Lookup("server-rate-limit")); err != nil { panic(err) } @@ -39,7 +30,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // GRPC Server - flags.String("grpc-port", conf.Server.GRPC.Port, "port that GRPC server run on") if err = viper.BindPFlag("server.grpc.port", flags.Lookup("grpc-port")); err != nil { panic(err) } @@ -47,7 +37,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Bool("grpc-tls-enabled", conf.Server.GRPC.TLSConfig.Enabled, "switch option for GRPC tls server") if err = viper.BindPFlag("server.grpc.tls.enabled", flags.Lookup("grpc-tls-enabled")); err != nil { panic(err) } @@ -55,7 +44,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("grpc-tls-key-path", conf.Server.GRPC.TLSConfig.KeyPath, "GRPC tls key path") if err = viper.BindPFlag("server.grpc.tls.key", flags.Lookup("grpc-tls-key-path")); err != nil { panic(err) } @@ -63,7 +51,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("grpc-tls-cert-path", conf.Server.GRPC.TLSConfig.CertPath, "GRPC tls certificate path") if err = viper.BindPFlag("server.grpc.tls.cert", flags.Lookup("grpc-tls-cert-path")); err != nil { panic(err) } @@ -72,7 +59,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // HTTP Server - flags.Bool("http-enabled", conf.Server.HTTP.Enabled, "switch option for HTTP server") if err = viper.BindPFlag("server.http.enabled", flags.Lookup("http-enabled")); err != nil { panic(err) } @@ -80,7 +66,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("http-port", conf.Server.HTTP.Port, "HTTP port address") if err = viper.BindPFlag("server.http.port", flags.Lookup("http-port")); err != nil { panic(err) } @@ -88,7 +73,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Bool("http-tls-enabled", conf.Server.HTTP.TLSConfig.Enabled, "switch option for HTTP tls server") if err = viper.BindPFlag("server.http.tls.enabled", flags.Lookup("http-tls-enabled")); err != nil { panic(err) } @@ -96,7 +80,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("http-tls-key-path", conf.Server.HTTP.TLSConfig.KeyPath, "HTTP tls key path") if err = viper.BindPFlag("server.http.tls.key", flags.Lookup("http-tls-key-path")); err != nil { panic(err) } @@ -104,7 +87,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("http-tls-cert-path", conf.Server.HTTP.TLSConfig.CertPath, "HTTP tls certificate path") if err = viper.BindPFlag("server.http.tls.cert", flags.Lookup("http-tls-cert-path")); err != nil { panic(err) } @@ -112,7 +94,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.StringSlice("http-cors-allowed-origins", conf.Server.HTTP.CORSAllowedOrigins, "CORS allowed origins for http gateway") if err = viper.BindPFlag("server.http.cors_allowed_origins", flags.Lookup("http-cors-allowed-origins")); err != nil { panic(err) } @@ -120,7 +101,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.StringSlice("http-cors-allowed-headers", conf.Server.HTTP.CORSAllowedHeaders, "CORS allowed headers for http gateway") if err = viper.BindPFlag("server.http.cors_allowed_headers", flags.Lookup("http-cors-allowed-headers")); err != nil { panic(err) } @@ -129,7 +109,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // PROFILER - flags.Bool("profiler-enabled", conf.Profiler.Enabled, "switch option for profiler") if err = viper.BindPFlag("profiler.enabled", flags.Lookup("profiler-enabled")); err != nil { panic(err) } @@ -137,7 +116,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("profiler-port", conf.Profiler.Port, "profiler port address") if err = viper.BindPFlag("profiler.port", flags.Lookup("profiler-port")); err != nil { panic(err) } @@ -146,7 +124,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // LOG - flags.String("log-level", conf.Log.Level, "real time logs of authorization. Permify uses zerolog as a logger") if err = viper.BindPFlag("logger.level", flags.Lookup("log-level")); err != nil { panic(err) } @@ -154,7 +131,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("log-output", conf.Log.Output, "logger output valid values json, text") if err = viper.BindPFlag("logger.output", flags.Lookup("log-output")); err != nil { panic(err) } @@ -163,7 +139,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // AUTHN - flags.Bool("authn-enabled", conf.Authn.Enabled, "enable server authentication") if err = viper.BindPFlag("authn.enabled", flags.Lookup("authn-enabled")); err != nil { panic(err) } @@ -171,7 +146,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("authn-method", conf.Authn.Method, "server authentication method") if err = viper.BindPFlag("authn.method", flags.Lookup("authn-method")); err != nil { panic(err) } @@ -179,7 +153,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.StringSlice("authn-preshared-keys", conf.Authn.Preshared.Keys, "preshared key/keys for server authentication") if err = viper.BindPFlag("authn.preshared.keys", flags.Lookup("authn-preshared-keys")); err != nil { panic(err) } @@ -187,7 +160,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("authn-oidc-issuer", conf.Authn.Oidc.Issuer, "issuer identifier of the OpenID Connect Provider") if err = viper.BindPFlag("authn.oidc.issuer", flags.Lookup("authn-oidc-issuer")); err != nil { panic(err) } @@ -195,7 +167,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("authn-oidc-audience", conf.Authn.Oidc.Audience, "intended audience of the OpenID Connect token") if err = viper.BindPFlag("authn.oidc.audience", flags.Lookup("authn-oidc-audience")); err != nil { panic(err) } @@ -203,7 +174,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Duration("authn-oidc-refresh-interval", conf.Authn.Oidc.RefreshInterval, "refresh interval for the OpenID Connect configuration") if err = viper.BindPFlag("authn.oidc.refresh_interval", flags.Lookup("authn-oidc-refresh-interval")); err != nil { panic(err) } @@ -211,7 +181,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.StringSlice("authn-oidc-valid-methods", conf.Authn.Oidc.ValidMethods, "list of valid JWT signing methods for OpenID Connect") if err = viper.BindPFlag("authn.oidc.valid_methods", flags.Lookup("authn-oidc-valid-methods")); err != nil { panic(err) } @@ -220,7 +189,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // TRACER - flags.Bool("tracer-enabled", conf.Tracer.Enabled, "switch option for tracing") if err = viper.BindPFlag("tracer.enabled", flags.Lookup("tracer-enabled")); err != nil { panic(err) } @@ -228,7 +196,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("tracer-exporter", conf.Tracer.Exporter, "can be; jaeger, signoz, zipkin or otlp. (integrated tracing tools)") if err = viper.BindPFlag("tracer.exporter", flags.Lookup("tracer-exporter")); err != nil { panic(err) } @@ -236,7 +203,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("tracer-endpoint", conf.Tracer.Endpoint, "export uri for tracing data") if err = viper.BindPFlag("tracer.endpoint", flags.Lookup("tracer-endpoint")); err != nil { panic(err) } @@ -244,7 +210,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Bool("tracer-insecure", conf.Tracer.Insecure, "use https or http for tracer data, only used for otlp exporter or signoz") if err = viper.BindPFlag("tracer.insecure", flags.Lookup("tracer-insecure")); err != nil { panic(err) } @@ -252,7 +217,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("tracer-urlpath", conf.Tracer.URLPath, "allow to set url path for otlp exporter") if err = viper.BindPFlag("tracer.urlpath", flags.Lookup("tracer-urlpath")); err != nil { panic(err) } @@ -261,7 +225,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // METER - flags.Bool("meter-enabled", conf.Meter.Enabled, "switch option for metric") if err = viper.BindPFlag("meter.enabled", flags.Lookup("meter-enabled")); err != nil { panic(err) } @@ -269,7 +232,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("meter-exporter", conf.Meter.Exporter, "can be; otlp. (integrated metric tools)") if err = viper.BindPFlag("meter.exporter", flags.Lookup("meter-exporter")); err != nil { panic(err) } @@ -277,7 +239,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("meter-endpoint", conf.Meter.Endpoint, "export uri for metric data") if err = viper.BindPFlag("meter.endpoint", flags.Lookup("meter-endpoint")); err != nil { panic(err) } @@ -285,7 +246,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Bool("meter-insecure", conf.Meter.Insecure, "use https or http for metric data") if err = viper.BindPFlag("meter.insecure", flags.Lookup("meter-insecure")); err != nil { panic(err) } @@ -293,7 +253,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("meter-urlpath", conf.Meter.URLPath, "allow to set url path for otlp exporter") if err = viper.BindPFlag("meter.urlpath", flags.Lookup("meter-urlpath")); err != nil { panic(err) } @@ -302,7 +261,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // SERVICE - flags.Bool("service-circuit-breaker", conf.Service.CircuitBreaker, "switch option for service circuit breaker") if err = viper.BindPFlag("service.circuit_breaker", flags.Lookup("service-circuit-breaker")); err != nil { panic(err) } @@ -310,7 +268,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Bool("service-watch-enabled", conf.Service.Watch.Enabled, "switch option for watch service") if err = viper.BindPFlag("service.watch.enabled", flags.Lookup("service-watch-enabled")); err != nil { panic(err) } @@ -318,7 +275,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int64("service-schema-cache-number-of-counters", conf.Service.Schema.Cache.NumberOfCounters, "schema service cache number of counters") if err = viper.BindPFlag("service.schema.cache.number_of_counters", flags.Lookup("service-schema-cache-number-of-counters")); err != nil { panic(err) } @@ -326,7 +282,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("service-schema-cache-max-cost", conf.Service.Schema.Cache.MaxCost, "schema service cache max cost") if err = viper.BindPFlag("service.schema.cache.max_cost", flags.Lookup("service-schema-cache-max-cost")); err != nil { panic(err) } @@ -334,7 +289,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int("service-permission-bulk-limit", conf.Service.Permission.BulkLimit, "bulk operations limit") if err = viper.BindPFlag("service.permission.bulk_limit", flags.Lookup("service-permission-bulk-limit")); err != nil { panic(err) } @@ -342,7 +296,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int("service-permission-concurrency-limit", conf.Service.Permission.ConcurrencyLimit, "concurrency limit") if err = viper.BindPFlag("service.permission.concurrency_limit", flags.Lookup("service-permission-concurrency-limit")); err != nil { panic(err) } @@ -350,7 +303,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int64("service-permission-cache-number-of-counters", conf.Service.Permission.Cache.NumberOfCounters, "permission service cache number of counters") if err = viper.BindPFlag("service.permission.cache.number_of_counters", flags.Lookup("service-permission-cache-number-of-counters")); err != nil { panic(err) } @@ -358,7 +310,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("service-permission-cache-max-cost", conf.Service.Permission.Cache.MaxCost, "permission service cache max cost") if err = viper.BindPFlag("service.permission.cache.max_cost", flags.Lookup("service-permission-cache-max-cost")); err != nil { panic(err) } @@ -367,7 +318,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // DATABASE - flags.String("database-engine", conf.Database.Engine, "data source. e.g. postgres, memory") if err = viper.BindPFlag("database.engine", flags.Lookup("database-engine")); err != nil { panic(err) } @@ -375,7 +325,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("database-uri", conf.Database.URI, "uri of your data source to store relation tuples and schema") if err = viper.BindPFlag("database.uri", flags.Lookup("database-uri")); err != nil { panic(err) } @@ -383,7 +332,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Bool("database-auto-migrate", conf.Database.AutoMigrate, "auto migrate database tables") if err = viper.BindPFlag("database.auto_migrate", flags.Lookup("database-auto-migrate")); err != nil { panic(err) } @@ -391,7 +339,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int("database-max-open-connections", conf.Database.MaxOpenConnections, "maximum number of parallel connections that can be made to the database at any time") if err = viper.BindPFlag("database.max_open_connections", flags.Lookup("database-max-open-connections")); err != nil { panic(err) } @@ -399,7 +346,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int("database-max-idle-connections", conf.Database.MaxIdleConnections, "maximum number of idle connections that can be made to the database at any time") if err = viper.BindPFlag("database.max_idle_connections", flags.Lookup("database-max-idle-connections")); err != nil { panic(err) } @@ -407,7 +353,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Duration("database-max-connection-lifetime", conf.Database.MaxConnectionLifetime, "maximum amount of time a connection may be reused") if err = viper.BindPFlag("database.max_connection_lifetime", flags.Lookup("database-max-connection-lifetime")); err != nil { panic(err) } @@ -415,7 +360,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Duration("database-max-connection-idle-time", conf.Database.MaxConnectionIdleTime, "maximum amount of time a connection may be idle") if err = viper.BindPFlag("database.max_connection_idle_time", flags.Lookup("database-max-connection-idle-time")); err != nil { panic(err) } @@ -423,7 +367,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int("database-max-data-per-write", conf.Database.MaxDataPerWrite, "sets the maximum amount of data per write operation to the database") if err = viper.BindPFlag("database.max_data_per_write", flags.Lookup("database-max-data-per-write")); err != nil { panic(err) } @@ -431,7 +374,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int("database-max-retries", conf.Database.MaxRetries, "defines the maximum number of retries for database operations in case of failure") if err = viper.BindPFlag("database.max_retries", flags.Lookup("database-max-retries")); err != nil { panic(err) } @@ -439,7 +381,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Int("database-watch-buffer-size", conf.Database.WatchBufferSize, "specifies the buffer size for database watch operations, impacting how many changes can be queued") if err = viper.BindPFlag("database.watch_buffer_size", flags.Lookup("database-watch-buffer-size")); err != nil { panic(err) } @@ -447,7 +388,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Bool("database-garbage-collection-enabled", conf.Database.GarbageCollection.Enabled, "use database garbage collection for expired relationships and attributes") if err = viper.BindPFlag("database.garbage_collection.enabled", flags.Lookup("database-garbage-collection-enabled")); err != nil { panic(err) } @@ -455,7 +395,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Duration("database-garbage-collection-interval", conf.Database.GarbageCollection.Interval, "interval for database garbage collection") if err = viper.BindPFlag("database.garbage_collection.interval", flags.Lookup("database-garbage-collection-interval")); err != nil { panic(err) } @@ -463,7 +402,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Duration("database-garbage-collection-timeout", conf.Database.GarbageCollection.Timeout, "timeout for database garbage collection") if err = viper.BindPFlag("database.garbage_collection.timeout", flags.Lookup("database-garbage-collection-timeout")); err != nil { panic(err) } @@ -471,7 +409,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.Duration("database-garbage-collection-window", conf.Database.GarbageCollection.Window, "window for database garbage collection") if err = viper.BindPFlag("database.garbage_collection.window", flags.Lookup("database-garbage-collection-window")); err != nil { panic(err) } @@ -480,7 +417,6 @@ func RegisterServeFlags(cmd *cobra.Command) { } // DISTRIBUTED - flags.Bool("distributed-enabled", conf.Distributed.Enabled, "enable distributed") if err = viper.BindPFlag("distributed.enabled", flags.Lookup("distributed-enabled")); err != nil { panic(err) } @@ -488,7 +424,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("distributed-address", conf.Distributed.Address, "distributed address") if err = viper.BindPFlag("distributed.address", flags.Lookup("distributed-address")); err != nil { panic(err) } @@ -496,7 +431,6 @@ func RegisterServeFlags(cmd *cobra.Command) { panic(err) } - flags.String("distributed-port", conf.Distributed.Port, "distributed port") if err = viper.BindPFlag("distributed.port", flags.Lookup("distributed-port")); err != nil { panic(err) } diff --git a/pkg/cmd/serve.go b/pkg/cmd/serve.go index d4ecf6b78..c6e94c5d8 100644 --- a/pkg/cmd/serve.go +++ b/pkg/cmd/serve.go @@ -10,7 +10,10 @@ import ( "syscall" "time" + "github.com/davecgh/go-spew/spew" + "github.com/sony/gobreaker" + "github.com/spf13/cobra" "github.com/spf13/viper" "go.opentelemetry.io/otel/sdk/metric" @@ -24,7 +27,6 @@ import ( "github.com/Permify/permify/pkg/cmd/flags" PQDatabase "github.com/Permify/permify/pkg/database/postgres" - "github.com/spf13/cobra" "go.opentelemetry.io/otel/sdk/trace" "golang.org/x/sync/errgroup" @@ -52,11 +54,75 @@ func NewServeCommand() *cobra.Command { Args: cobra.NoArgs, } + conf := config.DefaultConfig() + f := command.Flags() + f.StringP("config", "c", "", "config file (default is $HOME/.permify.yaml)") + f.Bool("http-enabled", conf.Server.HTTP.Enabled, "switch option for HTTP server") + f.String("account-id", conf.AccountID, "account id") + f.Int64("server-rate-limit", conf.Server.RateLimit, "the maximum number of requests the server should handle per second") + f.String("grpc-port", conf.Server.GRPC.Port, "port that GRPC server run on") + f.Bool("grpc-tls-enabled", conf.Server.GRPC.TLSConfig.Enabled, "switch option for GRPC tls server") + f.String("grpc-tls-key-path", conf.Server.GRPC.TLSConfig.KeyPath, "GRPC tls key path") + f.String("grpc-tls-cert-path", conf.Server.GRPC.TLSConfig.CertPath, "GRPC tls certificate path") + f.String("http-port", conf.Server.HTTP.Port, "HTTP port address") + f.Bool("http-tls-enabled", conf.Server.HTTP.TLSConfig.Enabled, "switch option for HTTP tls server") + f.String("http-tls-key-path", conf.Server.HTTP.TLSConfig.KeyPath, "HTTP tls key path") + f.String("http-tls-cert-path", conf.Server.HTTP.TLSConfig.CertPath, "HTTP tls certificate path") + f.StringSlice("http-cors-allowed-origins", conf.Server.HTTP.CORSAllowedOrigins, "CORS allowed origins for http gateway") + f.StringSlice("http-cors-allowed-headers", conf.Server.HTTP.CORSAllowedHeaders, "CORS allowed headers for http gateway") + f.Bool("profiler-enabled", conf.Profiler.Enabled, "switch option for profiler") + f.String("profiler-port", conf.Profiler.Port, "profiler port address") + f.String("log-level", conf.Log.Level, "set log verbosity ('info', 'debug', 'error', 'warning')") + f.String("log-output", conf.Log.Output, "logger output valid values json, text") + f.Bool("authn-enabled", conf.Authn.Enabled, "enable server authentication") + f.String("authn-method", conf.Authn.Method, "server authentication method") + f.StringSlice("authn-preshared-keys", conf.Authn.Preshared.Keys, "preshared key/keys for server authentication") + f.String("authn-oidc-issuer", conf.Authn.Oidc.Issuer, "issuer identifier of the OpenID Connect Provider") + f.String("authn-oidc-audience", conf.Authn.Oidc.Audience, "intended audience of the OpenID Connect token") + f.Duration("authn-oidc-refresh-interval", conf.Authn.Oidc.RefreshInterval, "refresh interval for the OpenID Connect configuration") + f.StringSlice("authn-oidc-valid-methods", conf.Authn.Oidc.ValidMethods, "list of valid JWT signing methods for OpenID Connect") + f.Bool("tracer-enabled", conf.Tracer.Enabled, "switch option for tracing") + f.String("tracer-exporter", conf.Tracer.Exporter, "can be; jaeger, signoz, zipkin or otlp. (integrated tracing tools)") + f.String("tracer-endpoint", conf.Tracer.Endpoint, "export uri for tracing data") + f.Bool("tracer-insecure", conf.Tracer.Insecure, "use https or http for tracer data, only used for otlp exporter or signoz") + f.String("tracer-urlpath", conf.Tracer.URLPath, "allow to set url path for otlp exporter") + f.Bool("meter-enabled", conf.Meter.Enabled, "switch option for metric") + f.String("meter-exporter", conf.Meter.Exporter, "can be; otlp. (integrated metric tools)") + f.String("meter-endpoint", conf.Meter.Endpoint, "export uri for metric data") + f.Bool("meter-insecure", conf.Meter.Insecure, "use https or http for metric data") + f.String("meter-urlpath", conf.Meter.URLPath, "allow to set url path for otlp exporter") + f.Bool("service-circuit-breaker", conf.Service.CircuitBreaker, "switch option for service circuit breaker") + f.Bool("service-watch-enabled", conf.Service.Watch.Enabled, "switch option for watch service") + f.Int64("service-schema-cache-number-of-counters", conf.Service.Schema.Cache.NumberOfCounters, "schema service cache number of counters") + f.String("service-schema-cache-max-cost", conf.Service.Schema.Cache.MaxCost, "schema service cache max cost") + f.Int("service-permission-bulk-limit", conf.Service.Permission.BulkLimit, "bulk operations limit") + f.Int("service-permission-concurrency-limit", conf.Service.Permission.ConcurrencyLimit, "concurrency limit") + f.Int64("service-permission-cache-number-of-counters", conf.Service.Permission.Cache.NumberOfCounters, "permission service cache number of counters") + f.String("service-permission-cache-max-cost", conf.Service.Permission.Cache.MaxCost, "permission service cache max cost") + f.String("database-engine", conf.Database.Engine, "data source. e.g. postgres, memory") + f.String("database-uri", conf.Database.URI, "uri of your data source to store relation tuples and schema") + f.Bool("database-auto-migrate", conf.Database.AutoMigrate, "auto migrate database tables") + f.Int("database-max-open-connections", conf.Database.MaxOpenConnections, "maximum number of parallel connections that can be made to the database at any time") + f.Int("database-max-idle-connections", conf.Database.MaxIdleConnections, "maximum number of idle connections that can be made to the database at any time") + f.Duration("database-max-connection-lifetime", conf.Database.MaxConnectionLifetime, "maximum amount of time a connection may be reused") + f.Duration("database-max-connection-idle-time", conf.Database.MaxConnectionIdleTime, "maximum amount of time a connection may be idle") + f.Int("database-max-data-per-write", conf.Database.MaxDataPerWrite, "sets the maximum amount of data per write operation to the database") + f.Int("database-max-retries", conf.Database.MaxRetries, "defines the maximum number of retries for database operations in case of failure") + f.Int("database-watch-buffer-size", conf.Database.WatchBufferSize, "specifies the buffer size for database watch operations, impacting how many changes can be queued") + f.Bool("database-garbage-collection-enabled", conf.Database.GarbageCollection.Enabled, "use database garbage collection for expired relationships and attributes") + f.Duration("database-garbage-collection-interval", conf.Database.GarbageCollection.Interval, "interval for database garbage collection") + f.Duration("database-garbage-collection-timeout", conf.Database.GarbageCollection.Timeout, "timeout for database garbage collection") + f.Duration("database-garbage-collection-window", conf.Database.GarbageCollection.Window, "window for database garbage collection") + f.Bool("distributed-enabled", conf.Distributed.Enabled, "enable distributed") + f.String("distributed-address", conf.Distributed.Address, "distributed address") + f.String("distributed-port", conf.Distributed.Port, "distributed port") + // SilenceUsage is set to true to suppress usage when an error occurs command.SilenceUsage = true - // register flags for serve - flags.RegisterServeFlags(command) + command.PreRun = func(cmd *cobra.Command, args []string) { + flags.RegisterServeFlags(f) + } return command } @@ -92,6 +158,8 @@ func serve() func(cmd *cobra.Command, args []string) error { } } + spew.Dump(cfg) + // Print banner and initialize logger internal.PrintBanner() From 6dc5f2e88ca3068fe81f9a379638e7cd4b5222b3 Mon Sep 17 00:00:00 2001 From: Tolga Ozen Date: Sun, 31 Mar 2024 00:44:56 +0300 Subject: [PATCH 2/2] build: version info update --- docs/api-reference/apidocs.swagger.json | 2 +- internal/info.go | 2 +- pkg/pb/base/v1/openapi.pb.go | 2 +- proto/base/v1/openapi.proto | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api-reference/apidocs.swagger.json b/docs/api-reference/apidocs.swagger.json index f2e0047ed..b5d3f3675 100644 --- a/docs/api-reference/apidocs.swagger.json +++ b/docs/api-reference/apidocs.swagger.json @@ -3,7 +3,7 @@ "info": { "title": "Permify API", "description": "Permify is an open source authorization service for creating fine-grained and scalable authorization systems.", - "version": "v0.7.9", + "version": "v0.8.0", "contact": { "name": "API Support", "url": "https://github.com/Permify/permify/issues", diff --git a/internal/info.go b/internal/info.go index 6c228e5a3..15d3cacd8 100644 --- a/internal/info.go +++ b/internal/info.go @@ -23,7 +23,7 @@ var Identifier = "" */ const ( // Version is the last release of the Permify (e.g. v0.1.0) - Version = "v0.7.9" + Version = "v0.8.0" ) // Function to create a single line of the ASCII art with centered content and color diff --git a/pkg/pb/base/v1/openapi.pb.go b/pkg/pb/base/v1/openapi.pb.go index 0c06a6220..427f1c97c 100644 --- a/pkg/pb/base/v1/openapi.pb.go +++ b/pkg/pb/base/v1/openapi.pb.go @@ -46,7 +46,7 @@ var file_base_v1_openapi_proto_rawDesc = []byte{ 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x50, 0x65, 0x72, 0x6d, 0x69, 0x66, 0x79, 0x2f, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x66, 0x79, 0x2f, 0x62, 0x6c, 0x6f, 0x62, 0x2f, 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x2f, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, - 0x32, 0x06, 0x76, 0x30, 0x2e, 0x37, 0x2e, 0x39, 0x2a, 0x01, 0x02, 0x32, 0x10, 0x61, 0x70, 0x70, + 0x32, 0x06, 0x76, 0x30, 0x2e, 0x38, 0x2e, 0x30, 0x2a, 0x01, 0x02, 0x32, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x3a, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x5a, 0x23, 0x0a, 0x21, 0x0a, 0x0a, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x41, 0x75, 0x74, 0x68, 0x12, diff --git a/proto/base/v1/openapi.proto b/proto/base/v1/openapi.proto index ee4a9fe79..f21a86d6b 100644 --- a/proto/base/v1/openapi.proto +++ b/proto/base/v1/openapi.proto @@ -9,7 +9,7 @@ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Permify API"; description: "Permify is an open source authorization service for creating fine-grained and scalable authorization systems."; - version: "v0.7.9"; + version: "v0.8.0"; contact: { name: "API Support"; url: "https://github.com/Permify/permify/issues";