-
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
9 changed files
with
147 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,33 @@ | ||
package dial | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tarantool/go-tarantool/v2" | ||
) | ||
|
||
func New(opts Opts) (tarantool.Dialer, error) { | ||
transport := ConvertTransport(opts.Transport) | ||
|
||
if transport == TransportDefault { | ||
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 ssl(opts) | ||
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,41 @@ | ||
package dial | ||
|
||
// 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" | ||
TransportInvalid Transport = "invalid" | ||
) | ||
|
||
func ConvertTransport(tr string) Transport { | ||
switch tr { | ||
case "": | ||
return TransportDefault | ||
case "plain": | ||
return TransportPlain | ||
case "ssl": | ||
return TransportSSL | ||
default: | ||
return TransportInvalid | ||
} | ||
} | ||
|
||
type Opts struct { | ||
Address string | ||
User string | ||
Password string | ||
SslKeyFile string | ||
SslCertFile string | ||
SslCaFile string | ||
SslCiphers string | ||
SslPassword string | ||
SslPasswordFile string | ||
Transport string | ||
} |
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,23 @@ | ||
//go:build !tt_ssl_disable | ||
// +build !tt_ssl_disable | ||
|
||
package dial | ||
|
||
import ( | ||
"github.com/tarantool/go-tarantool/v2" | ||
"github.com/tarantool/go-tlsdialer" | ||
) | ||
|
||
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 ssl(opts Opts) (tarantool.Dialer, error) { | ||
return nil, errors.New("SSL support is disabled") | ||
} |
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