From b4342a66299d2415f9aaf14befd484955ce55ef3 Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Sep 04 2015 19:08:58 +0000 Subject: start on the script to sync FAS groups to koji for use with build- permissions --- diff --git a/scripts/koji-group-sync.py b/scripts/koji-group-sync.py new file mode 100644 index 0000000..6e6857a --- /dev/null +++ b/scripts/koji-group-sync.py @@ -0,0 +1,38 @@ +#!/usr/bin/python +from centos import AccountSystem +from centos import defaults + +FAS_USERNAME = '' +FAS_PASSWORD = '' +GROUP_INCLUDE_PREFIX = 'sig-' +GROUP_FILE = '/etc/bsadmin/groups' +IGNORE_CERT_VALIDATION = True + + +def group_users(account_system_handle): + fas = account_system_handle + groups = fas.group_data().keys() + + group_users = {} + for groupname in groups: + if not groupname.startswith(GROUP_INCLUDE_PREFIX): + continue + group_users[groupname] = [member_entry['username'] for member_entry in + fas.group_members(groupname)] + return group_users + + +def write_file(group_membership, filename=GROUP_FILE): + with open(filename, 'w') as groupfile: + for groupname, users in group_membership.iteritems(): + signame = groupname[len(GROUP_INCLUDE_PREFIX):] + print >>groupfile, "{}:{}".format(signame, ','.join(users)) + + +if __name__ == '__main__': + fas = AccountSystem(base_url=defaults.FAS_TOPURL, + username=FAS_USERNAME, + password=FAS_PASSWORD, + insecure=IGNORE_CERT_VALIDATION) + + write_file(group_users(fas))