mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-23 04:28:48 -05:00
Merge branch 'master' into no-additional-init
This commit is contained in:
@@ -5,9 +5,8 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/asim/go-micro/v3"
|
||||
|
||||
pkgcrypto "github.com/owncloud/ocis/ocis-pkg/crypto"
|
||||
svc "github.com/owncloud/ocis/ocis-pkg/service/http"
|
||||
"github.com/owncloud/ocis/proxy/pkg/crypto"
|
||||
)
|
||||
|
||||
// Server initializes the http service and server.
|
||||
@@ -17,25 +16,19 @@ func Server(opts ...Option) (svc.Service, error) {
|
||||
httpCfg := options.Config.HTTP
|
||||
|
||||
var cer tls.Certificate
|
||||
var certErr error
|
||||
|
||||
var tlsConfig *tls.Config
|
||||
if options.Config.HTTP.TLS {
|
||||
if httpCfg.TLSCert == "" || httpCfg.TLSKey == "" {
|
||||
l.Warn().Msgf("No tls certificate provided, using a generated one")
|
||||
_, certErr := os.Stat("./server.crt")
|
||||
_, keyErr := os.Stat("./server.key")
|
||||
l.Warn().Msgf("No tls certificate provided, using a generated one")
|
||||
_, certErr := os.Stat(httpCfg.TLSCert)
|
||||
_, keyErr := os.Stat(httpCfg.TLSKey)
|
||||
|
||||
if os.IsNotExist(certErr) || os.IsNotExist(keyErr) {
|
||||
// GenCert has side effects as it writes 2 files to the binary running location
|
||||
if err := crypto.GenCert(l); err != nil {
|
||||
l.Fatal().Err(err).Msgf("Could not generate test-certificate")
|
||||
os.Exit(1)
|
||||
}
|
||||
if os.IsNotExist(certErr) || os.IsNotExist(keyErr) {
|
||||
// GenCert has side effects as it writes 2 files to the binary running location
|
||||
if err := pkgcrypto.GenCert(httpCfg.TLSCert, httpCfg.TLSKey, l); err != nil {
|
||||
l.Fatal().Err(err).Msgf("Could not generate test-certificate")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
httpCfg.TLSCert = "server.crt"
|
||||
httpCfg.TLSKey = "server.key"
|
||||
}
|
||||
|
||||
cer, certErr = tls.LoadX509KeyPair(httpCfg.TLSCert, httpCfg.TLSKey)
|
||||
@@ -44,7 +37,7 @@ func Server(opts ...Option) (svc.Service, error) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
tlsConfig = &tls.Config{Certificates: []tls.Certificate{cer}}
|
||||
tlsConfig = &tls.Config{MinVersion: tls.VersionTLS12, Certificates: []tls.Certificate{cer}}
|
||||
}
|
||||
chain := options.Middlewares.Then(options.Handler)
|
||||
|
||||
@@ -59,7 +52,9 @@ func Server(opts ...Option) (svc.Service, error) {
|
||||
svc.Flags(options.Flags...),
|
||||
)
|
||||
|
||||
micro.RegisterHandler(service.Server(), chain)
|
||||
if err := micro.RegisterHandler(service.Server(), chain); err != nil {
|
||||
return svc.Service{}, err
|
||||
}
|
||||
|
||||
return service, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user