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 typing import Any, Optional
|
||||
import dataclasses
|
||||
import getpass
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
@ -92,7 +93,7 @@ def cli(args):
|
||||
data = json.loads(output)
|
||||
print('\n'.join(item['name'] for item in data))
|
||||
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:
|
||||
raise RuntimeError('congratulations, you reached unreachable code')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user