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 <abokovoy@redhat.com>
Reviewed-By: Thomas Woerner <twoerner@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Rafael Guterres Jeffman <rjeffman@redhat.com>
This commit is contained in:
Alexander Bokovoy 2024-04-26 19:32:16 +03:00 committed by Antonio Torres
parent 295ac6385c
commit 3608b2b63d
No known key found for this signature in database
GPG Key ID: 359FAF777296F653

View File

@ -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__
)