ykarel / centos / cbs-tools

Forked from centos/cbs-tools 4 years ago
Clone

Blame scripts/koji-group-sync.py

b4342a
#!/usr/bin/python
b4342a
from centos import AccountSystem
b4342a
from centos import defaults
b4342a
b4342a
FAS_USERNAME = ''
b4342a
FAS_PASSWORD = ''
b4342a
GROUP_INCLUDE_PREFIX = 'sig-'
b4342a
GROUP_FILE = '/etc/bsadmin/groups'
b4342a
IGNORE_CERT_VALIDATION = True
b4342a
b4342a
b4342a
def group_users(account_system_handle):
b4342a
    fas = account_system_handle
b4342a
    groups = fas.group_data().keys()
b4342a
b4342a
    group_users = {}
b4342a
    for groupname in groups:
b4342a
        if not groupname.startswith(GROUP_INCLUDE_PREFIX):
b4342a
            continue
b4342a
        group_users[groupname] = [member_entry['username'] for member_entry in
b4342a
                                  fas.group_members(groupname)]
b4342a
    return group_users
b4342a
b4342a
b4342a
def write_file(group_membership, filename=GROUP_FILE):
b4342a
    with open(filename, 'w') as groupfile:
b4342a
        for groupname, users in group_membership.iteritems():
b4342a
            signame = groupname[len(GROUP_INCLUDE_PREFIX):]
b4342a
            print >>groupfile, "{}:{}".format(signame, ','.join(users))
b4342a
b4342a
b4342a
if __name__ == '__main__':
b4342a
    fas = AccountSystem(base_url=defaults.FAS_TOPURL,
b4342a
                        username=FAS_USERNAME,
b4342a
                        password=FAS_PASSWORD,
b4342a
                        insecure=IGNORE_CERT_VALIDATION)
b4342a
b4342a
    write_file(group_users(fas))