Skip to content
Snippets Groups Projects
Commit 9f4d7eba authored by Dmitry E. Oboukhov's avatar Dmitry E. Oboukhov
Browse files

net.box can use uri instead host, port arguments. closes #368.

parent df07f110
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ local errno = require 'errno'
local ffi = require 'ffi'
local digest = require 'digest'
local yaml = require 'yaml'
local urilib = require 'uri'
-- packet codes
local OK = 0
......@@ -347,6 +348,32 @@ local remote_methods = {
setmetatable(self, getmetatable(remote))
end
-- uri as the first argument
if opts == nil then
opts = {}
if type(port) == 'table' then
opts = port
port = nil
end
if port == nil then
local address = urilib.parse(tostring(host))
if address == nil or address.service == nil then
box.error(box.error.PROC_LUA,
"usage: remote:new(uri[, opts] | host, port[, opts])")
end
host = address.host
port = address.service
opts.user = address.login or opts.user
opts.password = address.password or opts.password
end
end
self.is_instance = true
self.host = host
self.port = port
......
......@@ -141,7 +141,7 @@ cn.space.net_box_test_space:insert{234, 1,2,3}
...
cn.space.net_box_test_space.insert{234, 1,2,3}
---
- error: 'builtin/net.box.lua:228: Use space:method(...) instead space.method(...)'
- error: 'builtin/net.box.lua:229: Use space:method(...) instead space.method(...)'
...
cn.space.net_box_test_space:replace{354, 1,2,3}
---
......@@ -603,3 +603,34 @@ remote.self.call('console_test')
---
- error: 'usage: remote:call(proc_name, ...)'
...
-- uri as the first argument
uri = string.format('%s:%s@%s:%s', 'netbox', 'test', LISTEN.host, LISTEN.service)
---
...
cn = remote.new(uri)
---
...
cn:ping()
---
- true
...
cn:close()
---
...
uri = string.format('%s@%s:%s', 'netbox', LISTEN.host, LISTEN.service)
---
...
remote.new(uri)
---
- error: 'net.box: password is not defined'
...
cn = remote.new(uri, { password = 'test' })
---
...
cn:ping()
---
- true
...
cn:close()
---
...
......@@ -238,3 +238,17 @@ cn.ping()
remote.self:call('console_test')
remote.self.call('console_test')
-- uri as the first argument
uri = string.format('%s:%s@%s:%s', 'netbox', 'test', LISTEN.host, LISTEN.service)
cn = remote.new(uri)
cn:ping()
cn:close()
uri = string.format('%s@%s:%s', 'netbox', LISTEN.host, LISTEN.service)
remote.new(uri)
cn = remote.new(uri, { password = 'test' })
cn:ping()
cn:close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment