diff --git a/README.md b/README.md index 7a20be447..3ce5ee47e 100644 --- a/README.md +++ b/README.md @@ -126,12 +126,12 @@ The Indexer has a default set of disabled parameters. To view the disabled para This will output ONLY the disabled parameters in a YAML configuration. To view all parameters (both enabled and disabled) issue: ``` -~$ algorand-indexer api-config all +~$ algorand-indexer api-config --all ``` ### Interpreting The Configuration -Below is a sample output of what the output of `algorand-indexer api-config` will look like: +Below is a snippet of the output from `algorand-indexer api-config`: ``` /v2/accounts: diff --git a/api/server.go b/api/server.go index 0eb833a24..74f5616ee 100644 --- a/api/server.go +++ b/api/server.go @@ -37,6 +37,9 @@ type ExtraOptions struct { // ReadTimeout is the maximum duration for reading the entire request, including the body. ReadTimeout time.Duration + + // DisabledMapConfig is the disabled map configuration that is being used by the server + DisabledMapConfig *DisabledMapConfig } func (e ExtraOptions) handlerTimeout() time.Duration { @@ -50,7 +53,7 @@ func (e ExtraOptions) handlerTimeout() time.Duration { } // Serve starts an http server for the indexer API. This call blocks. -func Serve(ctx context.Context, disabledMapConfig *DisabledMapConfig, serveAddr string, db idb.IndexerDb, fetcherError error, log *log.Logger, options ExtraOptions) { +func Serve(ctx context.Context, serveAddr string, db idb.IndexerDb, fetcherError error, log *log.Logger, options ExtraOptions) { e := echo.New() e.HideBanner = true @@ -83,7 +86,7 @@ func Serve(ctx context.Context, disabledMapConfig *DisabledMapConfig, serveAddr log.Fatal(err) } - disabledMap, err := MakeDisabledMapFromOA3(swag, disabledMapConfig) + disabledMap, err := MakeDisabledMapFromOA3(swag, options.DisabledMapConfig) if err != nil { log.Fatal(err) } diff --git a/cmd/algorand-indexer/api_config.go b/cmd/algorand-indexer/api_config.go index be156c0fd..f1a19f9cd 100644 --- a/cmd/algorand-indexer/api_config.go +++ b/cmd/algorand-indexer/api_config.go @@ -11,6 +11,10 @@ import ( "github.com/algorand/indexer/config" ) +var ( + showAllDisabled bool +) + var apiConfigCmd = &cobra.Command{ Use: "api-config", Short: "dump api configuration", @@ -31,19 +35,14 @@ var apiConfigCmd = &cobra.Command{ os.Exit(1) } + options := makeOptions() + var displayDisabledMapConfig *api.DisplayDisabledMap // Show a limited subset - if len(args) == 0 { - displayDisabledMapConfig = api.MakeDisplayDisabledMapFromConfig(swag, disabledMapConfig, true) - + if !showAllDisabled { + displayDisabledMapConfig = api.MakeDisplayDisabledMapFromConfig(swag, options.DisabledMapConfig, true) } else { - // This is the only acceptable option - if args[0] != "all" { - fmt.Fprintf(os.Stderr, "unrecognized option to api-config: %s", args[0]) - os.Exit(1) - } - - displayDisabledMapConfig = api.MakeDisplayDisabledMapFromConfig(swag, disabledMapConfig, false) + displayDisabledMapConfig = api.MakeDisplayDisabledMapFromConfig(swag, options.DisabledMapConfig, false) } output, err := displayDisabledMapConfig.String() @@ -58,3 +57,8 @@ var apiConfigCmd = &cobra.Command{ }, } + +func init() { + apiConfigCmd.Flags().BoolVarP(&showAllDisabled, "all", "", false, "show all api config parameters, enabled and disabled") + apiConfigCmd.Flags().Lookup("all").NoOptDefVal = "true" +} diff --git a/cmd/algorand-indexer/daemon.go b/cmd/algorand-indexer/daemon.go index 9706d0468..7f19634cc 100644 --- a/cmd/algorand-indexer/daemon.go +++ b/cmd/algorand-indexer/daemon.go @@ -128,7 +128,7 @@ var daemonCmd = &cobra.Command{ fmt.Printf("serving on %s\n", daemonServerAddr) logger.Infof("serving on %s", daemonServerAddr) - api.Serve(ctx, disabledMapConfig, daemonServerAddr, db, bot, logger, makeOptions()) + api.Serve(ctx, daemonServerAddr, db, bot, logger, makeOptions()) wg.Wait() }, } @@ -175,6 +175,12 @@ func makeOptions() (options api.ExtraOptions) { options.WriteTimeout = writeTimeout options.ReadTimeout = readTimeout + // TODO enable this when command line options allows for disabling/enabling overrides + //disabledMapConfig := api.GetDefaultDisabledMapConfigForPostgres() + disabledMapConfig := api.MakeDisabledMapConfig() + + options.DisabledMapConfig = disabledMapConfig + return } diff --git a/cmd/algorand-indexer/main.go b/cmd/algorand-indexer/main.go index 856bc275c..7ca86e459 100644 --- a/cmd/algorand-indexer/main.go +++ b/cmd/algorand-indexer/main.go @@ -12,7 +12,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/viper" - "github.com/algorand/indexer/api" bg "github.com/algorand/indexer/cmd/block-generator/core" iv "github.com/algorand/indexer/cmd/import-validator/core" v "github.com/algorand/indexer/cmd/validator/core" @@ -24,8 +23,6 @@ import ( "github.com/algorand/indexer/version" ) -var disabledMapConfig *api.DisabledMapConfig - func maybeFail(err error, errfmt string, params ...interface{}) { if err == nil { return @@ -207,11 +204,6 @@ func configureLogger() error { } func main() { - - // TODO enable this when command line options allows for disabling/enabling overrides - //disabledMapConfig = api.GetDefaultDisabledMapConfigForPostgres() - disabledMapConfig = api.MakeDisabledMapConfig() - if err := rootCmd.Execute(); err != nil { logger.WithError(err).Error("an error occurred running indexer") os.Exit(1)