_subprocess_run_as_user
Run simple commands as another user
This module provides a set of tools similar to subprocess.run
, glob.glob
or
os.path.exists
, but extended so that they can be executed on behalf of
another user. Note that this requires appropriate sudo permissions.
_mkdir_as_user(*, folder, user)
¶
Create a folder as a different user
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder
|
str
|
Absolute path to the folder |
required |
user
|
str
|
User to be impersonated |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if |
Source code in fractal_server/runner/executors/slurm_sudo/_subprocess_run_as_user.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
_run_command_as_user(*, cmd, user=None, check=False)
¶
Use sudo -u
to impersonate another user and run a command
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmd
|
str
|
Command to be run |
required |
user
|
str | None
|
User to be impersonated |
None
|
check
|
bool
|
If |
False
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if |
Returns:
Name | Type | Description |
---|---|---|
res |
CompletedProcess
|
The return value from |
Source code in fractal_server/runner/executors/slurm_sudo/_subprocess_run_as_user.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|