Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WSL support #3

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions keycmd/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ def main():
"""CLI entrypoint"""
args = cli.parse_args()

if args.verbose:
set_verbose()

if args.version:
log(f"v{__version__}")
return

if args.verbose:
set_verbose()

try:
conf = load_conf()
except tomli.TOMLDecodeError as err:
Expand Down
36 changes: 36 additions & 0 deletions keycmd/wsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from subprocess import run

from keyring.backend import KeyringBackend

from .logs import error


def call_host_keyring(python, command):
p = run(
[python, "-c", f"import keyring; {command}"], shell=False, capture_output=True
)
if p.returncode != 0:
error(f"call to WSL host keyring failed (python path: {python}): {stderr}")
stdout, stderr = p.stdout.decode("utf-8").strip(), p.stderr.decode("utf-8").strip()
return stdout


class WslHostKeyring(KeyringBackend):
priority = 1
python = "py.exe"

def set_password(self, servicename, username, password):
call_host_keyring(
self.python,
f"keyring.set_password('{servicename}', '{username}', '{password}')",
)

def get_password(self, servicename, username):
return call_host_keyring(
self.python, f"print(keyring.get_password('{servicename}', '{username}'))"
)

def delete_password(self, servicename, username):
call_host_keyring(
self.python, f"keyring.delete_password('{servicename}', '{username}')"
)
Loading