From eb89966ca5dbf82a5dd6503551aaf7c3aad699f2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 05 2019 09:59:30 +0000 Subject: Add an update-acls action to pagure-admin Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/cli/admin.py b/pagure/cli/admin.py index 1c64290..2274efe 100644 --- a/pagure/cli/admin.py +++ b/pagure/cli/admin.py @@ -30,6 +30,7 @@ if "PAGURE_CONFIG" not in os.environ and os.path.exists( import pagure.config # noqa: E402 import pagure.exceptions # noqa: E402 import pagure.lib.git # noqa: E402 +import pagure.lib.model # noqa: E402 import pagure.lib.model_base # noqa: E402 import pagure.lib.query # noqa: E402 import pagure.lib.tasks_utils # noqa: E402 @@ -422,6 +423,22 @@ def _parser_delete_project(subparser): local_parser.set_defaults(func=do_delete_project) +def _parser_update_acls(subparser): + """ Set up the CLI argument parser for the update-acls action. + + :arg subparser: an argparse subparser allowing to have action's specific + arguments + + """ + local_parser = subparser.add_parser( + "update-acls", + help="Update the ACLs stored in the database with the ones defined " + "in the configuration file (addition only, no ACLs are removed from " + "the database).", + ) + local_parser.set_defaults(func=do_update_acls) + + def parse_arguments(args=None): """ Set-up the argument parsing. """ parser = argparse.ArgumentParser( @@ -480,6 +497,9 @@ def parse_arguments(args=None): # delete-project _parser_delete_project(subparser) + # update-acls + _parser_update_acls(subparser) + return parser.parse_args(args) @@ -785,6 +805,22 @@ def do_delete_project(args): print("Project deleted") +def do_update_acls(args): + """ Update the ACLs in the database from the list present in the + configuration file. + + :arg args: the argparse object returned by ``parse_arguments()``. + + """ + acls = _config.get("ACLS", {}) + _log.debug("ACLS: %s", acls) + + model.create_default_status(scopedsession, acls=_config.get("ACLS", {})) + print( + "ACLS in the database synced with the list in the configuration file" + ) + + def do_get_watch_status(args): """ Get the watch status of an user on a project.