From 3608b2b63de736186176f8da0fad36ce3b0d57a3 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Fri, 26 Apr 2024 19:32:16 +0300 Subject: [PATCH] batch: account for auto-binding in server context When batch runs under server context, we have no context.principal set because we talk directly to LDAPI endpoint and authenticate using auto-binding, not GSSAPI. Account to that in the logger. Fixes: https://pagure.io/freeipa/issue/9583 Signed-off-by: Alexander Bokovoy Reviewed-By: Thomas Woerner Reviewed-By: Rob Crittenden Reviewed-By: Rafael Guterres Jeffman --- ipaserver/plugins/batch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ipaserver/plugins/batch.py b/ipaserver/plugins/batch.py index b7fe157d6..13ff1f153 100644 --- a/ipaserver/plugins/batch.py +++ b/ipaserver/plugins/batch.py @@ -159,6 +159,7 @@ class batch(Command): def execute(self, methods=None, **options): results = [] + op_account = getattr(context, 'principal', '[autobind]') for arg in (methods or []): params = dict() name = None @@ -174,7 +175,7 @@ class batch(Command): result = api.Command[name](*a, **newkw) logger.info( '%s: batch: %s(%s): SUCCESS', - getattr(context, 'principal', 'UNKNOWN'), + op_account, name, ', '.join(api.Command[name]._repr_iter(**params)) ) @@ -185,13 +186,13 @@ class batch(Command): isinstance(e, errors.ConversionError)): logger.info( '%s: batch: %s', - context.principal, + op_account, e.__class__.__name__ ) else: logger.info( '%s: batch: %s(%s): %s', - context.principal, name, + op_account, name, ', '.join(api.Command[name]._repr_iter(**params)), e.__class__.__name__ )