Introduce TLS Settings for go-micro based http services
TLS for the services can be configure by setting the "OCIS_HTTP_TLS_ENABLED", "OCIS_HTTP_TLS_CERTIFICATE" and "OCIS_HTTP_TLS_KEY" environment variables. Currently the ocis proxy is this only service that directly accesses backend services. It determines whether to use TLS or not by looking a the new registry metadata "use_tls". As specific CA Cert for certificate verification can be set with the "PROXY_HTTPS_CACERT" environment variable.
This commit is contained in:
committed by
Ralf Haferkamp
parent
cbe41fb85f
commit
b24d126b30
@@ -1,6 +1,8 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/account"
|
||||
@@ -15,10 +17,11 @@ import (
|
||||
)
|
||||
|
||||
// Server initializes the http service and server.
|
||||
func Server(opts ...Option) http.Service {
|
||||
func Server(opts ...Option) (http.Service, error) {
|
||||
options := newOptions(opts...)
|
||||
|
||||
service := http.NewService(
|
||||
service, err := http.NewService(
|
||||
http.TLSConfig(options.Config.HTTP.TLS),
|
||||
http.Logger(options.Logger),
|
||||
http.Name(options.Name),
|
||||
http.Version(version.GetString()),
|
||||
@@ -27,6 +30,12 @@ func Server(opts ...Option) http.Service {
|
||||
http.Context(options.Context),
|
||||
http.Flags(options.Flags...),
|
||||
)
|
||||
if err != nil {
|
||||
options.Logger.Error().
|
||||
Err(err).
|
||||
Msg("Error initializing http service")
|
||||
return http.Service{}, fmt.Errorf("could not initialize http service: %w", err)
|
||||
}
|
||||
|
||||
handle := svc.NewService(options.Config, options.Logger)
|
||||
|
||||
@@ -81,5 +90,5 @@ func Server(opts ...Option) http.Service {
|
||||
|
||||
micro.RegisterHandler(service.Server(), mux)
|
||||
|
||||
return service
|
||||
return service, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user