mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-19 19:10:08 -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>
79 lines
2.4 KiB
Go
79 lines
2.4 KiB
Go
package grpc
|
|
|
|
import (
|
|
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
thumbnailssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/thumbnails/v0"
|
|
svc "github.com/owncloud/ocis/v2/services/thumbnails/pkg/service/grpc/v0"
|
|
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/service/grpc/v0/decorators"
|
|
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/thumbnail/imgsource"
|
|
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/thumbnail/storage"
|
|
)
|
|
|
|
// NewService initializes the grpc service and server.
|
|
func NewService(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.Logger(options.Logger),
|
|
grpc.Namespace(options.Namespace),
|
|
grpc.Name(options.Name),
|
|
grpc.Version(version.GetString()),
|
|
grpc.Address(options.Address),
|
|
grpc.Context(options.Context),
|
|
grpc.Flags(options.Flags...),
|
|
grpc.Version(version.GetString()),
|
|
)
|
|
if err != nil {
|
|
options.Logger.Fatal().Err(err).Msg("Error creating thumbnail service")
|
|
return grpc.Service{}
|
|
}
|
|
|
|
tconf := options.Config.Thumbnail
|
|
tm, err := pool.StringToTLSMode(options.Config.GRPCClientTLS.Mode)
|
|
if err != nil {
|
|
options.Logger.Error().Err(err).Msg("could not get gateway client tls mode")
|
|
return grpc.Service{}
|
|
}
|
|
gc, err := pool.GetGatewayServiceClient(tconf.RevaGateway,
|
|
pool.WithTLSCACert(options.Config.GRPCClientTLS.CACert),
|
|
pool.WithTLSMode(tm),
|
|
)
|
|
if err != nil {
|
|
options.Logger.Error().Err(err).Msg("could not get gateway client")
|
|
return grpc.Service{}
|
|
}
|
|
var thumbnail decorators.DecoratedService
|
|
{
|
|
thumbnail = svc.NewService(
|
|
svc.Config(options.Config),
|
|
svc.Logger(options.Logger),
|
|
svc.ThumbnailSource(imgsource.NewWebDavSource(tconf)),
|
|
svc.ThumbnailStorage(
|
|
storage.NewFileSystemStorage(
|
|
tconf.FileSystemStorage,
|
|
options.Logger,
|
|
),
|
|
),
|
|
svc.CS3Source(imgsource.NewCS3Source(tconf, gc)),
|
|
svc.CS3Client(gc),
|
|
)
|
|
thumbnail = decorators.NewInstrument(thumbnail, options.Metrics)
|
|
thumbnail = decorators.NewLogging(thumbnail, options.Logger)
|
|
thumbnail = decorators.NewTracing(thumbnail)
|
|
}
|
|
|
|
_ = thumbnailssvc.RegisterThumbnailServiceHandler(
|
|
service.Server(),
|
|
thumbnail,
|
|
)
|
|
|
|
return service
|
|
}
|