Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simone Rossi
main
Commits
a4a95def
Commit
a4a95def
authored
Aug 23, 2018
by
Daniele Venzano
Browse files
fix problems related to setting the filesystem uid
parent
8d269bbb
Changes
4
Show whitespace changes
Inline
Side-by-side
zoe_api/api_endpoint.py
View file @
a4a95def
...
...
@@ -231,7 +231,7 @@ class APIEndpoint:
users
=
self
.
sql
.
user
.
select
(
**
filters
)
return
users
def
user_new
(
self
,
user
:
zoe_lib
.
state
.
User
,
username
:
str
,
email
:
str
,
role_id
:
int
,
quota_id
:
int
,
auth_source
:
str
)
->
int
:
def
user_new
(
self
,
user
:
zoe_lib
.
state
.
User
,
username
:
str
,
email
:
str
,
role_id
:
int
,
quota_id
:
int
,
auth_source
:
str
,
fs_uid
:
int
)
->
int
:
"""Creates a new user."""
if
not
user
.
role
.
can_change_config
:
raise
zoe_api
.
exceptions
.
ZoeAuthException
()
...
...
@@ -241,7 +241,7 @@ class APIEndpoint:
if
self
.
quota_by_id
(
quota_id
)
is
None
:
raise
zoe_api
.
exceptions
.
ZoeNotFoundException
(
"Quota {} does not exist"
.
format
(
quota_id
))
return
self
.
sql
.
user
.
insert
(
username
,
email
,
auth_source
,
role_id
,
quota_id
)
return
self
.
sql
.
user
.
insert
(
username
,
email
,
auth_source
,
role_id
,
quota_id
,
fs_uid
)
def
user_update
(
self
,
user
:
zoe_lib
.
state
.
User
,
user_id
,
user_data
):
"""Update a user."""
...
...
@@ -277,6 +277,8 @@ class APIEndpoint:
if
'password'
in
user_data
:
update_fields
[
'password'
]
=
user_data
[
'password'
]
update_fields
[
'auth_source'
]
=
'internal'
if
'fs_uid'
in
user_data
:
update_fields
[
'fs_uid'
]
=
user_data
[
'fs_uid'
]
self
.
sql
.
user
.
update
(
user_id
,
**
update_fields
)
...
...
zoe_api/rest_api/user.py
View file @
a4a95def
...
...
@@ -132,7 +132,7 @@ class UserCollectionAPI(ZoeAPIRequestHandler):
return
try
:
new_id
=
self
.
api_endpoint
.
user_new
(
self
.
current_user
,
data
[
'username'
],
data
[
'email'
],
data
[
'role_id'
],
data
[
'quota_id'
],
data
[
'auth_source'
])
new_id
=
self
.
api_endpoint
.
user_new
(
self
.
current_user
,
data
[
'username'
],
data
[
'email'
],
data
[
'role_id'
],
data
[
'quota_id'
],
data
[
'auth_source'
]
,
data
[
'fs_uid'
]
)
except
KeyError
:
self
.
set_status
(
400
,
'Error decoding JSON data'
)
return
...
...
zoe_cmd/entrypoint_admin.py
View file @
a4a95def
...
...
@@ -147,7 +147,7 @@ def quota_ls_cmd(api: ZoeAPI, args):
if
'name'
in
args
:
filters
[
'name'
]
=
args
.
name
quotas
=
api
.
quota
.
list
(
filters
)
tabular_data
=
[[
q
[
'id'
],
q
[
'name'
],
q
[
'concurrent_executions'
],
q
[
'memory'
],
q
[
'cores'
]]
for
q
in
sorted
(
quotas
)]
tabular_data
=
[[
q
[
'id'
],
q
[
'name'
],
q
[
'concurrent_executions'
],
q
[
'memory'
],
q
[
'cores'
]]
for
q
in
sorted
(
quotas
,
key
=
lambda
x
:
x
[
'id'
]
)]
headers
=
[
'ID'
,
'Name'
,
'Conc. Executions'
,
'Memory'
,
'Cores'
]
print
(
tabulate
(
tabular_data
,
headers
))
...
...
@@ -204,7 +204,7 @@ def role_ls_cmd(api: ZoeAPI, args):
if
args
.
name
is
not
None
:
filters
[
'name'
]
=
args
.
name
roles
=
api
.
role
.
list
(
filters
)
tabular_data
=
[[
r
[
'id'
],
r
[
'name'
],
b2t
(
r
[
'can_see_status'
]),
b2t
(
r
[
'can_change_config'
]),
b2t
(
r
[
'can_operate_others'
]),
b2t
(
r
[
'can_delete_executions'
]),
b2t
(
r
[
'can_access_api'
]),
b2t
(
r
[
'can_customize_resources'
])]
for
r
in
sorted
(
roles
)]
tabular_data
=
[[
r
[
'id'
],
r
[
'name'
],
b2t
(
r
[
'can_see_status'
]),
b2t
(
r
[
'can_change_config'
]),
b2t
(
r
[
'can_operate_others'
]),
b2t
(
r
[
'can_delete_executions'
]),
b2t
(
r
[
'can_access_api'
]),
b2t
(
r
[
'can_customize_resources'
])]
for
r
in
sorted
(
roles
,
key
=
lambda
x
:
x
[
'id'
]
)]
headers
=
[
'ID'
,
'Name'
,
'See status'
,
'Change config'
,
'Operate others'
,
'Delete execs'
,
'API access'
,
'Customize resources'
]
print
(
tabulate
(
tabular_data
,
headers
))
...
...
@@ -328,17 +328,18 @@ def user_create_cmd(api: ZoeAPI, args):
'username'
:
args
.
username
,
'email'
:
args
.
email
,
'auth_source'
:
args
.
auth_source
,
'fs_uid'
:
args
.
fs_uid
}
quota
=
api
.
quota
.
list
({
'name'
:
args
.
quota
})
[
0
]
if
quota
is
None
:
quota
=
api
.
quota
.
list
({
'name'
:
args
.
quota
})
if
len
(
quota
)
==
0
:
print
(
'Unknown quota'
)
return
user
[
'quota_id'
]
=
quota
[
'id'
]
role
=
api
.
role
.
list
({
'name'
:
args
.
role
})
[
0
]
if
role
is
None
:
user
[
'quota_id'
]
=
quota
[
0
][
'id'
]
role
=
api
.
role
.
list
({
'name'
:
args
.
role
})
if
len
(
role
)
==
0
:
print
(
'Unknown role'
)
return
user
[
'role_id'
]
=
role
[
'id'
]
user
[
'role_id'
]
=
role
[
0
][
'id'
]
new_id
=
api
.
user
.
create
(
user
)
print
(
'New user created with ID: {}'
.
format
(
new_id
))
...
...
@@ -505,6 +506,7 @@ def process_arguments() -> Tuple[ArgumentParser, Namespace]:
sub_parser
.
add_argument
(
'username'
,
help
=
"Username"
)
sub_parser
.
add_argument
(
'email'
,
help
=
"Email"
)
sub_parser
.
add_argument
(
'auth_source'
,
choices
=
[
'internal'
,
'ldap'
,
'ldap+ssl'
,
'textfile'
,
'pam'
],
help
=
"Authentication method"
)
sub_parser
.
add_argument
(
'fs_uid'
,
help
=
"Filesystem UID"
,
type
=
int
)
sub_parser
.
add_argument
(
'role'
,
help
=
"Role name"
)
sub_parser
.
add_argument
(
'quota'
,
help
=
"Quota name"
)
sub_parser
.
set_defaults
(
func
=
user_create_cmd
)
...
...
zoe_lib/state/user.py
View file @
a4a95def
...
...
@@ -162,9 +162,9 @@ class UserTable(BaseTable):
else
:
return
[
User
(
x
,
self
.
sql_manager
)
for
x
in
self
.
cursor
]
def
insert
(
self
,
username
:
str
,
email
:
str
,
auth_source
:
str
,
role_id
:
int
,
quota_id
:
int
):
def
insert
(
self
,
username
:
str
,
email
:
str
,
auth_source
:
str
,
role_id
:
int
,
quota_id
:
int
,
fs_uid
:
int
):
"""Adds a new user to the state."""
query
=
self
.
cursor
.
mogrify
(
'INSERT INTO "user" (id, username, fs_uid, email, priority, enabled, auth_source, role_id, quota_id) VALUES (DEFAULT, %s,
(SELECT MAX("user".fs_uid)+1 FROM "user")
, %s, DEFAULT, TRUE, %s, %s, %s) RETURNING id'
,
(
username
,
email
,
auth_source
,
role_id
,
quota_id
))
query
=
self
.
cursor
.
mogrify
(
'INSERT INTO "user" (id, username, fs_uid, email, priority, enabled, auth_source, role_id, quota_id) VALUES (DEFAULT, %s,
%s
, %s, DEFAULT, TRUE, %s, %s, %s) RETURNING id'
,
(
username
,
fs_uid
,
email
,
auth_source
,
role_id
,
quota_id
))
self
.
cursor
.
execute
(
query
)
self
.
sql_manager
.
commit
()
return
self
.
cursor
.
fetchone
()[
0
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment