Skip to content

Commit

Permalink
Merge pull request #52 from renproject/release/v3.0.6
Browse files Browse the repository at this point in the history
v3.0.6
  • Loading branch information
Yunshi Sun committed Feb 24, 2020
2 parents e99b315 + 3adc871 commit 13eafa8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.5
3.0.6
11 changes: 8 additions & 3 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"
"io/ioutil"
"path/filepath"
"sync/atomic"

"github.com/fatih/color"
"github.com/renproject/darknode-cli/cmd/provider"
"github.com/renproject/darknode-cli/util"
"github.com/renproject/phi"
Expand All @@ -20,7 +22,7 @@ func listAllNodes(ctx *cli.Context) error {
}

nodes := make([][]string, len(nodesNames))
errs := map[string]error{}
var errs int64
phi.ParForAll(nodesNames, func(i int) {
name := nodesNames[i]
var err error
Expand Down Expand Up @@ -49,10 +51,13 @@ func listAllNodes(ctx *cli.Context) error {
return []string{name, id.String(), ip, provider, string(tags), ethAddr.Hex()}, nil
}()
if err != nil {
errs[name] = err
color.Red("[%v] cannot get detail of the darknode, err = %v", name, err)
atomic.AddInt64(&errs, 1)
}
})
if len(errs) == len(nodesNames) {

// Check if we can find any valid nodes.
if atomic.LoadInt64(&errs) == int64(len(nodesNames)) {
return fmt.Errorf("cannot find any node")
}

Expand Down
1 change: 0 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func checkUpdates(curVer string) {
client := github.NewClient(nil)
release, _, err := client.Repositories.GetLatestRelease(ctx, "renproject", "darknode-cli")
if err != nil {
color.Red("cannot check latest release, err = %v", err)
return
}

Expand Down
3 changes: 1 addition & 2 deletions darknode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func NewConfig(network Network) (Config, error) {
// all versions of darknode configs.
type GeneralConfig struct {
// Private configuration
Keystore keystore.Keystore `json:"keystore"`
ECDSADistKeyShare ECDSADistKeyShare `json:"ecdsaDistKeyShare"`
Keystore keystore.Keystore `json:"keystore"`

// Public configuration
Network Network `json:"network"`
Expand Down
25 changes: 14 additions & 11 deletions util/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func ValidateNodeName(name string) error {
}

// Config returns the config of the node with given name.
func Config(name string) (darknode.GeneralConfig, error){
func Config(name string) (darknode.GeneralConfig, error) {
path := filepath.Join(NodePath(name), "config.json")
return darknode.NewConfigFromJSONFile(path)
}
Expand Down Expand Up @@ -118,21 +118,14 @@ func GetNodesByTags(tags string) ([]string, error) {
if err != nil {
return nil, err
}
ts := strings.Split(strings.TrimSpace(tags), ",")
nodes := make([]string, 0)
for _, f := range files {
tagFile := filepath.Join(Directory, "darknodes", f.Name(), "tags.out")
tags, err := ioutil.ReadFile(tagFile)
path := filepath.Join(Directory, "darknodes", f.Name(), "tags.out")
tagFile, err := ioutil.ReadFile(path)
if err != nil {
continue
}
haveAllTags := true
for i := range ts {
if !strings.Contains(string(tags), ts[i]) {
haveAllTags = false
}
}
if !haveAllTags {
if !ValidateTags(string(tagFile), tags) {
continue
}

Expand All @@ -145,6 +138,16 @@ func GetNodesByTags(tags string) ([]string, error) {
return nodes, nil
}

func ValidateTags(have, required string) bool {
tagsStr := strings.Split(strings.TrimSpace(required), ",")
for _, tag := range tagsStr {
if !strings.Contains(have, tag) {
return false
}
}
return true
}

func isDeployed(name string) bool {
path := NodePath(name)
script := fmt.Sprintf("cd %v && terraform output ip", path)
Expand Down
2 changes: 1 addition & 1 deletion util/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NodePath(name string) string {

// BackUpConfig copies the config file of the node to the backup folder under
// .darknode directory in case something unexpected happens.
func BackUpConfig(name string) error{
func BackUpConfig(name string) error {
path := NodePath(name)
backupFolder := filepath.Join(Directory, "backup", name)
if err := Run("mkdir", "-p", backupFolder); err != nil {
Expand Down

0 comments on commit 13eafa8

Please sign in to comment.