source: trunk/packages/invirt-dev/invirt-build-conf @ 2570

Last change on this file since 2570 was 2569, checked in by broder, 15 years ago

Pass a mode to os.fdopen in invirt-build-conf and invirt-submit-build.

By default, os.fdopen opens files in read-only mode.

  • Property svn:executable set to *
File size: 1.4 KB
RevLine 
[2565]1#!/usr/bin/python
2
3"""Re-generate the remctl configuration for build submissions.
4
5This script generates the remctl ACL and configuration for each build
6pocket defined in the configuration.
7"""
8
9
10import os
11import tempfile
12
13from invirt.authz import mech as authz
14from invirt.config import structs as config
15
16
[2566]17def userToPrinc(user):
18    """Convert an AFS principal to a Kerberos v5 principal."""
19    if '@' in user:
20        (princ, realm) = user.split('@')
21    else:
22        princ = user
23        realm = config.kerberos.realm
24
25    return princ.replace('.', '/') + '@' + realm
26
27
[2565]28def main():
29    # Python could really use a file-like object that gets written to
30    # a temporary path and moved to its final resting place on
31    # .close(). Oh well.
[2567]32    conf_fd, conf_name = tempfile.mkstemp()
[2569]33    conf = os.fdopen(conf_fd, 'r+')
[2565]34    build_handler = '/usr/sbin/invirt-submit-build'
35
36    for pocket in config.git.pockets:
37        acl = authz.expandAdmin(getattr(config.git.pockets, pocket).acl, None)
38
[2567]39        acl_fd, acl_name = tempfile.mkstemp()
[2569]40        acl_fd = os.fdopen(acl_fd, 'r+')
[2568]41        print >>acl_fd, '\n'.join(userToPrinc(a) for a in acl)
[2565]42
43        acl_path = os.path.join('/etc/remctl/acl/build-%s' % pocket)
44
[2567]45        os.rename(acl_name, acl_path)
[2565]46        print >>conf, 'build %s %s %s' % (pocket, build_handler, acl_path)
47
[2567]48    os.rename(conf_name, '/etc/remctl/conf.d/build')
[2565]49
50
51if __name__ == '__main__':
52    main()
Note: See TracBrowser for help on using the repository browser.