@@ -16,6 +16,8 @@ import (
16
16
17
17
// Env contains the structure of the .env file
18
18
type Env struct {
19
+ PrivateKey string `json:"private_key"`
20
+ PublicKey string `json:"public_key"`
19
21
PrimaryServer EnvServer `json:"primary_server"`
20
22
AlternativeServers []EnvServer `json:"alternative_servers"`
21
23
MockMode bool `json:"mock_mode"`
@@ -34,18 +36,27 @@ func (e *Env) validate() error {
34
36
return nil
35
37
}
36
38
37
- err := e .PrimaryServer .validate (true )
39
+ err := e .PrimaryServer .validate ()
38
40
if err != nil {
39
41
return fmt .Errorf ("primary_server.%s" , err .Error ())
40
42
}
41
43
42
44
for idx , server := range e .AlternativeServers {
43
- err := server .validate (false )
45
+ err := server .validate ()
44
46
if err != nil {
45
47
return fmt .Errorf ("%s[%d].%s" , "alternative_servers" , idx , err .Error ())
46
48
}
47
49
}
48
50
51
+ keyPairHelpMsg := `, use the go program inside the "gen_key" folder to generate a key pair`
52
+ if e .PrivateKey == "" && e .PublicKey == "" {
53
+ return errors .New (`"public_key" and "private_key" are required` + keyPairHelpMsg )
54
+ } else if e .PrivateKey == "" {
55
+ return errors .New (`"private_key" required` + keyPairHelpMsg )
56
+ } else if e .PublicKey == "" {
57
+ return errors .New (`"public_key" required` + keyPairHelpMsg )
58
+ }
59
+
49
60
return nil
50
61
}
51
62
@@ -54,11 +65,9 @@ type EnvServer struct {
54
65
ServerLocation string `json:"server_location"`
55
66
APIKeyID string `json:"api_key_id"`
56
67
APIKey string `json:"api_key"`
57
- PrivateKey string `json:"private_key"`
58
- PublicKey string `json:"public_key"`
59
68
}
60
69
61
- func (e * EnvServer ) validate (isPrimary bool ) error {
70
+ func (e * EnvServer ) validate () error {
62
71
if e .ServerLocation == "" {
63
72
return errors .New ("server_location is required" )
64
73
}
@@ -68,23 +77,6 @@ func (e *EnvServer) validate(isPrimary bool) error {
68
77
if e .APIKey == "" {
69
78
return errors .New ("api_key is required" )
70
79
}
71
- if isPrimary {
72
- if e .PrivateKey == "" && e .PublicKey == "" {
73
- return errors .New (`"public_key" and "private_key" required by "primary_server"` )
74
- } else if e .PrivateKey == "" {
75
- return errors .New (`"private_key" required by "primary_server"` )
76
- } else if e .PublicKey == "" {
77
- return errors .New (`"public_key" required by "primary_server"` )
78
- }
79
- } else {
80
- if e .PrivateKey != "" && e .PublicKey != "" {
81
- fmt .Println ("WARN: public_key and private_key pairs are not used by alternative servers" )
82
- } else if e .PrivateKey != "" {
83
- fmt .Println ("WARN: private_key not used by alternative servers" )
84
- } else if e .PublicKey != "" {
85
- fmt .Println ("WARN: public_key not used by alternative servers" )
86
- }
87
- }
88
80
89
81
return nil
90
82
}
@@ -120,7 +112,7 @@ func main() {
120
112
}
121
113
envFile = []byte (os .Getenv (envEnvName ))
122
114
if len (envFile ) == 0 {
123
- log .Fatalf ("no %s file or %s envourment variable found, cannot continue" , envFilename , envEnvName )
115
+ log .Fatalf ("no %s file or %s environment variable found, cannot continue" , envFilename , envEnvName )
124
116
}
125
117
}
126
118
@@ -148,7 +140,7 @@ func main() {
148
140
if err != nil {
149
141
log .Fatal (err )
150
142
}
151
- decryptionKey := crypto .LoadAndVerivyKeys (env .PrimaryServer . PublicKey , env . PrimaryServer .PrivateKey )
143
+ decryptionKey := crypto .LoadAndVerivyKeys (env .PublicKey , env .PrivateKey )
152
144
153
145
fmt .Println ("credentials set" )
154
146
fmt .Println ("testing connections.." )
0 commit comments