-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
146 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ run: | |
timeout: 3m | ||
build-tags: | ||
- go_tarantool_ssl_disable | ||
- tt_ssl_disable | ||
|
||
linters: | ||
disable-all: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package dial | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tarantool/go-tarantool/v2" | ||
) | ||
|
||
// Transport is a type, with a restriction on the list of supported connection modes. | ||
type Transport string | ||
|
||
func (t Transport) String() string { | ||
return string(t) | ||
} | ||
|
||
const ( | ||
TransportDefault Transport = "" | ||
TransportPlain Transport = "plain" | ||
TransportSSL Transport = "ssl" | ||
) | ||
|
||
type Opts struct { | ||
Address string | ||
User string | ||
Password string | ||
SslKeyFile string | ||
SslCertFile string | ||
SslCaFile string | ||
SslCiphers string | ||
SslPassword string | ||
SslPasswordFile string | ||
Transport string | ||
} | ||
|
||
// dial creates dialer according to the opts.Transport | ||
func Dial(opts Opts) (tarantool.Dialer, error) { | ||
transport := TransportDefault | ||
if opts.Transport == TransportDefault.String() { | ||
if opts.SslKeyFile != "" || opts.SslCaFile != "" || opts.SslCertFile != "" || | ||
opts.SslCiphers != "" || opts.SslPassword != "" || opts.SslPasswordFile != "" { | ||
transport = TransportSSL | ||
} else { | ||
transport = TransportPlain | ||
} | ||
} | ||
|
||
switch transport { | ||
case TransportPlain: | ||
return tarantool.NetDialer{ | ||
Address: opts.Address, | ||
User: opts.User, | ||
Password: opts.Password, | ||
}, nil | ||
case TransportSSL: | ||
return New(Opts{ | ||
Address: opts.Address, | ||
User: opts.User, | ||
Password: opts.Password, | ||
SslKeyFile: opts.SslKeyFile, | ||
SslCertFile: opts.SslCertFile, | ||
SslCaFile: opts.SslCaFile, | ||
SslCiphers: opts.SslCiphers, | ||
SslPassword: opts.SslPassword, | ||
SslPasswordFile: opts.SslPasswordFile, | ||
}) | ||
default: | ||
return nil, fmt.Errorf("unsupported transport type: %s", opts.Transport) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !tt_ssl_disable | ||
// +build !tt_ssl_disable | ||
|
||
package dial | ||
|
||
import ( | ||
"github.com/tarantool/go-tarantool/v2" | ||
"github.com/tarantool/go-tlsdialer" | ||
) | ||
|
||
func New(opts Opts) (tarantool.Dialer, error) { | ||
return ssl(opts) | ||
} | ||
|
||
func ssl(opts Opts) (tarantool.Dialer, error) { | ||
return tlsdialer.OpenSSLDialer{ | ||
Address: opts.Address, | ||
User: opts.User, | ||
Password: opts.Password, | ||
SslKeyFile: opts.SslKeyFile, | ||
SslCertFile: opts.SslCertFile, | ||
SslCaFile: opts.SslCaFile, | ||
SslCiphers: opts.SslCiphers, | ||
SslPassword: opts.SslPassword, | ||
SslPasswordFile: opts.SslPasswordFile, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build tt_ssl_disable | ||
// +build tt_ssl_disable | ||
|
||
package dial | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/tarantool/go-tarantool/v2" | ||
) | ||
|
||
func New(opts Opts) (tarantool.Dialer, error) { | ||
return nil, errors.New("SSL support is disabled.") | ||
Check failure on line 13 in lib/dial/ssl_disable.go
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters