Skip to content

Commit d6d88b3

Browse files
committed
Merge branch 'master' into feat/CI
2 parents 755ab42 + 35d516c commit d6d88b3

7 files changed

Lines changed: 38 additions & 11 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.14
1+
3.0.15

cmd/flag.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var (
2424
Value: "mainnet",
2525
Usage: "Network of your Darknode (default: mainnet)",
2626
}
27+
ConfigFlag = cli.StringFlag{
28+
Name: "config",
29+
Usage: "Path of the config file",
30+
}
2731
AddressFlag = cli.StringFlag{
2832
Name: "address",
2933
Usage: "Ethereum address you want to withdraw the tokens to",

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func main() {
4040
Usage: "Deploy a new Darknode",
4141
Flags: []cli.Flag{
4242
// General
43-
NameFlag, TagsFlag, NetworkFlag,
43+
NameFlag, TagsFlag, NetworkFlag, ConfigFlag,
4444
// AWS
4545
AwsFlag, AwsAccessKeyFlag, AwsSecretKeyFlag, AwsInstanceFlag, AwsRegionFlag, AwsProfileFlag,
4646
// Digital Ocean

cmd/provider/aws.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (p providerAws) Name() string {
6666
func (p providerAws) Deploy(ctx *cli.Context) error {
6767
name := ctx.String("name")
6868
tags := ctx.String("tags")
69+
config := ctx.String("config")
6970

7071
latestVersion, err := util.LatestStableRelease()
7172
if err != nil {
@@ -81,7 +82,7 @@ func (p providerAws) Deploy(ctx *cli.Context) error {
8182
if err != nil {
8283
return err
8384
}
84-
if err := initNode(name, tags, network); err != nil {
85+
if err := initNode(name, tags, network, config); err != nil {
8586
return err
8687
}
8788

cmd/provider/do.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (p providerDo) Name() string {
3232
func (p providerDo) Deploy(ctx *cli.Context) error {
3333
name := ctx.String("name")
3434
tags := ctx.String("tags")
35+
config := ctx.String("config")
3536

3637
latestVersion, err := util.LatestStableRelease()
3738
if err != nil {
@@ -47,7 +48,7 @@ func (p providerDo) Deploy(ctx *cli.Context) error {
4748
if err != nil {
4849
return err
4950
}
50-
if err := initNode(name, tags, network); err != nil {
51+
if err := initNode(name, tags, network, config); err != nil {
5152
return err
5253
}
5354

cmd/provider/gcp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (p providerGcp) Name() string {
7070
func (p providerGcp) Deploy(ctx *cli.Context) error {
7171
name := ctx.String("name")
7272
tags := ctx.String("tags")
73+
config := ctx.String("config")
7374

7475
latestVersion, err := util.LatestStableRelease()
7576
if err != nil {
@@ -89,7 +90,7 @@ func (p providerGcp) Deploy(ctx *cli.Context) error {
8990
if err != nil {
9091
return err
9192
}
92-
if err := initNode(name, tags, network); err != nil {
93+
if err := initNode(name, tags, network, config); err != nil {
9394
return err
9495
}
9596

cmd/provider/provider.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,40 @@ func GetProvider(name string) (string, error) {
8383
}
8484

8585
// initialise all files needed by deploying a new node
86-
func initNode(name, tags string, network darknode.Network) error {
86+
func initNode(name, tags string, network darknode.Network, configFile string) error {
8787
if err := initNodeDirectory(name, tags); err != nil {
8888
return err
8989
}
9090
if err := util.GenerateSshKeyAndWriteToDir(name); err != nil {
9191
return err
9292
}
9393

94-
// Generate a new config and write to a file.
95-
config, err := darknode.NewConfig(network)
96-
if err != nil {
97-
return err
94+
// Use given config for the new darknode
95+
var conf darknode.Config
96+
if configFile != "" {
97+
path, err := filepath.Abs(configFile)
98+
if err != nil{
99+
return errors.New("invalid config path")
100+
}
101+
102+
file, err := os.Open(path)
103+
if err != nil {
104+
return fmt.Errorf("cannot open config file, err = %v", err)
105+
}
106+
defer file.Close()
107+
108+
if err := json.NewDecoder(file).Decode(&conf); err != nil {
109+
return err
110+
}
111+
} else {
112+
var err error
113+
conf, err = darknode.NewConfig(network)
114+
if err != nil {
115+
return err
116+
}
98117
}
99-
configData, err := json.MarshalIndent(config, "", " ")
118+
119+
configData, err := json.MarshalIndent(conf, "", " ")
100120
if err != nil {
101121
return err
102122
}

0 commit comments

Comments
 (0)