// Run is a function to run the command func (c *Command) Run(args []string) int { var err error // error holder var count int // key counter // init config c.config = new(config) // init consul config c.config.consulConfig = new(ccns.Config) // setup flags if err = c.setupFlags(args); err != nil { log.Printf("[Error] Init failed: %s", err.Error()) return 1 } // sanity check if c.config.noKV && c.config.aclFileName == "" { log.Printf("[Error] Passing 'nokv' and an empty 'acls' file " + "doesn't make any sense. You should specify an 'acls' file " + "when using the 'nokv' option.") return 1 } // build client if c.consulClient, err = c.config.consulConfig.New(); err != nil { log.Printf("[Error] Failed initialize consul client: %s", err.Error()) return 1 } // build transformer if needed if c.pathTransformer, err = ct.New(c.config.pathTransform); err != nil { log.Printf("[Error] Failed to initialize path transformer: %s", err.Error()) return 1 } // restore keys unless otherwise requested if !c.config.noKV { if count, err = c.restoreKeys(); err != nil { log.Printf("[Error] Failed to restore kv data: %s", err.Error()) return 1 } // show success log.Printf("[Success] Restored %d keys from %s to %s/%s", count, c.config.fileName, c.config.consulConfig.Address, c.config.consulPrefix) } // restore acls if requested if c.config.aclFileName != "" { if count, err = c.restoreAcls(); err != nil { log.Printf("[Error] Failed to restore ACL tokens: %s", err.Error()) return 1 } // show success log.Printf("[Success] Restored %d ACL tokens from %s to %s", count, c.config.aclFileName, c.config.consulConfig.Address) } // exit clean return 0 }
// Run is a function to run the command func (c *Command) Run(args []string) int { var err error // error holder var count int // key counter // init config c.config = new(config) // init consul config c.config.consulConfig = new(ccns.Config) // setup flags if err = c.setupFlags(args); err != nil { log.Printf("[Error] Init failed: %s", err.Error()) return 1 } // sanity check if c.config.noKV && c.config.aclFileName == "" { log.Printf("[Error] Passing 'nokv' and an empty 'acls' file " + "doesn't make any sense. You should specify an 'acls' file " + "when using the 'nokv' option.") return 1 } // build client if c.consulClient, err = c.config.consulConfig.New(); err != nil { log.Printf("[Error] Failed initialize consul client: %s", err.Error()) return 1 } // build transformer if needed if c.pathTransformer, err = ct.New(c.config.pathTransform); err != nil { log.Printf("[Error] Failed to initialize path transformer: %s", err.Error()) return 1 } // backup keys unless otherwise requested if !c.config.noKV { if count, err = c.backupKeys(); err != nil { log.Printf("[Error] Failed to backup key data: %s", err.Error()) return 1 } // show success log.Printf("[Success] Backed up %d keys from %s/%s to %s", count, c.config.consulConfig.Address, c.config.consulPrefix, c.config.fileName) } // backup acls if requested if c.config.aclFileName != "" { if count, err = c.backupAcls(); err != nil { log.Printf("[Error] Failed to backup ACL tokens: %s", err.Error()) return 1 } // show success log.Printf("[Success] Backed up %d ACL tokens from %s to %s", count, c.config.consulConfig.Address, c.config.aclFileName) } // make sure they know to keep the sig fmt.Print("Keep your backup and signature files " + "in a safe place.\nYou will need both to restore your data.\n") // exit clean return 0 }