Created
January 12, 2015 15:19
-
-
Save zachfi/d1b53a6a3566560dd60a to your computer and use it in GitHub Desktop.
Gitolite keys from LDAP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env python | |
| from pyldap import PyLDAP | |
| from config import get_option, load_config | |
| from os import mkdir | |
| from os.path import isdir | |
| def main(): | |
| opt, users = get_option() | |
| config = load_config(opt.config, 'LDAP') | |
| ldap = PyLDAP( | |
| config['url'], | |
| config['binddn'], | |
| config['bindpw'], | |
| config['basedn'], | |
| ) | |
| ldap.bind() | |
| keydir = 'keys.d' | |
| if not isdir(keydir): | |
| mkdir(keydir) | |
| for user in users: | |
| userDN = ldap.userDN(user) | |
| mail = ldap.objectAttribute(userDN, 'mail') | |
| keys = ldap.objectAttribute(userDN, 'sshPublicKey') | |
| if keys is None: | |
| continue | |
| else: | |
| for i, k in enumerate(keys): | |
| filename = "{dir}/{mail}@{index}.pub".format( | |
| dir='keys.d', | |
| mail=mail, | |
| index=i) | |
| with open(filename, 'w') as f: | |
| f.write(k) | |
| ldap.unbind | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment