-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpass.py
executable file
·37 lines (30 loc) · 1.14 KB
/
pass.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
33
34
35
36
37
"""
pass.py
A keyring class to store and get passwords from pass
password-store http://zx2c4.com/projects/password-store/
"""
from keyring.backend import KeyringBackend
from subprocess import Popen, PIPE
class Keyring(KeyringBackend):
"""Pass Keyring"""
def supported(self):
return 0
def get_password(self, service, username):
proc = Popen(['pass', 'show', '/'.join([service,username])],
stdin=None, stdout=PIPE, stderr=PIPE)
password, _ = proc.communicate()
proc.wait()
if(proc.returncode == 0):
return password.decode('utf-8').rstrip('\n')
else:
return None
def set_password(self, service, username, password):
proc = Popen(['pass', 'insert', '--echo', '--force', '/'.join([service,username])],
stdin=PIPE, stdout=PIPE)
proc.communicate(password.encode('utf-8'));
proc.wait()
def delete_password(self, service, username):
proc = Popen(['pass', 'rm', '--force', '/'.join([service,username])])
proc.wait()
if(proc.returncode != 0):
raise PasswordDeleteError("Password not found")