Skip to content

Commit

Permalink
cfg: allow uri of any type, not only string
Browse files Browse the repository at this point in the history
Since 2.10.0-beta2 URI in all APIs can be passed not only as a
string or number but also as a table.

The table can be used to pass options like transport type (plain,
SSL), encryption certificate and key, and potentially more.

VShard always supported only string URIs but now it allows numbers
and tables as well. In the config the replica_object.uri field is
affected by the change.

Part of #325
  • Loading branch information
Gerold103 committed May 9, 2022
1 parent d6f9ac4 commit 804410f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
41 changes: 41 additions & 0 deletions test/unit-luatest/config_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
local t = require('luatest')
local lcfg = require('vshard.cfg')
local uuid = require('uuid')

local g = t.group('config')

g.test_basic_uri = function()
local url = 'storage:storage@127.0.0.1:3301'
local storage_1_a = {
uri = url,
name = 'storage_1_a',
}
local config = {
sharding = {
storage_1_uuid = {
replicas = {
storage_1_a_uuid = storage_1_a,
}
},
},
}
t.assert(lcfg.check(config), 'normal uri')

storage_1_a.uri = {url}
t.assert(lcfg.check(config), 'table uri')

storage_1_a.uri = {url, params = {transport = 'plain'}}
t.assert(lcfg.check(config), 'uri with options')

storage_1_a.uri = 3301
t.assert(lcfg.check(config), 'number uri')

storage_1_a.uri = 'bad uri ###'
t.assert_error(lcfg.check, config)

storage_1_a.uri = nil
t.assert_error(lcfg.check, config)

storage_1_a.uri = uuid.new()
t.assert_error(lcfg.check, config)
end
6 changes: 5 additions & 1 deletion vshard/cfg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ local function validate_config(config, template, check_arg)
end

local replica_template = {
uri = {type = 'non-empty string', name = 'URI', check = check_uri},
uri = {
type = {'non-empty string', 'number', 'table'},
name = 'URI',
check = check_uri
},
name = {type = 'string', name = "Name", is_optional = true},
zone = {type = {'string', 'number'}, name = "Zone", is_optional = true},
master = {
Expand Down

0 comments on commit 804410f

Please sign in to comment.