Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: add grant method for all driver spaces #239

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/fast_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
run_tests:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

strategy:
fail-fast: false
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Grant method was added for `*_ready_buffer` spaces (#237).

## [1.4.2] - 2024-08-10

The release re-publish packages.
Expand Down
2 changes: 1 addition & 1 deletion queue/abstract.lua
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function tube.grant(self, user, args)
tube_grant_space(user, '_queue', 'read')
tube_grant_space(user, '_queue_consumers')
tube_grant_space(user, '_queue_taken_2')
tube_grant_space(user, self.name)
self.raw:grant(user, {if_not_exists = true})
session.grant(user)

if args.call then
Expand Down
5 changes: 5 additions & 0 deletions queue/abstract/driver/fifo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ function tube.new(space, on_task_change)
return self
end

-- method.grant grants provided user to all spaces of driver.
function method.grant(self, user, opts)
box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts)
end

-- normalize task: cleanup all internal fields
function method.normalize_task(self, task)
return task
Expand Down
5 changes: 5 additions & 0 deletions queue/abstract/driver/fifottl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ function tube.new(space, on_task_change, opts)
return self
end

-- method.grant grants provided user to all spaces of driver.
function method.grant(self, user, opts)
box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts)
end

-- cleanup internal fields in task
function method.normalize_task(self, task)
return task and task:transform(3, 5)
Expand Down
8 changes: 8 additions & 0 deletions queue/abstract/driver/utube.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ function tube.new(space, on_task_change, opts)
return self
end

-- method.grant grants provided user to all spaces of driver.
function method.grant(self, user, opts)
box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts)
if self.space_ready_buffer ~= nil then
box.schema.user.grant(user, 'read,write', 'space', self.space_ready_buffer.name, opts)
end
end

-- normalize task: cleanup all internal fields
function method.normalize_task(self, task)
return task and task:transform(3, 1)
Expand Down
8 changes: 8 additions & 0 deletions queue/abstract/driver/utubettl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ function tube.new(space, on_task_change, opts)
return self
end

-- method.grant grants provided user to all spaces of driver.
function method.grant(self, user, opts)
box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts)
if self.space_ready_buffer ~= nil then
box.schema.user.grant(user, 'read,write', 'space', self.space_ready_buffer.name, opts)
end
end

-- cleanup internal fields in task
function method.normalize_task(self, task)
return task and task:transform(i_next_event, i_data - i_next_event)
Expand Down
64 changes: 63 additions & 1 deletion t/090-grant-check.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env tarantool
local test = require('tap').test()
test:plan(3)
test:plan(9)

local test_user = 'test'
local test_pass = '1234'
Expand All @@ -21,6 +21,68 @@ local engine = os.getenv('ENGINE') or 'memtx'

local qc = require('queue.compat')

local test_drivers_grant_cases = {
{
name = 'fifo',
queue_type = 'fifo',
},
{
name = 'fifottl',
queue_type = 'fifottl',
},
{
name = 'utube_default',
queue_type = 'utube',
storage_mode = 'default',
},
{
name = 'utube_ready_buffer',
queue_type = 'utube',
storage_mode = 'ready_buffer',
},
{
name = 'utubettl_default',
queue_type = 'utubettl',
storage_mode = 'default',
},
{
name = 'utubettl_ready_buffer',
queue_type = 'utubettl',
storage_mode = 'ready_buffer',
},
}

for _, tc in pairs(test_drivers_grant_cases) do
test:test('test dirvers grant ' .. tc.name, function(test)
local queue = require('queue')
box.schema.user.create(test_user, { password = test_pass })

test:plan(2)

local tube_opts = { engine = engine }
if tc.storage_mode ~= nil and tc.storage_mode ~= 'default' then
tube_opts.storage_mode = tc.storage_mode
tube_opts.engine = 'memtx'
end
local tube = queue.create_tube('test', tc.queue_type, tube_opts)
tube:put('help')

tube:grant(test_user)

box.session.su(test_user)
local a = tube:take()
test:is(a[1], 0, 'we aren\'t getting any error')

local c = tube:ack(a[1])
test:is(c[1], 0, 'we aren\'t getting any error')

box.session.su('admin')

box.schema.user.drop(test_user)
tube:drop()
end)
end

test:test('check for space grants', function(test)
-- prepare for tests
local queue = require('queue')
Expand Down
Loading