diff --git a/scripts/fas_perms_to_koji.py b/scripts/fas_perms_to_koji.py index e703242..9cf2770 100755 --- a/scripts/fas_perms_to_koji.py +++ b/scripts/fas_perms_to_koji.py @@ -12,18 +12,19 @@ # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# This script reads from a file, group information generated by FAS and sync +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# This script reads from a file, group information generated by FAS and sync # it with koji # No command line argument, options are hardcoded at this time. @@ -32,7 +33,7 @@ import os.path import sys from collections import defaultdict -KOJI_URL='http://localhost/kojihub' +KOJI_URL = 'http://localhost/kojihub' CLIENT_CERT = os.path.expanduser('~/.koji/client.crt') CLIENTCA_CERT = os.path.expanduser('~/.koji/clientca.crt') SERVERCA_CERT = os.path.expanduser('~/.koji/serverca.crt') @@ -41,7 +42,7 @@ FASDUMP = '/etc/bsadmin/groups' SYSTEM_USERS = ['koji', 'kojira'] def get_user_list(): - users = [(x['name'],x['id']) for x in kojiclient.listUsers()] + users = [(x['name'], x['id']) for x in kojiclient.listUsers()] return users if len(users) else None def get_user(user): @@ -55,7 +56,7 @@ def get_user_perms(user): def get_users_perms(): userlist = defaultdict(list) for user in get_user_list(): - userlist[user[0]] = get_user_perms(user) + userlist[user[0]] = get_user_perms(user) return userlist if len(userlist) else None @@ -66,20 +67,20 @@ def get_user_perms_from_file(user): def get_all_defined_perms(): perms = [] for perm in kojiclient.getAllPerms(): - perms.append(perm['name']) + perms.append(perm['name']) return perms def get_users_perms_from_file(): userlist = defaultdict(list) try: - groups = open (FASDUMP, 'r') + groups = open(FASDUMP, 'r') except: - return None + return None for line in groups.readlines(): sig, users = line.strip('\n').split(':') - for user in users.replace(" ","").split(','): - perm="build-"+sig + for user in users.replace(" ", "").split(','): + perm = "build-"+sig userlist[user].append(perm) return userlist if len(userlist) else None @@ -87,7 +88,7 @@ def get_users_perms_from_file(): def fix_permissions(new, old): usernames = list(set(new)|set(old)) # Do not touch system users - usernames = [ u for u in usernames if u not in SYSTEM_USERS ] + usernames = [u for u in usernames if u not in SYSTEM_USERS] for username in usernames: togrant = list(set(new[username]) - set(old[username])) torevoke = list(set(old[username]) - set(new[username])) @@ -95,18 +96,18 @@ def fix_permissions(new, old): if togrant or torevoke: print "\n# user:%s\n# NEW perms:%s\n# OLD perms:%s \ \n# To grant:%s\n# To revoke:%s" \ - % (user,new[username],old[username],togrant,torevoke) + % (user, new[username], old[username], togrant, torevoke) if not user: # Create user if it doesn't exist yet - user = kojiclient.createUser(username) + user = kojiclient.createUser(username) # Always grant "build" permission for building from srpm - kojiclient.grantPermission(username, 'build') + kojiclient.grantPermission(username, 'build') for perm in togrant: if perm in get_all_defined_perms(): - kojiclient.grantPermission(username, perm) + kojiclient.grantPermission(username, perm) for perm in torevoke: if perm in get_all_defined_perms(): - kojiclient.revokePermission(username, perm) + kojiclient.revokePermission(username, perm) if __name__ == '__main__': try: