1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#!/usr/bin/env python3
from parse import search
from os import environ, path
from sys import stdin
from gnupg import GPG
if 'PASSWORD_STORE_DIR' in environ:
pass_dir = environ['PASSWORD_STORE_DIR']
else:
pass_dir = path.join(path.expanduser('~'), '.password-store')
file_path = path.join(pass_dir, 'git')
data = stdin.read()
if 'username' in data:
(protocol, host, username) = search('protocol={}\nhost={}\nusername={}\n', data)
file_path = path.join(file_path, host, username) + '.gpg'
else:
(protocol, host) = search('protocol={}\nhost={}\n', data)
file_path = path.join(file_path, host, 'default') + '.gpg'
with open(file_path, 'rb') as fp:
encrypted = fp.read()
gpg = GPG()
gpg.use_agent = True
password = str(gpg.decrypt(encrypted)).splitlines()[0]
output = ('protocol={}\n'
'host={}\n'
'username={}\n'
'password={}').format(protocol, host, username, password)
print(output)
|