2017-12-14 14:02:20 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-08-08 09:56:36 +00:00
|
|
|
|
|
|
|
# Usage: git loadkey
|
|
|
|
#
|
|
|
|
# Configuration format:
|
|
|
|
# [
|
|
|
|
# {
|
|
|
|
# "match": ".*",
|
|
|
|
# "keyname": "...",
|
|
|
|
# }
|
|
|
|
# ]
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import os.path
|
|
|
|
import json
|
|
|
|
|
2017-11-10 11:44:57 +00:00
|
|
|
CONFIG = os.path.expanduser('~/.config/git-committerconfig.json')
|
2017-08-08 09:56:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
2017-12-14 14:02:20 +00:00
|
|
|
repos = [x.split()[1] for x in subprocess.check_output(['git', 'remote', '-v'], universal_newlines=True).split('\n') if len(x.strip()) > 0]
|
2017-08-08 09:56:36 +00:00
|
|
|
except:
|
2017-12-14 14:02:20 +00:00
|
|
|
print('Could not find origin, not loading key.')
|
2017-08-08 09:56:36 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
if os.path.isfile(CONFIG):
|
|
|
|
combinations = json.loads(open(CONFIG).read())
|
|
|
|
else:
|
2017-12-14 14:02:20 +00:00
|
|
|
print('Config ({}) found.'.format(CONFIG))
|
2017-08-08 09:56:36 +00:00
|
|
|
return 1
|
|
|
|
|
|
|
|
required_keys = []
|
|
|
|
|
|
|
|
for repo in sorted(set(repos)):
|
|
|
|
for combi in combinations:
|
|
|
|
if re.search(combi['match'], repo):
|
|
|
|
required_keys.append(combi['keyname'])
|
|
|
|
break
|
|
|
|
|
|
|
|
for key in sorted(set(required_keys)):
|
2017-12-14 14:02:20 +00:00
|
|
|
print('Loading key "{}"...'.format(key))
|
2017-08-08 09:56:36 +00:00
|
|
|
subprocess.check_call(['vault-sshadd', key])
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
exit(main())
|