-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: move url parsing to connect package
Moves the common URL parsing logic from the `cmd` package to the `connect` package. Part of #TNTP-1081
- Loading branch information
Showing
12 changed files
with
280 additions
and
253 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package connect | ||
|
||
import libcluster "github.com/tarantool/tt/lib/cluster" | ||
|
||
// MakeEtcdOptsFromUriOpts create etcd connect options from URI options. | ||
func MakeEtcdOptsFromUriOpts(src UriOpts) libcluster.EtcdOpts { | ||
var endpoints []string | ||
if src.Endpoint != "" { | ||
endpoints = []string{src.Endpoint} | ||
} | ||
|
||
return libcluster.EtcdOpts{ | ||
Endpoints: endpoints, | ||
Username: src.Username, | ||
Password: src.Password, | ||
KeyFile: src.KeyFile, | ||
CertFile: src.CertFile, | ||
CaPath: src.CaPath, | ||
CaFile: src.CaFile, | ||
SkipHostVerify: src.SkipHostVerify || src.SkipPeerVerify, | ||
Timeout: src.Timeout, | ||
} | ||
} |
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,91 @@ | ||
package connect_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
libcluster "github.com/tarantool/tt/lib/cluster" | ||
"github.com/tarantool/tt/lib/connect" | ||
) | ||
|
||
func TestMakeEtcdOptsFromUriOpts(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
UriOpts connect.UriOpts | ||
Expected libcluster.EtcdOpts | ||
}{ | ||
{ | ||
Name: "empty", | ||
UriOpts: connect.UriOpts{}, | ||
Expected: libcluster.EtcdOpts{}, | ||
}, | ||
{ | ||
Name: "ignored", | ||
UriOpts: connect.UriOpts{ | ||
Host: "foo", | ||
Prefix: "foo", | ||
Key: "bar", | ||
Instance: "zoo", | ||
Ciphers: "foo:bar:ciphers", | ||
}, | ||
Expected: libcluster.EtcdOpts{}, | ||
}, | ||
{ | ||
Name: "skip_host_verify", | ||
UriOpts: connect.UriOpts{ | ||
SkipHostVerify: true, | ||
}, | ||
Expected: libcluster.EtcdOpts{ | ||
SkipHostVerify: true, | ||
}, | ||
}, | ||
{ | ||
Name: "skip_peer_verify", | ||
UriOpts: connect.UriOpts{ | ||
SkipPeerVerify: true, | ||
}, | ||
Expected: libcluster.EtcdOpts{ | ||
SkipHostVerify: true, | ||
}, | ||
}, | ||
{ | ||
Name: "full", | ||
UriOpts: connect.UriOpts{ | ||
Endpoint: "foo", | ||
Host: "host", | ||
Prefix: "prefix", | ||
Key: "key", | ||
Instance: "instance", | ||
Username: "username", | ||
Password: "password", | ||
KeyFile: "key_file", | ||
CertFile: "cert_file", | ||
CaPath: "ca_path", | ||
CaFile: "ca_file", | ||
SkipHostVerify: true, | ||
SkipPeerVerify: true, | ||
Timeout: 2 * time.Second, | ||
}, | ||
Expected: libcluster.EtcdOpts{ | ||
Endpoints: []string{"foo"}, | ||
Username: "username", | ||
Password: "password", | ||
KeyFile: "key_file", | ||
CertFile: "cert_file", | ||
CaPath: "ca_path", | ||
CaFile: "ca_file", | ||
SkipHostVerify: true, | ||
Timeout: 2 * time.Second, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
etcdOpts := connect.MakeEtcdOptsFromUriOpts(tc.UriOpts) | ||
|
||
assert.Equal(t, tc.Expected, etcdOpts) | ||
}) | ||
} | ||
} |
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,29 @@ | ||
package connect | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tarantool/go-tarantool" | ||
) | ||
|
||
// MakeConnectOptsFromUriOpts create Tarantool connect options from | ||
// URI options. | ||
func MakeConnectOptsFromUriOpts(src UriOpts) (string, tarantool.Opts) { | ||
opts := tarantool.Opts{ | ||
User: src.Username, | ||
Pass: src.Password, | ||
Ssl: tarantool.SslOpts{ | ||
KeyFile: src.KeyFile, | ||
CertFile: src.CertFile, | ||
CaFile: src.CaFile, | ||
Ciphers: src.Ciphers, | ||
}, | ||
Timeout: src.Timeout, | ||
} | ||
|
||
if opts.Ssl != (tarantool.SslOpts{}) { | ||
opts.Transport = "ssl" | ||
} | ||
|
||
return fmt.Sprintf("tcp://%s", src.Host), opts | ||
} |
Oops, something went wrong.