forked from infra/ansible
distgit: deploy script to transfer pagure group ownership
Fixes: infra/tickets#12935 Signed-off-by: Victor Koycheff <victorinaforvu@gmail.com>
This commit is contained in:
parent
38fe6cbb19
commit
62eff4cb2d
2 changed files with 75 additions and 0 deletions
62
roles/distgit/files/pagure_transfer_group.py
Normal file
62
roles/distgit/files/pagure_transfer_group.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import print_function, unicode_literals, absolute_import
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import pagure.config
|
||||
import pagure.exceptions
|
||||
import pagure.lib.model_base
|
||||
import pagure.lib.query
|
||||
|
||||
def parse_arguments():
|
||||
""" Set-up the argument parsing. """
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("group_name", help="Name of the group")
|
||||
parser.add_argument(
|
||||
"new_creator",
|
||||
help="Name of the user that will be the new creator of the group",
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
def transfer_group(session, args):
|
||||
# Validate user
|
||||
if not args.new_creator:
|
||||
raise pagure.exceptions.PagureException(
|
||||
"An username must be provided to associate with the group"
|
||||
)
|
||||
user = pagure.lib.query.get_user(session, args.new_creator)
|
||||
# Validate group
|
||||
group = pagure.lib.query.search_groups(session, group_name=args.group_name)
|
||||
if not group:
|
||||
raise pagure.exceptions.PagureException(
|
||||
"The group %r does not exist" % args.group_name
|
||||
)
|
||||
|
||||
if group.user_id == user.id:
|
||||
raise pagure.exceptions.PagureException(
|
||||
"The group %r was already created by user %r" % (args.group_name, args.new_creator)
|
||||
)
|
||||
|
||||
previous_creator = group.creator.username
|
||||
group.user_id = user.id
|
||||
session.commit()
|
||||
print("Group %r was transfered from %r to %r." % (args.group_name, previous_creator, args.new_creator))
|
||||
|
||||
def main():
|
||||
# Parse the arguments
|
||||
args = parse_arguments()
|
||||
if "PAGURE_CONFIG" not in os.environ and os.path.exists(
|
||||
"/etc/pagure/pagure.cfg"
|
||||
):
|
||||
print("Using configuration file `/etc/pagure/pagure.cfg`")
|
||||
os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg"
|
||||
_config = pagure.config.reload_config()
|
||||
session = pagure.lib.model_base.create_session(_config["DB_URL"])
|
||||
try:
|
||||
transfer_group(session, args)
|
||||
finally:
|
||||
session.remove()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
|
@ -306,6 +306,19 @@
|
|||
- distgit
|
||||
- mass-branching
|
||||
|
||||
- name: Deploy the pagure group transfer script
|
||||
ansible.builtin.copy:
|
||||
src: pagure_transfer_group.py
|
||||
dest: /usr/local/bin/pagure_transfer_group.py
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
when: env == 'staging'
|
||||
tags:
|
||||
- config
|
||||
- distgit
|
||||
- scripts
|
||||
|
||||
# -- Lookaside Cache -------------------------------------
|
||||
# This is the annex to Dist Git, where we host source tarballs.
|
||||
- name: Install the Lookaside Cache httpd configs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue