Skip to content

Commit 74cf4a1

Browse files
committed
move pub/priv key pair in env.json
1 parent a4aee74 commit 74cf4a1

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ The public and private key pair can be generated using the go program inside the
5959
6060
```js
6161
{
62+
"private_key": "......",
63+
"public_key": "......",
6264
"primary_server": {
6365
"server_location": "http://localhost:4000",
6466
"api_key_id": "aa",
65-
"api_key": "bbb",
66-
"private_key": "......",
67-
"public_key": "......"
67+
"api_key": "bbb"
6868
},
6969
"alternative_servers": [
7070
// If you want to send CVs to multiple servers you can add additional servers here

examples/deno/env.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"private_key": "iCupcgnNmXrsaBoq3SLIs3uDAbEsYyOPecCn2FIFSIg=",
3+
"public_key": "6qw/E3STkmLouif4EUG5wqC2yzWbO4UvgYr7K0YHVyg=",
24
"primary_server": {
35
"server_location": "http://localhost:4000",
46
"api_key_id": "aa",

gen_key/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ func main() {
2020
fmt.Println(priv)
2121

2222
fmt.Println()
23-
fmt.Println("Add them here your scrapers `env.json` file using")
23+
fmt.Println("Add them like so to your scraper's `env.json`")
2424
envAddition, _ := json.MarshalIndent(map[string]any{
25-
"primary_server": map[string]string{
26-
"server_location": "..",
27-
"api_key_id": "..",
28-
"api_key": "..",
29-
"private_key": priv,
30-
"public_key": pub,
31-
},
25+
"private_key": priv,
26+
"public_key": pub,
27+
"primary_server": map[string]string{},
3228
}, "", " ")
3329
fmt.Println(string(envAddition))
3430

main.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616

1717
// Env contains the structure of the .env file
1818
type 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

Comments
 (0)