Skip to content

Commit

Permalink
add config verification
Browse files Browse the repository at this point in the history
  • Loading branch information
gadost committed Feb 10, 2022
1 parent c221bab commit 6a6ca09
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func init() {
}

func BootstrapChainConf() {
if _, err := os.Stat(conf.UserHome + "/.telescope/conf.d/" + ChainName + ".toml"); !os.IsNotExist(err) {
fmt.Printf("config file for chain %s exits", ChainName)
os.Exit(1)
}
for {
fmt.Fprint(os.Stderr, "Add new chain "+ChainName+" ?(Y/n): ")
s, _ = r.ReadString('\n')
Expand Down
29 changes: 27 additions & 2 deletions cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package cmd
import (
"fmt"

"github.com/gadost/telescope/conf"
"github.com/gadost/telescope/watcher"
"github.com/spf13/cobra"
)

Expand All @@ -16,11 +18,34 @@ var verifyCmd = &cobra.Command{
Short: "verify configs",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("verify called")
Verify()
},
}

func init() {
configCmd.AddCommand(verifyCmd)
verifyCmd.Flags().StringVarP(&ChainName, "chain", "c", "", "Chain name")
verifyCmd.PersistentFlags().StringVarP(&c, "conf", "c", conf.UserHome+"/.telescope/conf.d", "Configurations directory")
}

func Verify() {
cfg, chains := conf.ConfLoad(c)
for _, chainName := range chains {
if cfg.Chain[chainName].Info.Github != "" {

repoInfo := watcher.Parse(cfg.Chain[chainName].Info.Github)
if repoInfo.Domain == "" || repoInfo.Owner == "" && repoInfo.RepoName == "" {
fmt.Printf("Can't parse %s as github repository", cfg.Chain[chainName].Info.Github)
}
}

for _, node := range cfg.Chain[chainName].Node {
if node.Role != "validator" && node.Role != "sentry" {
fmt.Printf("Can't parse node type %s , chain: %s", node.Role, chainName)
}
if node.RPC == "" {
fmt.Printf("empty RPC for node , chain: %s", chainName)
}
}
}

}

0 comments on commit 6a6ca09

Please sign in to comment.