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
|
2024-06-24 12:57:27 +00:00
|
|
|
import yaml
|
2017-08-08 09:56:36 +00:00
|
|
|
|
2024-06-24 12:57:27 +00:00
|
|
|
CONFIG = os.path.expanduser('~/.config/git-committerconfig.yaml')
|
2017-08-08 09:56:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
2024-06-24 12:57:27 +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):
|
2024-06-24 12:57:27 +00:00
|
|
|
combinations = yaml.safe_load(open(CONFIG).read())
|
2017-08-08 09:56:36 +00:00
|
|
|
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
|
|
|
|
|
2024-06-24 12:57:27 +00:00
|
|
|
|
2017-08-08 09:56:36 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
exit(main())
|