@@ -16,6 +16,8 @@ import (
1616
1717// Env contains the structure of the .env file
1818type Env struct {
19+ PrivateKey string `json:"private_key"`
20+ PublicKey string `json:"public_key"`
1921 PrimaryServer EnvServer `json:"primary_server"`
2022 AlternativeServers []EnvServer `json:"alternative_servers"`
2123 MockMode bool `json:"mock_mode"`
@@ -34,18 +36,27 @@ func (e *Env) validate() error {
3436 return nil
3537 }
3638
37- err := e .PrimaryServer .validate (true )
39+ err := e .PrimaryServer .validate ()
3840 if err != nil {
3941 return fmt .Errorf ("primary_server.%s" , err .Error ())
4042 }
4143
4244 for idx , server := range e .AlternativeServers {
43- err := server .validate (false )
45+ err := server .validate ()
4446 if err != nil {
4547 return fmt .Errorf ("%s[%d].%s" , "alternative_servers" , idx , err .Error ())
4648 }
4749 }
4850
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+
4960 return nil
5061}
5162
@@ -54,11 +65,9 @@ type EnvServer struct {
5465 ServerLocation string `json:"server_location"`
5566 APIKeyID string `json:"api_key_id"`
5667 APIKey string `json:"api_key"`
57- PrivateKey string `json:"private_key"`
58- PublicKey string `json:"public_key"`
5968}
6069
61- func (e * EnvServer ) validate (isPrimary bool ) error {
70+ func (e * EnvServer ) validate () error {
6271 if e .ServerLocation == "" {
6372 return errors .New ("server_location is required" )
6473 }
@@ -68,23 +77,6 @@ func (e *EnvServer) validate(isPrimary bool) error {
6877 if e .APIKey == "" {
6978 return errors .New ("api_key is required" )
7079 }
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- }
8880
8981 return nil
9082}
@@ -120,7 +112,7 @@ func main() {
120112 }
121113 envFile = []byte (os .Getenv (envEnvName ))
122114 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 )
124116 }
125117 }
126118
@@ -148,7 +140,7 @@ func main() {
148140 if err != nil {
149141 log .Fatal (err )
150142 }
151- decryptionKey := crypto .LoadAndVerivyKeys (env .PrimaryServer . PublicKey , env . PrimaryServer .PrivateKey )
143+ decryptionKey := crypto .LoadAndVerivyKeys (env .PublicKey , env .PrivateKey )
152144
153145 fmt .Println ("credentials set" )
154146 fmt .Println ("testing connections.." )
0 commit comments