mirror of
https://github.com/dadevel/wg-netns
synced 2024-10-30 21:20:12 +00:00
retrieve current username correctly
`os.getlogin()` does not work in some cases, however `getpass.getuser()` does. Closes #17.
This commit is contained in:
parent
a4c991a499
commit
b0e7fcdda8
@ -4,6 +4,7 @@ from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
import getpass
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -92,7 +93,7 @@ def cli(args):
|
|||||||
data = json.loads(output)
|
data = json.loads(output)
|
||||||
print('\n'.join(item['name'] for item in data))
|
print('\n'.join(item['name'] for item in data))
|
||||||
elif opts.action == 'switch':
|
elif opts.action == 'switch':
|
||||||
os.execvp('sudo', ['ip', 'ip', 'netns', 'exec', opts.netns, 'sudo', '-u', os.getlogin(), '-D', Path.cwd().as_posix(), os.environ['SHELL'], '-i'])
|
os.execvp('sudo', ['ip', 'ip', 'netns', 'exec', opts.netns, 'sudo', '-u', getpass.getuser(), '-D', Path.cwd().as_posix(), os.environ['SHELL'], '-i'])
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('congratulations, you reached unreachable code')
|
raise RuntimeError('congratulations, you reached unreachable code')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user