func RmChain(do *definitions.Do) error { chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber) if err != nil { return err } if IsChainExisting(chain) { if err = perform.DockerRemove(chain.Service, chain.Operations, do.RmD); err != nil { return err } } else { logger.Infoln("That chain's container does not exist.") } if do.File { oldFile := util.GetFileByNameAndType("chains", do.Name) if err != nil { return err } oldFile = path.Join(BlockchainsPath, oldFile) + ".toml" logger.Printf("Removing file =>\t\t%s\n", oldFile) if err := os.Remove(oldFile); err != nil { return err } } return nil }
func RmChain(do *definitions.Do) error { chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber) if err != nil { return err } if IsChainExisting(chain) { if err = perform.DockerRemove(chain.Service, chain.Operations, do.RmD, do.Volumes); err != nil { return err } } else { log.Info("Chain container does not exist") } if do.File { oldFile := util.GetFileByNameAndType("chains", do.Name) if err != nil { return err } log.WithField("file", oldFile).Warn("Removing file") if err := os.Remove(oldFile); err != nil { return err } } return nil }
func RmService(do *definitions.Do) error { for _, servName := range do.Args { service, err := loaders.LoadServiceDefinition(servName, false, do.Operations.ContainerNumber) if err != nil { return err } if IsServiceExisting(service.Service, service.Operations) { err = perform.DockerRemove(service.Service, service.Operations, do.RmD) if err != nil { return err } } if do.File { oldFile := util.GetFileByNameAndType("services", servName) if err != nil { return err } oldFile = path.Join(ServicesPath, oldFile) + ".toml" logger.Printf("Removing file =>\t\t%s\n", oldFile) if err := os.Remove(oldFile); err != nil { return err } } } do.Result = "success" return nil }
func RenameAction(do *definitions.Do) error { if do.Name == do.NewName { return fmt.Errorf("Cannot rename to same name") } do.Name = strings.Replace(do.Name, " ", "_", -1) do.NewName = strings.Replace(do.NewName, " ", "_", -1) act, _, err := LoadActionDefinition(do.Name) if err != nil { log.WithFields(log.Fields{ "from": do.Name, "to": do.NewName, }).Debug("Failed renaming action") return err } do.Name = strings.Replace(do.Name, " ", "_", -1) log.WithField("file", do.Name).Debug("Finding action definition file") oldFile := util.GetFileByNameAndType("actions", do.Name) if oldFile == "" { return fmt.Errorf("Could not find that action definition file.") } log.WithField("file", oldFile).Debug("Found action definition file") // if !strings.Contains(oldFile, ActionsPath) { // oldFile = filepath.Join(ActionsPath, oldFile) + ".toml" // } var newFile string newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1) if newNameBase == do.Name { newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1) } else { newFile = strings.Replace(oldFile, do.Name, do.NewName, 1) newFile = strings.Replace(newFile, " ", "_", -1) } if newFile == oldFile { log.Info("Not renaming the same file") return nil } act.Name = strings.Replace(newNameBase, "_", " ", -1) log.WithFields(log.Fields{ "old": act.Name, "new": newFile, }).Debug("Writing new action definition file") err = WriteActionDefinitionFile(act, newFile) if err != nil { return err } log.WithField("file", oldFile).Debug("Removing old file") os.Remove(oldFile) return nil }
func TestActionDefinitionFile(name string) bool { name = strings.Replace(name, " ", "_", -1) if util.GetFileByNameAndType("actions", name) == "" { return false } return true }
func RenameAction(do *definitions.Do) error { if do.Name == do.NewName { return fmt.Errorf("Cannot rename to same name") } do.Name = strings.Replace(do.Name, " ", "_", -1) do.NewName = strings.Replace(do.NewName, " ", "_", -1) act, _, err := LoadActionDefinition(do.Name) if err != nil { logger.Debugf("About to fail. Name:NewName =>\t%s:%s", do.Name, do.NewName) return err } do.Name = strings.Replace(do.Name, " ", "_", -1) logger.Debugf("About to find defFile =>\t%s\n", do.Name) oldFile := util.GetFileByNameAndType("actions", do.Name) if oldFile == "" { return fmt.Errorf("Could not find that action definition file.") } logger.Debugf("Found defFile at =>\t\t%s\n", oldFile) if !strings.Contains(oldFile, ActionsPath) { oldFile = filepath.Join(ActionsPath, oldFile) + ".toml" } var newFile string newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1) if newNameBase == do.Name { newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1) } else { newFile = strings.Replace(oldFile, do.Name, do.NewName, 1) newFile = strings.Replace(newFile, " ", "_", -1) } if newFile == oldFile { logger.Infoln("Those are the same file. Not renaming") return nil } act.Name = strings.Replace(newNameBase, "_", " ", -1) logger.Debugf("About to write new def file =>\t%s:%s\n", act.Name, newFile) err = WriteActionDefinitionFile(act, newFile) if err != nil { return err } logger.Debugf("Removing old file =>\t\t%s\n", oldFile) os.Remove(oldFile) return nil }
func RmAction(do *definitions.Do) error { do.Name = strings.Join(do.Args, "_") if do.File { oldFile := util.GetFileByNameAndType("actions", do.Name) if oldFile == "" { return nil } if !strings.Contains(oldFile, ActionsPath) { oldFile = filepath.Join(ActionsPath, oldFile) + ".toml" } logger.Debugf("Removing file =>\t\t%s\n", oldFile) os.Remove(oldFile) } return nil }
func exportFile(chainName string) (string, error) { fileName := util.GetFileByNameAndType("chains", chainName) var hash string var err error if logger.Level > 0 { hash, err = util.SendToIPFS(fileName, logger.Writer) } else { hash, err = util.SendToIPFS(fileName, bytes.NewBuffer([]byte{})) } if err != nil { return "", err } return hash, nil }
func exportFile(chainName string) (string, error) { fileName := util.GetFileByNameAndType("chains", chainName) var hash string var err error if log.GetLevel() > 0 { hash, err = ipfs.SendToIPFS(fileName, "", os.Stdout) } else { hash, err = ipfs.SendToIPFS(fileName, "", bytes.NewBuffer([]byte{})) } if err != nil { return "", err } return hash, nil }
func RmAction(do *definitions.Do) error { do.Name = strings.Join(do.Operations.Args, "_") if do.File { oldFile := util.GetFileByNameAndType("actions", do.Name) if oldFile == "" { return nil } // if !strings.Contains(oldFile, ActionsPath) { // oldFile = filepath.Join(ActionsPath, oldFile) + ".toml" // } log.WithField("file", oldFile).Debug("Removing file") os.Remove(oldFile) } return nil }
func exportFile(actionName string) (string, error) { var err error fileName := util.GetFileByNameAndType("actions", actionName) if fileName == "" { return "", fmt.Errorf("no file to export") } var hash string if logger.Level > 0 { hash, err = ipfs.SendToIPFS(fileName, "", logger.Writer) } else { hash, err = ipfs.SendToIPFS(fileName, "", bytes.NewBuffer([]byte{})) } if err != nil { return "", err } return hash, nil }
// XXX: What's going on here? => [csk]: magic func RenameChain(do *definitions.Do) error { if do.Name == do.NewName { return fmt.Errorf("Cannot rename to same name") } newNameBase := strings.Replace(do.NewName, filepath.Ext(do.NewName), "", 1) transformOnly := newNameBase == do.Name if util.IsKnownChain(do.Name) { log.WithFields(log.Fields{ "from": do.Name, "to": do.NewName, }).Info("Renaming chain") log.WithField("=>", do.Name).Debug("Loading chain definition file") chainDef, err := loaders.LoadChainDefinition(do.Name, false, 1) // TODO:CNUM if err != nil { return err } if !transformOnly { log.Debug("Renaming chain container") err = perform.DockerRename(chainDef.Operations, do.NewName) if err != nil { return err } } oldFile := util.GetFileByNameAndType("chains", do.Name) if err != nil { return err } if filepath.Base(oldFile) == do.NewName { log.Info("Those are the same file. Not renaming") return nil } log.Debug("Renaming chain definition file") var newFile string if filepath.Ext(do.NewName) == "" { newFile = strings.Replace(oldFile, do.Name, do.NewName, 1) } else { newFile = filepath.Join(ChainsPath, do.NewName) } chainDef.Name = newNameBase // Generally we won't want to use Service.Name // as it will be confused with the Name. chainDef.Service.Name = "" // Service.Image should be taken from the default.toml. chainDef.Service.Image = "" err = WriteChainDefinitionFile(chainDef, newFile) if err != nil { return err } if !transformOnly { log.WithFields(log.Fields{ "from": fmt.Sprintf("%s:%d", do.Name, chainDef.Operations.ContainerNumber), "to": fmt.Sprintf("%s:%d", do.NewName, chainDef.Operations.ContainerNumber), }).Info("Renaming chain data container") do.Operations.ContainerNumber = chainDef.Operations.ContainerNumber err = data.RenameData(do) if err != nil { return err } } os.Remove(oldFile) } else { return fmt.Errorf("I cannot find that chain. Please check the chain name you sent me.") } return nil }
func FindServiceDefinitionFile(name string) string { return util.GetFileByNameAndType("services", name) }
func EditAction(do *definitions.Do) error { actDefFile := util.GetFileByNameAndType("actions", do.Name) logger.Infof("Editing Action =>\t\t%s\n", actDefFile) do.Result = "success" return Editor(actDefFile) }
func EditAction(do *definitions.Do) error { actDefFile := util.GetFileByNameAndType("actions", do.Name) log.WithField("file", actDefFile).Info("Editing action") do.Result = "success" return Editor(actDefFile) }
func EditChain(do *definitions.Do) error { chainDefFile := util.GetFileByNameAndType("chains", do.Name) logger.Infof("Editing Service =>\t\t%s\n", chainDefFile) do.Result = "success" return Editor(chainDefFile) }
func EditChain(do *definitions.Do) error { chainDefFile := util.GetFileByNameAndType("chains", do.Name) log.WithField("file", chainDefFile).Info("Editing chain definition") do.Result = "success" return Editor(chainDefFile) }
// XXX: What's going on here? => [csk]: magic func RenameChain(do *definitions.Do) error { if do.Name == do.NewName { return fmt.Errorf("Cannot rename to same name") } newNameBase := strings.Replace(do.NewName, filepath.Ext(do.NewName), "", 1) transformOnly := newNameBase == do.Name if isKnownChain(do.Name) { logger.Infof("Renaming chain =>\t\t%s:%s\n", do.Name, do.NewName) logger.Debugf("Loading Chain Def File =>\t%s\n", do.Name) chainDef, err := loaders.LoadChainDefinition(do.Name, false, 1) // TODO:CNUM if err != nil { return err } if !transformOnly { logger.Debugln("Embarking on DockerRename.") err = perform.DockerRename(chainDef.Service, chainDef.Operations, do.Name, newNameBase) if err != nil { return err } } oldFile := util.GetFileByNameAndType("chains", do.Name) if err != nil { return err } if filepath.Base(oldFile) == do.NewName { logger.Infoln("Those are the same file. Not renaming") return nil } logger.Debugln("Renaming Chain Definition File.") var newFile string if filepath.Ext(do.NewName) == "" { newFile = strings.Replace(oldFile, do.Name, do.NewName, 1) } else { newFile = filepath.Join(BlockchainsPath, do.NewName) } chainDef.Name = newNameBase chainDef.Service.Name = "" chainDef.Service.Image = "" err = WriteChainDefinitionFile(chainDef, newFile) if err != nil { return err } if !transformOnly { logger.Infof("Renaming DataC (fm ChainRaw) =>\t%s:%s\n", do.Name, do.NewName) do.Operations.ContainerNumber = chainDef.Operations.ContainerNumber logger.Debugf("\twith ContainerNumber =>\t%d\n", do.Operations.ContainerNumber) err = data.RenameData(do) if err != nil { return err } } os.Remove(oldFile) } else { return fmt.Errorf("I cannot find that chain. Please check the chain name you sent me.") } return nil }