X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dev.git/blobdiff_plain/c81a9160bc47b724cba617285da6fec429734a21..675ed12f6047c8d40475e83a3925bbf84ea107c0:/invirt-build-conf diff --git a/invirt-build-conf b/invirt-build-conf index f74b05d..1acbc9d 100755 --- a/invirt-build-conf +++ b/invirt-build-conf @@ -3,36 +3,65 @@ """Re-generate the remctl configuration for build submissions. This script generates the remctl ACL and configuration for each build -pocket defined in the configuration. +pocket defined in the configuration. It also updates the .k5login for +the git user that developers can push through. """ +from __future__ import with_statement - +import contextlib import os import tempfile -from invirt.authz import mech as authz +from invirt import authz +from invirt import builder from invirt.config import structs as config +def userToPrinc(user): + """Convert an AFS principal to a Kerberos v5 principal.""" + if '@' in user: + (princ, realm) = user.split('@') + else: + princ = user + realm = config.kerberos.realm + + return princ.replace('.', '/') + '@' + realm + +def acl_path(pocket): + return '/etc/remctl/acl/build-%s' % pocket + +@contextlib.contextmanager +def atomic_write(file): + tmp_fd, tmp_name = tempfile.mkstemp() + tmp = os.fdopen(tmp_fd, 'r+') + yield tmp + tmp.close() + os.rename(tmp_name, file) + def main(): - # Python could really use a file-like object that gets written to - # a temporary path and moved to its final resting place on - # .close(). Oh well. - conf = tempfile.NamedTemporaryFile(delete=False) - build_handler = '/usr/sbin/invirt-submit-build' + all_devs = set() + build_handler = '/usr/bin/invirt-submit-build' - for pocket in config.git.pockets: - acl = authz.expandAdmin(getattr(config.git.pockets, pocket).acl, None) + for pocket in config.build.pockets: + acl = authz.expandAdmin(getattr(config.build.pockets, pocket).acl, None) + with atomic_write(acl_path(pocket)) as f: + princs = [userToPrinc(a) for a in acl] + print >>f, '\n'.join(princs) + all_devs.update(set(princs)) - acl_fd = tempfile.NamedTemporaryFile(delete=False) - print >>acl_fd, '\n'.join(acl) + with atomic_write('/etc/remctl/conf.d/build') as f: + for pocket in config.build.pockets: + print >>f, 'build %s %s %s' % (pocket, build_handler, acl_path(pocket)) - acl_path = os.path.join('/etc/remctl/acl/build-%s' % pocket) + with atomic_write('/etc/remctl/acl/repo_admin') as f: + acl = authz.expandAdmin(config.build.repo_admin, None) + print >>f, '\n'.join(userToPrinc(a) for a in acl) - os.rename(acl_fd.name, acl_path) - print >>conf, 'build %s %s %s' % (pocket, build_handler, acl_path) + with atomic_write('/etc/remctl/conf.d/repo_admin') as f: + print >>f, 'create repo /usr/bin/invirt-add-repo /etc/remctl/acl/repo_admin' - os.rename(conf, '/etc/remctl/conf.d/build') + with atomic_write(os.path.join(builder._REPO_DIR, '.k5login')) as f: + print >>f, '\n'.join(all_devs) if __name__ == '__main__':