Skip to content

Commit

Permalink
precheck skip
Browse files Browse the repository at this point in the history
  • Loading branch information
po3rin committed Feb 15, 2021
1 parent 0be7385 commit 8fef9f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 2 additions & 5 deletions cmd/eskeeper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import (
"golang.org/x/crypto/ssh/terminal"
)

const (
TERMINAL = "terminal"
PIPE = "pipe"
)

var rootCmd = &cobra.Command{
Use: "eskeeper",
Short: "eskeeper synchronizes index and alias with configuration files while ensuring idempotency.",
Expand All @@ -26,6 +21,7 @@ var rootCmd = &cobra.Command{
eskeeper.UserName(viper.GetString("es_user")),
eskeeper.Pass(viper.GetString("es_pass")),
eskeeper.Verbose(viper.GetBool("verbose")),
eskeeper.Verbose(viper.GetBool("skip_precheck")),
)
if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -83,6 +79,7 @@ func init() {
pflag.StringP("es_pass", "p", "", "Elasticsearch password")
pflag.StringSliceP("es_urls", "e", []string{"http://localhost:9200"}, "Elasticserch endpoint URLs (comma delimited)")
pflag.BoolP("verbose", "v", false, "Make the operation more talkative")
pflag.BoolP("skip_precheck", "s", false, "Skip pre-check stage")

viper.BindPFlags(pflag.CommandLine)
}
Expand Down
24 changes: 17 additions & 7 deletions eskeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ type Eskeeper struct {
client *esclient

// options
user string
pass string
verbose bool
user string
pass string
verbose bool
skipPreCheck bool
}

// NewOption is optional func for eskeeper.New
Expand All @@ -40,6 +41,13 @@ func Verbose(v bool) NewOption {
}
}

// SkipPreCheck is optional func for skipping pre-check-stage..
func SkipPreCheck(v bool) NewOption {
return func(e *Eskeeper) {
e.skipPreCheck = v
}
}

// New inits Eskeeper.
func New(urls []string, opts ...NewOption) (*Eskeeper, error) {
eskeeper := &Eskeeper{}
Expand Down Expand Up @@ -73,10 +81,12 @@ func (e *Eskeeper) Sync(ctx context.Context, reader io.Reader) error {
return err
}

e.log("\n=== pre-check stage ===")
err = e.client.preCheck(ctx, conf)
if err != nil {
return err
if !e.skipPreCheck {
e.log("\n=== pre-check stage ===")
err = e.client.preCheck(ctx, conf)
if err != nil {
return err
}
}

e.log("\n=== sync stage ===")
Expand Down

0 comments on commit 8fef9f2

Please sign in to comment.