From 8ce3b4cc0a82d5ac17827df805f9830ef0a1b56e Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Mon, 16 Oct 2023 12:07:56 +0300 Subject: [PATCH] fix --- crud.lua | 39 +++++++++++++++++++++------------------ crud/common/utils.lua | 15 +++++++-------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/crud.lua b/crud.lua index 80c46828..eb250cb1 100644 --- a/crud.lua +++ b/crud.lua @@ -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 diff --git a/crud/common/utils.lua b/crud/common/utils.lua index b92478b1..2d843df3 100644 --- a/crud/common/utils.lua +++ b/crud/common/utils.lua @@ -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 = {