Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-jukovec committed Oct 16, 2023
1 parent b8a1e2d commit 8ce3b4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
39 changes: 21 additions & 18 deletions crud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,29 @@ function crud.init_storage()
error('box.cfg() must be called first')
end

local ok, storage_info = pcall(vshard.storage.info)
if not ok then
error('vshard.storage.cfg() must be called first')
local user = nil
if not box.info.ro then
local ok, storage_info = pcall(vshard.storage.info)
if not ok then
error('vshard.storage.cfg() must be called first')
end

local box_info = box.info()
local replicaset_uuid
if box_info.replicaset ~= nil then
replicaset_uuid = box_info.replicaset.uuid
else
replicaset_uuid = box_info.cluster.uuid
end
local replicaset_info = storage_info.replicasets[replicaset_uuid]
if replicaset_info == nil or replicaset_info.master == nil then
error(string.format('Failed to find a vshard configuration for ' ..
' replicaset with replicaset_uuid %s.',
replicaset_uuid))
end
user = luri.parse(replicaset_info.master.uri).login or 'guest'
end

local box_info = box.info()
local replicaset_uuid
if box_info.replicaset ~= nil then
replicaset_uuid = box_info.replicaset.uuid
else
replicaset_uuid = box_info.cluster.uuid
end
local replicaset_info = storage_info.replicasets[replicaset_uuid]
if replicaset_info == nil or replicaset_info.master == nil then
error(string.format('Failed to find a vshard configuration for ' ..
' replicaset with replicaset_uuid %s.',
replicaset_uuid))
end
local user = luri.parse(replicaset_info.master.uri).login or 'guest'

if rawget(_G, '_crud') == nil then
rawset(_G, '_crud', {})
end
Expand Down
15 changes: 7 additions & 8 deletions crud/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1196,26 +1196,25 @@ end
--- Initializes a storage function by its name.
--
-- It adds the function into the global scope by its name and required
-- rights to a vshard storage user.
-- access to a vshard storage user.
--
-- @function init_storage_call
--
-- @param string name of a user or nil if there is no need to setup access.
-- @param string name a name of the function.
-- @param function func the function.
--
-- @return nil
function utils.init_storage_call(user, name, func)
dev_checks('string', 'string', 'function')
dev_checks('?string', 'string', 'function')

rawset(_G['_crud'], name, func)

if box.info().ro then
return
if user ~= nil then
name = utils.get_storage_call(name)
box.schema.func.create(name, {setuid = true, if_not_exists = true})
box.schema.user.grant(user, 'execute', 'function', name, {if_not_exists=true})
end

name = utils.get_storage_call(name)
box.schema.func.create(name, {setuid = true, if_not_exists = true})
box.schema.user.grant(user, 'execute', 'function', name, {if_not_exists=true})
end

local expected_vshard_api = {
Expand Down

0 comments on commit 8ce3b4c

Please sign in to comment.