mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipalib: provide per-call command context
Add context which is valid for the duration of command call. The context is accessible using the `context` attribute of Command and Object plugins. Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
committed by
Martin Basti
parent
6851e560dd
commit
e5520dc347
@@ -38,6 +38,7 @@ from ipalib.errors import (ZeroArgumentError, MaxArgumentError, OverlapError,
|
||||
VersionError, OptionError, InvocationError,
|
||||
ValidationError, ConversionError)
|
||||
from ipalib import messages
|
||||
from ipalib.request import context, context_frame
|
||||
from ipalib.util import json_serialize
|
||||
|
||||
if six.PY3:
|
||||
@@ -370,6 +371,10 @@ class HasParam(Plugin):
|
||||
check(namespace)
|
||||
setattr(self, name, namespace)
|
||||
|
||||
@property
|
||||
def context(self):
|
||||
return context.current_frame
|
||||
|
||||
|
||||
class Command(HasParam):
|
||||
"""
|
||||
@@ -424,6 +429,11 @@ class Command(HasParam):
|
||||
XML-RPC and the executed an the nearest IPA server.
|
||||
"""
|
||||
self.ensure_finalized()
|
||||
with context_frame():
|
||||
self.context.principal = getattr(context, 'principal', None)
|
||||
return self.__do_call(*args, **options)
|
||||
|
||||
def __do_call(self, *args, **options):
|
||||
version_provided = 'version' in options
|
||||
if version_provided:
|
||||
self.verify_client_version(unicode(options['version']))
|
||||
|
||||
Reference in New Issue
Block a user