@@ -24,45 +24,46 @@ import (
2424type Config struct {
2525 config.Common
2626
27- trace trace.Driver
28- dialTimeout time.Duration
29- connectionTTL time.Duration
30- balancer balancer.Balancer
31- secure bool
32- endpoint string
33- database string
34- requestsType string
35- userAgent string
27+ trace trace.Driver
28+ dialTimeout time.Duration
29+ connectionTTL time.Duration
30+ balancer balancer.Balancer
31+ secure bool
32+ endpoint string
33+ database string
34+ requestsType string
35+ userAgent string
36+ grpcOptions []grpc.DialOption
37+ credentials credentials.Credentials
38+ tlsConfig * tls.Config
39+ meta meta.Meta
40+
3641 excludeGRPCCodesForPessimization []grpcCodes.Code
37- grpcOptions []grpc.DialOption
38- credentials credentials.Credentials
39- tlsConfig * tls.Config
40- meta meta.Meta
4142}
4243
4344// ExcludeGRPCCodesForPessimization defines grpc codes for exclude its from pessimization trigger
4445func (c Config ) ExcludeGRPCCodesForPessimization () []grpcCodes.Code {
4546 return c .excludeGRPCCodesForPessimization
4647}
4748
48- // GrpcDialOptions is an custom client grpc dial options which will appends to
49- // default grpc dial options
49+ // GrpcDialOptions reports about used grpc dialing options
5050func (c Config ) GrpcDialOptions () []grpc.DialOption {
5151 return c .grpcOptions
5252}
5353
54- // Meta is an internal option which contains meta information about database connection
54+ // Meta reports meta information about database connection
5555func (c Config ) Meta () meta.Meta {
5656 return c .meta
5757}
5858
59- // ConnectionTTL is a time to live of a connection
60- // If ConnectionTTL is zero then TTL is not used.
59+ // ConnectionTTL defines interval for parking grpc connections.
60+ //
61+ // If ConnectionTTL is zero - connections are not park.
6162func (c Config ) ConnectionTTL () time.Duration {
6263 return c .connectionTTL
6364}
6465
65- // Secure is an flag for secure connection
66+ // Secure is a flag for secure connection
6667func (c Config ) Secure () bool {
6768 return c .secure
6869}
@@ -72,6 +73,7 @@ func (c Config) Endpoint() string {
7273 return c .endpoint
7374}
7475
76+ // TLSConfig reports about TLS configuration
7577func (c Config ) TLSConfig () * tls.Config {
7678 return c .tlsConfig
7779}
@@ -89,7 +91,7 @@ func (c Config) Database() string {
8991 return c .database
9092}
9193
92- // Credentials is an ydb client credentials.
94+ // Credentials is a ydb client credentials.
9395// In most cases Credentials are required.
9496func (c Config ) Credentials () credentials.Credentials {
9597 return c .credentials
@@ -116,7 +118,7 @@ type Option func(c *Config)
116118
117119// WithInternalDNSResolver
118120//
119- // Deprecated: already used internal dns-resolver
121+ // Deprecated: always used internal dns-resolver
120122func WithInternalDNSResolver () Option {
121123 return func (c * Config ) {}
122124}
@@ -127,6 +129,9 @@ func WithEndpoint(endpoint string) Option {
127129 }
128130}
129131
132+ // WithSecure changes secure connection flag.
133+ //
134+ // Warning: if secure is false - TLS config options has no effect.
130135func WithSecure (secure bool ) Option {
131136 return func (c * Config ) {
132137 c .secure = secure
@@ -139,12 +144,22 @@ func WithDatabase(database string) Option {
139144 }
140145}
141146
147+ // WithCertificate appends certificate to TLS config root certificates
142148func WithCertificate (certificate * x509.Certificate ) Option {
143149 return func (c * Config ) {
144150 c .tlsConfig .RootCAs .AddCert (certificate )
145151 }
146152}
147153
154+ // WithTLSConfig replaces older TLS config
155+ //
156+ // Warning: all early changes of TLS config will be lost
157+ func WithTLSConfig (tlsConfig * tls.Config ) Option {
158+ return func (c * Config ) {
159+ c .tlsConfig = tlsConfig
160+ }
161+ }
162+
148163func WithTrace (t trace.Driver , opts ... trace.DriverComposeOption ) Option {
149164 return func (c * Config ) {
150165 c .trace = c .trace .Compose (t , opts ... )
@@ -218,12 +233,14 @@ func WithRequestsType(requestsType string) Option {
218233 }
219234}
220235
236+ // WithMinTLSVersion applies minimum TLS version that is acceptable.
221237func WithMinTLSVersion (minVersion uint16 ) Option {
222238 return func (c * Config ) {
223239 c .tlsConfig .MinVersion = minVersion
224240 }
225241}
226242
243+ // WithTLSSInsecureSkipVerify applies InsecureSkipVerify flag to TLS config
227244func WithTLSSInsecureSkipVerify () Option {
228245 return func (c * Config ) {
229246 c .tlsConfig .InsecureSkipVerify = true
@@ -267,32 +284,28 @@ func New(opts ...Option) Config {
267284 return c
268285}
269286
270- func certPool () (certPool * x509.CertPool ) {
271- defer func () {
272- // on darwin system panic raced on checking system security
273- if e := recover (); e != nil {
274- certPool = x509 .NewCertPool ()
275- }
276- }()
277- var err error
278- certPool , err = x509 .SystemCertPool ()
279- if err != nil {
280- certPool = x509 .NewCertPool ()
287+ func certPool () * x509.CertPool {
288+ certPool , err := x509 .SystemCertPool ()
289+ if err == nil {
290+ return certPool
291+ }
292+ return x509 .NewCertPool ()
293+ }
294+
295+ func defaultTLSConfig () * tls.Config {
296+ return & tls.Config {
297+ MinVersion : tls .VersionTLS12 ,
298+ RootCAs : certPool (),
281299 }
282- return
283300}
284301
285302func defaultConfig () (c Config ) {
286303 return Config {
287304 credentials : credentials .NewAnonymousCredentials (
288305 credentials .WithSourceInfo ("default" ),
289306 ),
290- balancer : balancers .Default (),
291- secure : true ,
292- tlsConfig : & tls.Config {
293- MinVersion : tls .VersionTLS12 ,
294- RootCAs : certPool (),
295- },
307+ balancer : balancers .Default (),
308+ tlsConfig : defaultTLSConfig (),
296309 grpcOptions : []grpc.DialOption {
297310 grpc .WithContextDialer (
298311 func (ctx context.Context , address string ) (net.Conn , error ) {
0 commit comments