agent: limit provisionning to some commands (#72478)

- authentic2.custom_user.management.commands.fix-attributes
- authentic2.management.commands.check-and-repair
- authentic2.management.commands.clean-unused-accounts
- authentic2.management.commands.cleanupauthentic
- authentic2.management.commands.deactivate-orphaned-ldap-users
- authentic2.management.commands.import_site
- authentic2.management.commands.sync-ldap-users
- authentic2_auth_oidc.management.commands.oidc-sync-provider
- hobo.multitenant.management.commands.runscript
This commit is contained in:
Benjamin Dauvergne 2022-12-16 09:27:52 +01:00
parent 3b11215c9f
commit a917ec7fec
1 changed files with 24 additions and 6 deletions

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import importlib
from authentic2.a2_rbac.signals import post_soft_create, post_soft_delete
from django.apps import AppConfig
from django.conf import settings
@ -49,12 +51,28 @@ class Authentic2AgentConfig(AppConfig):
post_soft_create.connect(engine.post_soft_create)
post_soft_delete.connect(engine.post_soft_delete)
from django.core.management.base import BaseCommand
# must use importlib.import_module as command's module names are not
# proper python symbols
commands_to_provision = [
'authentic2.custom_user.management.commands.fix-attributes',
'authentic2.management.commands.check-and-repair',
'authentic2.management.commands.clean-unused-accounts',
'authentic2.management.commands.cleanupauthentic',
'authentic2.management.commands.deactivate-orphaned-ldap-users',
'authentic2.management.commands.import_site',
'authentic2.management.commands.sync-ldap-users',
'authentic2_auth_oidc.management.commands.oidc-sync-provider',
'django.contrib.auth.management.commands.createsuperuser',
'hobo.multitenant.management.commands.runscript',
]
old_execute = BaseCommand.execute
def make_execute(old_execute):
def new_execute(self, *args, **kwargs):
with engine:
return old_execute(self, *args, **kwargs)
def new_execute(self, *args, **kwargs):
with engine:
return old_execute(self, *args, **kwargs)
return new_execute
BaseCommand.execute = new_execute
for command_to_provision in commands_to_provision:
module = importlib.import_module(command_to_provision)
module.Command.execute = make_execute(module.Command.execute)