Generate certificates if they don't exist

This commit is contained in:
2021-12-08 20:32:10 +01:00
parent 2f7676b35e
commit 1732c2c389
8 changed files with 184 additions and 51 deletions

View File

@@ -149,7 +149,7 @@ func FromDefaultLocations() (*Config, error) {
return nil, fmt.Errorf("config not found")
}
func (c *Config) UpdateFromEnv() error {
func (c *Config) UpdateFromEnv() {
// Server stuff
if val, found := os.LookupEnv("EZSHARE_SERVER_LOGLEVEL"); found {
c.Server.LogLevel = val
@@ -207,8 +207,6 @@ func (c *Config) UpdateFromEnv() error {
if val, found := os.LookupEnv("EZSHARE_CLIENT_SERVERCERTPATH"); found {
c.Client.ServerCertPath = val
}
return nil
}
func (sc *ServerConfig) Valid() error {

View File

@@ -219,9 +219,7 @@ func TestConfig(t *testing.T) {
t.Errorf("Loglevel is WARN before updating from env.")
}
os.Setenv("EZSHARE_SERVER_LOGLEVEL", "WARN")
if err := cfg.UpdateFromEnv(); err != nil {
t.Fatalf("Error updating config from environment: %s", err)
}
cfg.UpdateFromEnv()
if cfg.Server.LogLevel != "WARN" {
t.Errorf("Loglevel is not WARN after updating from env.")
}
@@ -229,9 +227,7 @@ func TestConfig(t *testing.T) {
// Test Server.Hostname
hostname := "https://share.example.org"
os.Setenv("EZSHARE_SERVER_HOSTNAME", hostname)
if err := cfg.UpdateFromEnv(); err != nil {
t.Fatalf("Error updating config from environment: %s", err)
}
cfg.UpdateFromEnv()
if cfg.Server.Hostname != hostname {
t.Errorf("Hostname is incorrect after updating from env.")
}
@@ -239,9 +235,7 @@ func TestConfig(t *testing.T) {
// Test Server.Datastore.Bolt.Path
boltPath := "/data/bolt.db"
os.Setenv("EZSHARE_SERVER_DATASTORE_BOLT_PATH", boltPath)
if err := cfg.UpdateFromEnv(); err != nil {
t.Fatalf("Error updating config from environment: %s", err)
}
cfg.UpdateFromEnv()
if cfg.Server.DataStoreConfig.BoltStoreConfig.Path != boltPath {
t.Errorf("Bolt path is incorrect after updating from env.")
}
@@ -249,9 +243,7 @@ func TestConfig(t *testing.T) {
// Test Server.Datastore.Bolt.Path
caCertPath := "/data/cert.pem"
os.Setenv("EZSHARE_SERVER_GRPC_CACERTS_CERTIFICATEKEYPATH", caCertPath)
if err := cfg.UpdateFromEnv(); err != nil {
t.Fatalf("Error updating config from environment: %s", err)
}
cfg.UpdateFromEnv()
if cfg.Server.GRPC.CACerts.CertificateKeyPath != caCertPath {
t.Errorf("GPRC CA Cert path is incorrect after updating from env.")
}