forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
41 lines (33 loc) · 1.3 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package secrets
import (
"encoding/json"
"io/ioutil"
)
// SecretsManagerConfig is the configuration that gets
// written to a single configuration file
type SecretsManagerConfig struct {
Token string `json:"token"` // Access token to the instance
ServerURL string `json:"server_url"` // The URL of the running server
Type SecretsManagerType `json:"type"` // The type of SecretsManager
Name string `json:"name"` // The name of the current node
Namespace string `json:"namespace"` // The namespace of the service
Extra map[string]interface{} `json:"extra"` // Any kind of arbitrary data
}
// WriteConfig writes the current configuration to the specified path
func (c *SecretsManagerConfig) WriteConfig(path string) error {
jsonBytes, _ := json.MarshalIndent(c, "", " ")
return ioutil.WriteFile(path, jsonBytes, 0600)
}
// ReadConfig reads the SecretsManagerConfig from the specified path
func ReadConfig(path string) (*SecretsManagerConfig, error) {
configFile, readErr := ioutil.ReadFile(path)
if readErr != nil {
return nil, readErr
}
config := &SecretsManagerConfig{}
unmarshalErr := json.Unmarshal(configFile, &config)
if unmarshalErr != nil {
return nil, unmarshalErr
}
return config, nil
}