Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rosetta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
ExaCT
Rosetta
Commits
80bf2282
Commit
80bf2282
authored
2 years ago
by
Stefano Alberto Russo
Browse files
Options
Downloads
Patches
Plain Diff
Added support for accessing local storages as another user.
parent
d1b4c99b
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
services/webapp/code/rosetta/core_app/api.py
+31
-1
31 additions, 1 deletion
services/webapp/code/rosetta/core_app/api.py
with
31 additions
and
1 deletion
services/webapp/code/rosetta/core_app/api.py
+
31
−
1
View file @
80bf2282
...
...
@@ -418,7 +418,37 @@ class FileManagerAPI(PrivateGETAPI, PrivatePOSTAPI):
else
:
raise
NotImplementedError
(
'
Not accessing through computing is not implemented for storage type
"
{}
"'
.
format
(
storage
.
type
))
elif
storage
.
access_mode
==
'
cli
'
:
command
=
'
/bin/bash -c
"
{}
"'
.
format
(
command
)
try
:
as_user
=
storage
.
conf
[
'
as_user
'
]
# Is "as_user" a UID?
try
:
uid
=
int
(
as_user
)
except
:
pass
else
:
# What is the user for this uid?
out
=
os_shell
(
'
sudo getent passwd
"
1000
"
| cut -d: -f1
'
,
capture
=
True
)
if
out
.
exit_code
!=
0
:
raise
Exception
(
out
.
sterr
)
else
:
if
not
out
.
stdout
.
strip
():
# No user found, create it
os_shell
(
'
sudo groupadd -g {0} group_{0}
'
.
format
(
uid
),
capture
=
True
)
if
out
.
exit_code
!=
0
:
raise
Exception
(
out
.
sterr
)
os_shell
(
'
sudo useradd user_{0} -d /home_{0} -u {0} -g {0} -m -s /bin/bash
'
.
format
(
uid
),
capture
=
True
)
if
out
.
exit_code
!=
0
:
raise
Exception
(
out
.
sterr
)
else
:
as_user
=
out
.
stdout
.
strip
()
except
(
KeyError
,
TypeError
):
as_user
=
None
if
as_user
:
command
=
'
sudo -i -u {} /bin/bash -c
"
{}
"'
.
format
(
as_user
,
command
)
else
:
command
=
'
/bin/bash -c
"
{}
"'
.
format
(
command
)
else
:
raise
NotImplementedError
(
'
Access mode
"
{}
"
not implemented for storage type
"
{}
"'
.
format
(
storage
.
access_mode
,
storage
.
type
))
...
...
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