Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-mysqlbackend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-mysqlbackend
Commits
03a3bbcf
Commit
03a3bbcf
authored
4 years ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Added function to set role's permission.
parent
9f5af78d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/make_db
+44
-1
44 additions, 1 deletion
utils/make_db
with
44 additions
and
1 deletion
utils/make_db
+
44
−
1
View file @
03a3bbcf
...
...
@@ -3,7 +3,8 @@
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2019, 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2021 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2019, 2020, 2021 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com>
...
...
@@ -23,6 +24,10 @@
#
# ** end header
# Although some sanity checks are performed, this script still allows lots of SQL injection
# possibilities.
set
-e
INSTALL_SQL_FILE
=
"db_2_0.sql"
...
...
@@ -198,9 +203,47 @@ function _db_exists() {
}
# Grant the given permissions to the given role.
#
# Arguments
# ---------
# role : str
# The role, may consist of alphanumerical letters plus `.`, `_`, `-`. The role must exist in the
# `roles` table.
#
# permissions : str
# The permissions string. May not contain single quotes, should be similar to:
# [{"grant":"true","priority":"true","permission":"*"}]
function
grant-permission
()
{
role
=
"
$1
"
permissions
=
"
$2
"
if
echo
-n
"
$role
"
|
grep
-v
-q
"^[[:alnum:]._-]*$"
;
then
echo
"Role contains invalid character(s)!"
exit
1
fi
if
[[
$permissions
==
"'"
]]
;
then
echo
"Permissions string contains single quote!"
exit
1
fi
cmd
=
"SELECT COUNT(1) from roles where name='
${
role
}
';"
count
=
$(
$MYSQL_CMD
$(
get_mysql_args
)
-AN
-e
"
$cmd
"
)
if
[[
$count
==
"0"
]]
;
then
echo
"Role not found!"
exit
1
fi
cmd
=
"INSERT INTO permissions (role, permissions) VALUE ('
${
role
}
', '
${
permissions
}
')"
cmd+
=
"ON DUPLICATE KEY UPDATE role='
${
role
}
'"
cmd+
=
";"
$MYSQL_CMD
$(
get_mysql_args
)
-e
"
$cmd
"
}
case
$1
in
"drop"
)
drop
$2
;;
"grant"
)
grant
$2
;;
"grant-permission"
)
grant-permission
$2
$3
;;
# Args: role, permissions
"test"
)
shift
;
runtests
$@
;;
"test-connection"
)
test-connection
;;
"install_db"
)
install_db
;;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment