本文整理匯總了Python中clacks.common.components.PluginRegistry.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Python PluginRegistry.getInstance方法的具體用法?Python PluginRegistry.getInstance怎麽用?Python PluginRegistry.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類clacks.common.components.PluginRegistry
的用法示例。
在下文中一共展示了PluginRegistry.getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setSambaPassword
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def setSambaPassword(self, user, object_dn, password):
"""
Set a new samba-password for a user
"""
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "sambaNTPassword")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "w", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to write %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "w")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "sambaLMPassword")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "w", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to write %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "w")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
# Set the password and commit the changes
lm, nt = smbpasswd.hash(password)
user = ObjectProxy(object_dn)
user.sambaNTPassword = nt
user.sambaLMPassword = lm
user.commit()
示例2: accountUnlockable
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def accountUnlockable(self, user, object_dn):
index = PluginRegistry.getInstance("ObjectIndex")
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "isLocked")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "r", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to read %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "r")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
res = index.search({"dn": object_dn, "userPassword": {"$size": 1}}, {"userPassword": 1})
if res.count():
hsh = res[0]["userPassword"][0]
else:
# No password hash -> cannot lock/unlock account
return False
# Try to detect the responsible password method-class
pwd_o = self.detect_method_by_hash(hsh)
if not pwd_o:
# Could not identify password method
return False
return pwd_o.isUnlockable(hsh)
示例3: serve
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def serve(self):
""" Start AMQP service for this clacks service provider. """
# Load AMQP and Command registry instances
amqp = PluginRegistry.getInstance('AMQPHandler')
self.__cr = PluginRegistry.getInstance('CommandRegistry')
# Create a list of queues we need here
queues = {}
for dsc in self.__cr.commands.values():
queues[dsc['target']] = True
# Finally create the queues
for queue in queues:
# Add round robin processor for queue
self.__cmdWorker = AMQPWorker(self.env, connection=amqp.getConnection(),
r_address='%s.command.%s; { create:always, node:{ type:queue, x-bindings:[ { exchange:"amq.direct", queue:"%s.command.%s" } ] } }' % (self.env.domain, queue, self.env.domain, queue),
workers=int(self.env.config.get('amqp.worker', default=1)),
callback=self.commandReceived)
# Add private processor for queue
self.__cmdWorker = AMQPWorker(self.env, connection=amqp.getConnection(),
r_address='%s.command.%s.%s; { create:always, delete:receiver, node:{ type:queue, x-bindings:[ { exchange:"amq.direct", queue:"%s.command.%s.%s" } ] } }' % (self.env.domain, queue, self.env.id, self.env.domain, queue, self.env.id),
workers=int(self.env.config.get('amqp.worker', default=1)),
callback=self.commandReceived)
# Announce service
if self.env.config.get("amqp.announce", default="True").lower() == "true":
url = parseURL(self.env.config.get("amqp.url"))
self.__zeroconf = ZeroconfService(name="Clacks RPC service",
port=url['port'],
stype="_%s._tcp" % url['scheme'],
text=dict_to_txt_array({'path': self.env.domain, 'service': 'clacks'}))
self.__zeroconf.publish()
self.log.info("ready to process incoming requests")
示例4: __dbus_proxy_monitor
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def __dbus_proxy_monitor(self, bus_name):
"""
This method monitors the DBus service 'org.clacks' and whenever there is a
change in the status (dbus closed/startet) we will take notice.
And can register or unregister methods to the dbus
"""
if "org.clacks" in self.bus.list_names():
if self.clacks_dbus:
del(self.clacks_dbus)
self.clacks_dbus = self.bus.get_object('org.clacks', '/org/clacks/notify')
ccr = PluginRegistry.getInstance('ClientCommandRegistry')
ccr.register("notify", 'Notify.notify', [], \
['user', 'title', 'message', 'timeout', 'icon'], \
'Sent a notification to a given user')
ccr.register("notify_all", 'Notify.notify_all', [], \
['title', 'message', 'timeout', 'icon'], \
'Sent a notification to a given user')
amcs = PluginRegistry.getInstance('AMQPClientService')
amcs.reAnnounce()
self.log.info("established dbus connection")
else:
if self.clacks_dbus:
del(self.clacks_dbus)
# Trigger resend of capapability event
ccr = PluginRegistry.getInstance('ClientCommandRegistry')
ccr.unregister("notify")
ccr.unregister("notify_all")
amcs = PluginRegistry.getInstance('AMQPClientService')
amcs.reAnnounce()
self.log.info("lost dbus connection")
else:
self.log.info("no dbus connection")
示例5: __dbus_proxy_monitor
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def __dbus_proxy_monitor(self, bus_name):
"""
This method monitors the DBus service 'org.clacks' and whenever there is a
change in the status (dbus closed/startet) we will take notice.
And can stop or restart singature checking.
"""
if "org.clacks" in self.bus.list_names():
if self.clacks_dbus:
del(self.clacks_dbus)
self.clacks_dbus = self.bus.get_object('org.clacks', '/org/clacks/shell')
self.clacks_dbus.connect_to_signal("_signatureChanged", self.__signatureChanged_received, dbus_interface="org.clacks")
self.log.info("established dbus connection")
self.__signatureChanged_received(None)
# Trigger resend of capapability event
ccr = PluginRegistry.getInstance('ClientCommandRegistry')
ccr.register("listDBusMethods", 'DBUSProxy.listDBusMethods', [], [], 'This method lists all callable dbus methods')
ccr.register("callDBusMethod", 'DBUSProxy.callDBusMethod', [], ['method', '*args'], \
'This method allows to access registered dbus methods by forwarding methods calls')
amcs = PluginRegistry.getInstance('AMQPClientService')
amcs.reAnnounce()
else:
if self.clacks_dbus:
del(self.clacks_dbus)
self.__signatureChanged_received(None)
self.log.info("lost dbus connection")
# Trigger resend of capapability event
ccr = PluginRegistry.getInstance('ClientCommandRegistry')
ccr.unregister("listDBusMethods")
ccr.unregister("callDBusMethod")
amcs = PluginRegistry.getInstance('AMQPClientService')
amcs.reAnnounce()
else:
self.log.info("no dbus connection")
示例6: _convert_to_unicodestring
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def _convert_to_unicodestring(self, value):
rom = PluginRegistry.getInstance("JSONRPCObjectMapper")
cr = PluginRegistry.getInstance("CommandRegistry")
new_value = []
for item in value:
uuid = item["__jsonclass__"][1][1]
new_value.append(rom.dispatchObjectMethod(uuid, "dump"))
cr.call("closeObject", uuid)
return new_value
示例7: searchForObjectDetails
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def searchForObjectDetails(self, user, extension, attribute, fltr, attributes, skip_values):
"""
Search selectable items valid for the attribute "extension.attribute".
This is used to add new groups to the users groupMembership attribute.
"""
# Extract the the required information about the object
# relation out of the BackendParameters for the given extension.
of = ObjectFactory.getInstance()
be_data = of.getObjectBackendParameters(extension, attribute)
if not be_data:
raise GOsaException(C.make_error("BACKEND_PARAMETER_MISSING", extension=extension, attribute=attribute))
# Collection basic information
otype, oattr, foreignMatchAttr, matchAttr = be_data[attribute] #@UnusedVariable
# Create a list of attributes that will be requested
if oattr not in attributes:
attributes.append(oattr)
attrs = dict([(x, 1) for x in attributes])
if not "dn" in attrs:
attrs.update({'dn': 1})
# Start the query and brind the result in a usable form
index = PluginRegistry.getInstance("ObjectIndex")
res = index.search({
'$or': [{'_type': otype}, {'_extensions': otype}],
oattr: re.compile("^.*" + re.escape(fltr) + ".*$")
}, attrs)
result = []
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s" % (env.domain, otype)
aclresolver = PluginRegistry.getInstance("ACLResolver")
for entry in res:
if not aclresolver.check(user, topic, "s", base=entry['dn']):
continue
item = {}
for attr in attributes:
if attr in entry and len(entry[attr]):
item[attr] = entry[attr] if attr == "dn" else entry[attr][0]
else:
item[attr] = ""
item['__identifier__'] = item[oattr]
# Skip values that are in the skip list
if skip_values and item['__identifier__'] in skip_values:
continue
result.append(item)
return result
示例8: get_adjusted_parent_dn
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def get_adjusted_parent_dn(self, dn=None):
index = PluginRegistry.getInstance("ObjectIndex")
tdn = []
pdn = self.get_parent_dn(dn)
# Skip base
if len(pdn) < len(self.__env.base):
return pdn
while True:
if pdn == self.__env.base or len(pdn) < len(self.__env.base):
break
# Fetch object type for pdn
ptype = index.search({"dn": pdn}, {'_type': 1})[0]['_type']
schema = self.__factory.getXMLSchema(ptype)
if not ("StructuralInvisible" in schema.__dict__ and schema.StructuralInvisible == True):
#tdn.insert(0, str2dn(pdn.encode('utf-8'))[0])
tdn.append(str2dn(pdn.encode('utf-8'))[0])
pdn = self.get_parent_dn(pdn)
tdn = str2dn(self.__env.base.encode('utf-8'))[::-1] + tdn[::-1]
return dn2str(tdn[::-1]).decode('utf-8')
示例9: resolve
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def resolve(self, number):
number = self.replaceNumber(number)
index = PluginRegistry.getInstance("ObjectIndex")
res = index.search({'_type': 'User', 'telephoneNumber': str(number)},
{'dn': 1})
if res.count() == 1:
obj = ObjectProxy(res[0]['dn'])
result = {
'company_id': '',
'company_name': 'Intern',
'company_phone': '',
'company_detail_url': '',
'contact_id': obj.uid,
'contact_name': obj.cn,
'contact_phone': obj.telephoneNumber[0],
'contact_detail_url': '',
'avatar': obj.jpegPhoto.get() if obj.jpegPhoto else None,
'ldap_uid': obj.uid,
'resource': 'ldap',
}
return result
return None
示例10: serve
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def serve(self):
# Collect value extenders
self.__value_extender = clacks.agent.objects.renderer.get_renderers()
self.__search_aid = PluginRegistry.getInstance("ObjectIndex").get_search_aid()
# Load DB instance
self.db = self.env.get_mongo_db('clacks')
示例11: setUserPassword
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def setUserPassword(self, user, object_dn, password):
"""
Set a new password for a user
"""
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "userPassword")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "w", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to write %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "w")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
user = ObjectProxy(object_dn)
method = user.passwordMethod
# Try to detect the responsible password method-class
pwd_o = self.get_method_by_method_type(method)
if not pwd_o:
raise PasswordException(C.make_error("PASSWORD_UNKNOWN_HASH", type=method))
# Generate the new password hash usind the detected method
pwd_str = pwd_o.generate_password_hash(password, method)
# Set the password and commit the changes
user.userPassword = pwd_str
user.commit()
示例12: lockAccountPassword
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def lockAccountPassword(self, user, object_dn):
"""
Locks the account password for the given DN
"""
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "userPassword")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "w", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to write %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "w")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
# Get the object for the given dn
user = ObjectProxy(object_dn)
# Check if there is a userPasswort available and set
if not "userPassword" in user.get_attributes():
raise PasswordException(C.make_error("PASSWORD_NO_ATTRIBUTE"))
if not user.userPassword:
raise PasswordException(C.make_error("PASSWORD_NOT_AVAILABLE"))
# Try to detect the responsible password method-class
pwd_o = self.detect_method_by_hash(user.userPassword)
if not pwd_o:
raise PasswordException(C.make_error("PASSWORD_METHOD_UNKNOWN"))
# Lock the hash and save it
user.userPassword = pwd_o.lock_account(user.userPassword)
user.commit()
示例13: serve
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def serve(self):
"""
Start the scheduler service.
"""
self.sched.start()
# Start migration job
self.sched.add_interval_job(self.migrate, seconds=60, tag="_internal", jobstore="ram")
# Notify others about local scheduler job changes
self.sched.add_listener(
self.__notify, EVENT_JOBSTORE_JOB_REMOVED | EVENT_JOBSTORE_JOB_ADDED | EVENT_JOB_EXECUTED
)
# Get notified by others about remote job changes
amqp = PluginRegistry.getInstance("AMQPHandler")
EventConsumer(
self.env,
amqp.getConnection(),
xquery="""
declare namespace f='http://www.gonicus.de/Events';
let $e := ./f:Event
return $e/f:SchedulerUpdate
and $e/f:Id != '%s'
"""
% self.env.id,
callback=self.__eventProcessor,
)
示例14: extensionExists
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def extensionExists(self, userid, dn, etype):
index = PluginRegistry.getInstance("ObjectIndex")
res = index.search({'_type': 'User', 'dn': dn}, {'_extensions': 1})
if not res.count():
raise GOsaException(C.make_error("UNKNOWN_USER", userid))
return etype in res[0]['_extensions'] if '_extensions' in res[0] else False
示例15: resolve
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import getInstance [as 別名]
def resolve(self, number):
number = self.replaceNumber(number)
index = PluginRegistry.getInstance("ObjectIndex")
res = index.search({"_type": "User", "telephoneNumber": str(number)}, {"dn": 1})
if res.count() != 1:
res = index.search({"_type": "User", "uid": str(number)}, {"dn": 1})
if res.count() == 1:
obj = ObjectProxy(res[0]["dn"])
result = {
"company_id": "",
"company_name": "Intern",
"company_phone": "",
"company_detail_url": "",
"contact_id": obj.uid,
"contact_name": obj.cn,
"contact_phone": obj.telephoneNumber[0],
"contact_detail_url": "",
"avatar": obj.jpegPhoto.get() if obj.jpegPhoto else None,
"ldap_uid": obj.uid,
"resource": "ldap",
}
return result
return None