2024-08-01 08:21:20 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/version"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-08-02 13:45:49 +00:00
|
|
|
defaultPrintResponseLimit = 1024
|
|
|
|
configPath = "config"
|
|
|
|
configPathFlag = "config"
|
|
|
|
httpTimeout = "http_timeout"
|
|
|
|
httpTimeoutFlag = "http-timeout"
|
|
|
|
skipVerifyTLS = "skip_verify_tls"
|
|
|
|
skipVerifyTLSFlag = "skip-verify-tls"
|
|
|
|
printResponseLimit = "print_response_limit"
|
2024-08-01 08:21:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
cfgFile string
|
|
|
|
rootCmd = &cobra.Command{
|
|
|
|
Use: "frostfs-s3-playback",
|
|
|
|
Version: version.Version,
|
|
|
|
Short: "FrostFS S3 Traffic Playback",
|
|
|
|
Long: "Helps to reproduce s3 commands from log files",
|
|
|
|
Example: "frostfs-s3-playback [--skip-verify-tls] [--http-timeout <timeout>] " +
|
|
|
|
"[--version] --config <config_path> <command>",
|
|
|
|
SilenceUsage: true,
|
|
|
|
SilenceErrors: true,
|
|
|
|
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
|
|
|
_ = viper.BindPFlag(configPath, cmd.PersistentFlags().Lookup(configPathFlag))
|
|
|
|
|
|
|
|
_ = viper.BindPFlag(httpTimeout, cmd.PersistentFlags().Lookup(httpTimeoutFlag))
|
|
|
|
|
|
|
|
_ = viper.BindPFlag(skipVerifyTLS, cmd.PersistentFlags().Lookup(skipVerifyTLSFlag))
|
|
|
|
|
2024-08-02 13:45:49 +00:00
|
|
|
viper.SetDefault(printResponseLimit, defaultPrintResponseLimit)
|
|
|
|
|
2024-08-01 08:21:20 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
|
|
return cmd.Help()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func Execute(ctx context.Context) (*cobra.Command, error) {
|
|
|
|
return rootCmd.ExecuteContextC(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func initConfig() {
|
|
|
|
viper.SetConfigFile(cfgFile)
|
|
|
|
_ = viper.ReadInConfig()
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
rootCmd.PersistentFlags().StringVar(&cfgFile, configPathFlag, "", "configuration filepath")
|
|
|
|
_ = rootCmd.MarkPersistentFlagRequired(configPathFlag)
|
|
|
|
_ = rootCmd.MarkPersistentFlagFilename(configPathFlag)
|
|
|
|
rootCmd.PersistentFlags().Duration(httpTimeoutFlag, time.Minute, "http request timeout")
|
|
|
|
rootCmd.PersistentFlags().Bool(skipVerifyTLSFlag, false, "skip TLS certificate verification")
|
|
|
|
|
|
|
|
rootCmd.AddCommand(runCmd)
|
|
|
|
}
|