mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-27 15:09:31 -06:00
* Introduce TLS Settings for go-micro based grpc services and clients TLS for the services can be configure by setting the OCIS_MICRO_GRPC_TLS_ENABLED" "OCIS_MICRO_GRPC_TLS_CERTIFICATE" and "OCIS_MICRO_GRPC_TLS_KEY" enviroment variables. TLS for the clients can configured by setting the "OCIS_MICRO_GRPC_CLIENT_TLS_MODE" and "OCIS_MICRO_GRPC_CLIENT_TLS_CACERT" variables. By default TLS is disabled. Co-authored-by: Martin <github@diemattels.at> * Unify TLS configuration for all grpc services All grpc service (whether they're based on reva) or go-micro use the same set of config vars now. TLS for the services can be configure by setting the OCIS_GRPC_TLS_ENABLED, OCIS_GRPC_TLS_CERTIFICATE and OCIS_GRPC_TLS_KEY enviroment variables. TLS for the clients can configured by setting the OCIS_GRPC_CLIENT_TLS_MODE and OCIS_MICRO_GRPC_CLIENT_TLS_CACERT variables. There are no individual per service config vars currently. If really needed, per service tls configurations can be specified via config file. Co-authored-by: Martin <github@diemattels.at> Co-authored-by: Martin <github@diemattels.at>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package grpc
|
|
|
|
import (
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
storesvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/store/v0"
|
|
svc "github.com/owncloud/ocis/v2/services/store/pkg/service/v0"
|
|
)
|
|
|
|
// Server initializes a new go-micro service ready to run
|
|
func Server(opts ...Option) grpc.Service {
|
|
options := newOptions(opts...)
|
|
|
|
service, err := grpc.NewService(
|
|
grpc.TLSEnabled(options.Config.GRPC.TLS.Enabled),
|
|
grpc.TLSCert(
|
|
options.Config.GRPC.TLS.Cert,
|
|
options.Config.GRPC.TLS.Key,
|
|
),
|
|
grpc.Namespace(options.Config.GRPC.Namespace),
|
|
grpc.Name(options.Config.Service.Name),
|
|
grpc.Version(version.GetString()),
|
|
grpc.Context(options.Context),
|
|
grpc.Address(options.Config.GRPC.Addr),
|
|
grpc.Logger(options.Logger),
|
|
grpc.Flags(options.Flags...),
|
|
)
|
|
if err != nil {
|
|
options.Logger.Fatal().Err(err).Msg("Error creating store service")
|
|
return grpc.Service{}
|
|
}
|
|
|
|
hdlr, err := svc.New(
|
|
svc.Logger(options.Logger),
|
|
svc.Config(options.Config),
|
|
)
|
|
if err != nil {
|
|
options.Logger.Fatal().Err(err).Msg("could not initialize service handler")
|
|
}
|
|
if err = storesvc.RegisterStoreHandler(service.Server(), hdlr); err != nil {
|
|
options.Logger.Fatal().Err(err).Msg("could not register service handler")
|
|
}
|
|
|
|
return service
|
|
}
|