-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvaultkeychain.py
More file actions
executable file
·35 lines (28 loc) · 957 Bytes
/
vaultkeychain.py
File metadata and controls
executable file
·35 lines (28 loc) · 957 Bytes
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
# -*- coding: utf-8 -*-
import keyring
import re
import os
import sys
from subprocess import Popen, PIPE
import builtins
def raw_input(prompt=None):
if prompt:
sys.stderr.write(str(prompt))
return builtins.input()
out, err = Popen(["git", "config", "--get", "remote.origin.url"], stdout=PIPE, stderr=PIPE).communicate()
out_text = out.decode("utf-8", errors="replace")
repo=re.sub(r'http(s)?:[/]{2}([^/]+)[/]', r'git@\2:', out_text.split('\n')[0])
if re.search(r'\S', repo):
KEYRING_SERVICE = repo
else:
KEYRING_SERVICE = os.getcwd()
username = "ansible-vault"
password = keyring.get_password(KEYRING_SERVICE, username )
if not password:
password = raw_input("Enter password for '%s':" % KEYRING_SERVICE)
try:
keyring.set_password(KEYRING_SERVICE, username, password)
except keyring.errors.PasswordSetError:
print("failed to store password", file=sys.stderr)
print(password)