aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2015-05-16 01:09:00 +0200
committerJohannes Löthberg <johannes@kyriasis.com>2015-05-16 01:09:00 +0200
commit43943e26128724aaf5516a596772a16afdae06ea (patch)
tree8af3c3b913dca9a4764174643588885fa2317eb0
parenta3db1c7d0d69b1506effb2c4eec4d091392e21de (diff)
downloadbin-43943e26128724aaf5516a596772a16afdae06ea.tar.xz
Import git-credential-pass
this is a barely functional python script to be able to use passwords stored in pass(1) with git.
-rwxr-xr-xgit-credential-pass35
1 files changed, 35 insertions, 0 deletions
diff --git a/git-credential-pass b/git-credential-pass
new file mode 100755
index 0000000..0db00e9
--- /dev/null
+++ b/git-credential-pass
@@ -0,0 +1,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)