Allow updating config from env
This commit is contained in:
@@ -144,6 +144,68 @@ func FromDefaultLocations() (*Config, error) {
|
||||
return nil, fmt.Errorf("config not found")
|
||||
}
|
||||
|
||||
func (c *Config) UpdateFromEnv() error {
|
||||
// Server stuff
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_LOGLEVEL"); found {
|
||||
c.Server.LogLevel = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_HOSTNAME"); found {
|
||||
c.Server.Hostname = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_GRPCENDPOINT"); found {
|
||||
c.Server.GRPCEndpoint = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_DATASTORE_TYPE"); found {
|
||||
c.Server.DataStoreConfig.Type = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_DATASTORE_BOLT_PATH"); found {
|
||||
c.Server.DataStoreConfig.BoltStoreConfig.Path = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_FILESTORE_TYPE"); found {
|
||||
c.Server.FileStoreConfig.Type = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_FILESTORE_BOLT_PATH"); found {
|
||||
c.Server.FileStoreConfig.BoltStoreConfig.Path = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_FILESTORE_FILESYSTEM_DIR"); found {
|
||||
c.Server.FileStoreConfig.FSStoreConfig.Dir = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_GRPC_CACERTS_CERTIFICATEKEYPATH"); found {
|
||||
c.Server.GRPC.CACerts.CertificateKeyPath = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_GRPC_CACERTS_CERTIFICATEPATH"); found {
|
||||
c.Server.GRPC.CACerts.CertificatePath = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_GRPC_CERTS_CERTIFICATEKEYPATH"); found {
|
||||
c.Server.GRPC.Certs.CertificateKeyPath = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_GRPC_CERTS_CERTIFICATEPATH"); found {
|
||||
c.Server.GRPC.Certs.CertificatePath = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_GRPC_LISTENADDR"); found {
|
||||
c.Server.GRPC.ListenAddr = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_SERVER_HTTP_LISTENADDR"); found {
|
||||
c.Server.HTTP.ListenAddr = val
|
||||
}
|
||||
|
||||
// Client stuff
|
||||
if val, found := os.LookupEnv("EZSHARE_CLIENT_DEFAULTSERVER"); found {
|
||||
c.Client.DefaultServer = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_CLIENT_CERTS_CERTIFICATEKEYPATH"); found {
|
||||
c.Client.Certs.CertificateKeyPath = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_CLIENT_CERTS_CERTIFICATEPATH"); found {
|
||||
c.Client.Certs.CertificatePath = val
|
||||
}
|
||||
if val, found := os.LookupEnv("EZSHARE_CLIENT_SERVERCERTPATH"); found {
|
||||
c.Client.ServerCertPath = val
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) ValidForServer() error {
|
||||
// Verify that grpc-endpoint is set
|
||||
if c.Server.GRPCEndpoint == "" {
|
||||
|
Reference in New Issue
Block a user