@@ -17,14 +17,15 @@ import (
17
17
"github.com/spf13/viper"
18
18
)
19
19
20
- // getDefaultConfig creates and returns a default configuration
21
- func getDefaultConfig (networkInfo network.Network ) * config.Config {
20
+ // CreateNewAppCore creates and returns a new instance of *core.Core
21
+ func CreateNewAppCore (networkInfo network.Network , eventManager event.Manager , debug bool ) (* Core , error ) {
22
+ configPath := viper .Get ("config-path" ).(string )
22
23
user := viper .Get ("user" ).(string )
23
24
identity := viper .Get ("default-ssh-identity" ).(string )
24
25
seed := time .Now ().UTC ().UnixNano ()
25
26
nameGenerator := namegenerator .NewNameGenerator (seed )
26
27
27
- return & config.Config {
28
+ defaultConf := config.Config {
28
29
Name : nameGenerator .Generate (),
29
30
SSH : config.SSHConfig {
30
31
User : user ,
@@ -34,13 +35,8 @@ func getDefaultConfig(networkInfo network.Network) *config.Config {
34
35
},
35
36
Interface : networkInfo .Interface ().Name ,
36
37
}
37
- }
38
-
39
- // CreateNewAppCore creates and returns a new instance of *core.Core
40
- func CreateNewAppCore (networkInfo network.Network , eventManager event.Manager , debug bool ) (* Core , error ) {
41
- configPath := viper .Get ("config-path" ).(string )
42
38
43
- configRepo , err := config .NewJSONRepo (configPath )
39
+ configRepo , err := config .NewJSONRepo (configPath , defaultConf )
44
40
45
41
if err != nil {
46
42
return nil , err
@@ -52,8 +48,7 @@ func CreateNewAppCore(networkInfo network.Network, eventManager event.Manager, d
52
48
53
49
if err != nil {
54
50
if errors .Is (err , exception .ErrRecordNotFound ) {
55
- conf = getDefaultConfig (networkInfo )
56
- conf , err = configService .Create (conf )
51
+ conf , err = configService .Create (& defaultConf )
57
52
if err != nil {
58
53
return nil , err
59
54
}
0 commit comments