Created
March 30, 2020 07:49
-
-
Save kmod-midori/0dec61e00526420d61a6ef54cee0377a to your computer and use it in GitHub Desktop.
KWallet wrapper for git credential helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from sys import stdin, argv | |
import subprocess | |
import json | |
if len(argv) != 2: | |
print("Usage: " + argv[0] + " <action: get|store>") | |
exit(1) | |
action = argv[1] | |
known = {} | |
while True: | |
line = stdin.readline().strip().split('=') | |
if len(line) != 2: | |
break | |
known[line[0]] = line[1] | |
if argv[1] == 'get': | |
url = 'py_' + known['protocol'] + '://' + known['host'] | |
shell = ['kwallet-query', '-f', 'git', '-r', url, 'kdewallet'] | |
command = subprocess.Popen( | |
shell, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) | |
output, errors = command.communicate() | |
output = output.decode('utf-8').strip() | |
if not output.startswith('Failed'): | |
result = json.loads(output) | |
print('username=' + result['username']) | |
print('password=' + result['password']) | |
if argv[1] == 'store': | |
j = json.dumps({ | |
'username': known['username'], | |
'password': known['password'] | |
}) | |
print(j) | |
url = 'py_' + known['protocol'] + '://' + known['host'] | |
shell = ['kwallet-query', '-f', 'git', '-w', url, 'kdewallet', '-v'] | |
command = subprocess.Popen( | |
shell, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True) | |
output, errors = command.communicate(input=j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment