本文整理汇总了Python中clacks.common.error.ClacksErrorHandler.make_error方法的典型用法代码示例。如果您正苦于以下问题:Python ClacksErrorHandler.make_error方法的具体用法?Python ClacksErrorHandler.make_error怎么用?Python ClacksErrorHandler.make_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clacks.common.error.ClacksErrorHandler
的用法示例。
在下文中一共展示了ClacksErrorHandler.make_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def process(self, obj, key, valDict, maxGidValue=65500, maxUidValue=65500):
try:
maxUidValue = int(maxUidValue)
maxGidValue = int(maxGidValue)
except ValueError:
raise PosixException(C.make_error("PARAMETER_NOT_NUMERIC", "GenerateIDs"))
if "uidNumber" in valDict:
if not(len(valDict['uidNumber']['value'])):
if len(valDict["uidNumber"]['backend']) > 1:
raise PosixException(C.make_error("BACKEND_TOO_MANY", "GenerateIDs"))
be = ObjectBackendRegistry.getBackend(valDict["uidNumber"]['backend'][0])
uid = be.get_next_id("uidNumber")
if uid > maxUidValue:
raise PosixException(C.make_error("POSIX_ID_POOL_EMPTY", "uidNumber", max=maxUidValue))
valDict["uidNumber"]['value'] = [uid]
if "gidNumber" in valDict:
if not(len(valDict['gidNumber']['value'])):
if len(valDict["gidNumber"]['backend']) > 1:
raise PosixException(C.make_error("BACKEND_TOO_MANY", "GenerateIDs"))
be = ObjectBackendRegistry.getBackend(valDict["gidNumber"]['backend'][0])
gid = be.get_next_id("gidNumber")
if gid > maxGidValue:
raise PosixException(C.make_error("POSIX_ID_POOL_EMPTY", "gidNumber", max=maxGidValue))
valDict["gidNumber"]['value'] = [gid]
return key, valDict
示例2: getObjectProperty
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def getObjectProperty(self, user, ref, name):
"""
Get a property of an existing stack object.
================= ==========================
Parameter Description
================= ==========================
ref UUID / object reference
name Property name
================= ==========================
``Return``: mixed
"""
objdsc = self.__get_ref(ref)
if not objdsc:
raise ValueError(C.make_error("REFERENCE_NOT_FOUND", ref=ref))
if not name in objdsc['object']['properties']:
raise ValueError(C.make_error("PROPERTY_NOT_FOUND", property=name))
if not self.__check_user(ref, user):
raise ValueError(C.make_error("NO_OBJECT_OWNER"))
if not self.__can_be_handled_locally(ref):
proxy = self.__get_proxy(ref)
return proxy.getObjectProperty(ref, name)
return getattr(objdsc['object']['object'], name)
示例3: setUserPassword
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [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()
示例4: lockAccountPassword
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [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()
示例5: dispatchObjectMethod
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def dispatchObjectMethod(self, user, ref, method, *args):
"""
Call a member method of the referenced object.
================= ==========================
Parameter Description
================= ==========================
ref UUID / object reference
method Method name
args Arguments to pass to the method
================= ==========================
``Return``: mixed
"""
objdsc = self.__get_ref(ref)
if not objdsc:
raise ValueError(C.make_error("REFERENCE_NOT_FOUND", ref=ref))
if not method in objdsc['object']['methods']:
raise ValueError(C.make_error("METHOD_NOT_FOUND", method=method))
if not self.__check_user(ref, user):
raise ValueError(C.make_error("NO_OBJECT_OWNER"))
#TODO: need to implement dispatchObjectMethodAsUser
#if not self.__can_be_handled_locally(ref):
# proxy = self.__get_proxy(ref)
# return proxy.dispatchObjectMethodAsUser(user, ref, method, *args)
return getattr(objdsc['object']['object'], method)(*args)
示例6: retract
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def retract(self, extension):
"""
Retracts an extension from the current object
"""
if not extension in self.__extensions:
raise ProxyException(C.make_error('OBJECT_EXTENSION_NOT_ALLOWED', extension=extension))
if self.__extensions[extension] is None:
raise ProxyException(C.make_error('OBJECT_NO_SUCH_EXTENSION', extension=extension))
# Collect all extensions that are required due to dependencies..
oTypes = self.__factory.getObjectTypes()
for ext in self.__extensions:
if self.__extensions[ext]:
if extension in oTypes[ext]['requires']:
raise ProxyException(C.make_error('OBJECT_EXTENSION_IN_USE', extension=extension, origin=ext))
# Check Acls
# Required is the 'd' (delete) right for the extension on the current object.
if self.__current_user is not None:
topic = "%s.objects.%s" % (self.__env.domain, extension)
if not self.__acl_resolver.check(self.__current_user, topic, "d", base=self.__base.dn):
self.__log.debug("user '%s' has insufficient permissions to add extension %s to %s, required is %s:%s on %s" % (
self.__current_user, extension, self.__base.dn, topic, "d", self.__base.dn))
raise ACLException(C.make_error('PERMISSION_RETRACT', extension=extension, target=self.__base.dn))
# Move the extension to retractions
self.__retractions[extension] = self.__extensions[extension]
self.__extensions[extension] = None
示例7: extensionExists
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [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
示例8: process
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def process(self, obj, key, valDict):
# Create a dictionary with all relevant samba attributes.
alist = ['CtxCallback', 'CtxCallbackNumber', 'CtxCfgFlags1', 'CtxCfgPresent',
'CtxInitialProgram', 'CtxKeyboardLayout', 'CtxMaxConnectionTime',
'CtxMaxDisconnectionTime', 'CtxMaxIdleTime', 'Ctx_flag_connectClientDrives',
'CtxMinEncryptionLevel', 'oldStorageBehavior',
'CtxNWLogonServer', 'CtxShadow', 'CtxWFHomeDir', 'CtxWFHomeDirDrive',
'CtxWFProfilePath', 'CtxWorkDirectory', 'Ctx_flag_brokenConn',
'Ctx_flag_connectClientPrinters', 'Ctx_flag_defaultPrinter',
'Ctx_flag_inheritMode', 'Ctx_flag_reConn', 'Ctx_shadow', 'Ctx_flag_tsLogin']
# Build up a list of values to encode.
res = {}
for entry in alist:
if not len(valDict[entry]['value']):
raise AttributeError(C.make_error('ATTRIBUTE_MANDATORY', entry))
else:
res[entry] = valDict[entry]['value'][0]
# Encode the sambaMungedDial attribute.
result = SambaMungedDial.encode(res)
valDict[key]['value'] = [result]
return key, valDict
示例9: commandReceived
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def commandReceived(self, ssn, message):
"""
Process incoming commands, coming in with session and message
information.
================= ==========================
Parameter Description
================= ==========================
ssn AMQP session object
message Received AMQP message
================= ==========================
Incoming messages are coming from an
:class:`clacks.common.components.amqp_proxy.AMQPServiceProxy` which
is providing a *reply to* queue as a return channel. The command
result is written to that queue.
"""
# Check for id
if not message.user_id:
raise ValueError(C.make_error("AMQP_MESSAGE_WITHOUT_UID"))
id_ = ''
name = args = err = res = None
try:
req = loads(message.content)
except ServiceRequestNotTranslatable, e:
err = str(e)
req = {'id': id_}
示例10: update
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def update(self, obj):
# Gather information
current = obj.asJSON(True)
saved = self.db.index.find_one({'_uuid': obj.uuid})
if not saved:
raise IndexException(C.make_error('OBJECT_NOT_FOUND', "base", id=obj.uuid))
# Remove old entry and insert new
self.remove_by_uuid(obj.uuid)
self.db.index.save(obj.asJSON(True))
# Has the entry been moved?
if current['dn'] != saved['dn']:
# Adjust all ParentDN entries of child objects
res = self.db.index.find(
{'_parent_dn': re.compile('^(.*,)?%s$' % re.escape(saved['dn']))},
{'_uuid': 1, 'dn': 1, '_parent_dn': 1})
for entry in res:
o_uuid = entry['_uuid']
o_dn = entry['dn']
o_parent = entry['_parent_dn']
n_dn = o_dn[:-len(saved['dn'])] + current['dn']
n_parent = o_parent[:-len(saved['dn'])] + current['dn']
self.db.index.update({'_uuid': o_uuid}, {
'$set': {'dn': n_dn, '_parent_dn': n_parent}})
示例11: build_dn_list
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def build_dn_list(self, rdns, base, data, FixedRDN):
fix = rdns[0]
var = rdns[1:] if len(rdns) > 1 else []
dns = [fix]
# Check if we've have to use a fixed RDN.
if FixedRDN:
return["%s,%s" % (FixedRDN, base)]
# Bail out if fix part is not in data
if not fix in data:
raise DNGeneratorError(C.make_error("ATTRIBUTE_NOT_FOUND", attribute=fix))
# Append possible variations of RDN attributes
if var:
for rdn in permutations(var + [None] * (len(var) - 1), len(var)):
dns.append("%s,%s" % (fix, ",".join(filter(lambda x: x and x in data and data[x], list(rdn)))))
dns = list(set(dns))
# Assemble DN of RDN combinations
dn_list = []
for t in [tuple(d.split(",")) for d in dns]:
ndn = []
for k in t:
ndn.append("%s=%s" % (k, ldap.dn.escape_dn_chars(data[k]['value'][0])))
dn_list.append("+".join(ndn) + "," + base)
return sorted(dn_list, key=len)
示例12: process
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def process(self, obj, key, valDict):
if len(valDict[key]['value']) and type(valDict[key]['value'][0]) in [str, unicode]:
valDict[key]['value'][0] = valDict[key]['value'][0].rstrip("$")
else:
raise ValueError(C.make_error("TYPE_UNKNOWN", self.__class__.__name__, type=type(valDict[key]['value'])))
return key, valDict
示例13: process
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def process(self, req, environ):
"""
Process an incoming JSONRPC request and dispatch it thru the
*CommandRegistry*.
================= ==========================
Parameter Description
================= ==========================
req Incoming Request
environ WSGI environment
================= ==========================
``Return``: varries
"""
# Handle OPTIONS
if req.method == 'OPTIONS':
return Response(
server=self.ident,
allow='POST'
)
if not req.method == 'POST':
raise exc.HTTPMethodNotAllowed(
"Only POST allowed",
allow='POST').exception
try:
json = loads(req.body)
except ValueError, e:
raise ValueError(C.make_error("INVALID_JSON", data=str(e)))
示例14: get_operator
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def get_operator(name):
for entry in pkg_resources.iter_entry_points("object.operator"):
module = entry.load()
if module.__name__ == name:
return module
raise KeyError(C.make_error("OPERATOR_NO_INSTANCE", operator=name))
示例15: get_filter
# 需要导入模块: from clacks.common.error import ClacksErrorHandler [as 别名]
# 或者: from clacks.common.error.ClacksErrorHandler import make_error [as 别名]
def get_filter(name):
for entry in pkg_resources.iter_entry_points("object.filter"):
module = entry.load()
if module.__name__ == name:
return module
raise KeyError(C.make_error("FILTER_NO_INSTANCE", name))