github.com/cs3org/reva/v2@v2.27.7/pkg/rgrpc/todo/pool/option.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package pool 20 21 import ( 22 "github.com/cs3org/reva/v2/pkg/sharedconf" 23 rtrace "github.com/cs3org/reva/v2/pkg/trace" 24 "go-micro.dev/v4/registry" 25 "go.opentelemetry.io/otel/trace" 26 ) 27 28 // Option is used to pass client options 29 type Option func(opts *ClientOptions) 30 31 // ClientOptions represent additional options (e.g. tls settings) for the grpc clients 32 type ClientOptions struct { 33 tlsMode TLSMode 34 caCert string 35 tracerProvider trace.TracerProvider 36 registry registry.Registry 37 } 38 39 func (o *ClientOptions) init() error { 40 // default to shared settings 41 sharedOpt := sharedconf.GRPCClientOptions() 42 var err error 43 44 if o.tlsMode, err = StringToTLSMode(sharedOpt.TLSMode); err != nil { 45 return err 46 } 47 o.caCert = sharedOpt.CACertFile 48 o.tracerProvider = rtrace.DefaultProvider() 49 return nil 50 } 51 52 // WithTLSMode allows to set the TLSMode option for grpc clients 53 func WithTLSMode(v TLSMode) Option { 54 return func(o *ClientOptions) { 55 o.tlsMode = v 56 } 57 } 58 59 // WithTLSCACert allows to set the CA Certificate for grpc clients 60 func WithTLSCACert(v string) Option { 61 return func(o *ClientOptions) { 62 o.caCert = v 63 } 64 } 65 66 // WithTracerProvider allows to set the opentelemetry tracer provider for grpc clients 67 func WithTracerProvider(v trace.TracerProvider) Option { 68 return func(o *ClientOptions) { 69 o.tracerProvider = v 70 } 71 } 72 73 // WithRegistry allows to set the registry for service lookup 74 func WithRegistry(v registry.Registry) Option { 75 return func(o *ClientOptions) { 76 o.registry = v 77 } 78 }