-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpasskeyring.py
33 lines (27 loc) · 1.11 KB
/
passkeyring.py
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
import keyring.backend
import os
from subprocess import Popen, PIPE
class PassKeyring(keyring.backend.KeyringBackend):
"""A keyring interfacing with Pass
"""
priority = 1
def set_password(self, servicename, username, password):
p1 = Popen(["echo", password], stdout=PIPE)
p2 = Popen(["pass", "insert", "-e", "-f", servicename+"/"+username], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
(stdout, stderr) = p2.communicate()
exit_code = p2.wait()
return exit_code
def get_password(self, servicename, username):
process = Popen(["pass", servicename+"/"+username], stdout=PIPE)
(stdout, stderr) = process.communicate()
exit_code = process.wait()
if exit_code == 0:
return stdout.rstrip()
else:
return None
def delete_password(self, servicename, username):
process = Popen(["pass", "rm", "-f", servicename+"/"+username], stdout=PIPE)
(stdout, stderr) = process.communicate()
exit_code = process.wait()
return exit_code