本文整理汇总了Python中privacyidea.model.meta.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __before__
def __before__(self, action, **params):
'''
'''
try:
c.audit['success'] = False
c.audit['client'] = get_client()
self.Policy = PolicyClass(request, config, c,
get_privacyIDEA_config(),
tokenrealms=request.params.get('serial'),
token_type_list=get_token_type_list())
self.set_language()
self.before_identity_check(action)
Session.commit()
return request
except webob.exc.HTTPUnauthorized as acc:
# the exception, when an abort() is called if forwarded
log.info("%r: webob.exception %r" % (action, acc))
log.info(traceback.format_exc())
Session.rollback()
Session.close()
raise acc
except Exception as exx:
log.error("exception %r" % (action, exx))
log.error(traceback.format_exc())
Session.rollback()
Session.close()
return sendError(response, exx, context='before')
finally:
pass
示例2: deleteToken
def deleteToken(self):
# some DBs (eg. DB2) run in deadlock, if the TokenRealm entry
# is deleteted via foreign key relation
# so we delete it explicit
Session.query(TokenRealm).filter(TokenRealm.token_id == self.privacyIDEATokenId).delete()
Session.delete(self)
return True
示例3: __init__
def __init__(self, machinetoken_id, key, value):
log.debug("setting %r to %r for MachineToken %s" % (key,
value,
machinetoken_id))
self.machinetoken_id = machinetoken_id
self.mt_key = key
self.mt_value = value
Session.add(self)
Session.commit()
示例4: deltoken
def deltoken(machine_name, serial, application):
machine_id = _get_machine_id(machine_name)
token_id = _get_token_id(serial)
num = Session.query(MachineToken).\
filter(and_(MachineToken.token_id == token_id,
MachineToken.machine_id == machine_id,
MachineToken.application == application)).delete()
Session.commit()
# 1 -> success
return num == 1
示例5: get_resolver_list
def get_resolver_list(self, action, **params):
res = {}
try:
from privacyidea.config.environment import get_resolver_list as getlist
list = getlist()
res['resolverlist'] = [l for l in list]
res['resolvertypes'] = [l.split(".")[-1] for l in list]
return sendResult(response, res, 1)
except Exception as exx:
Session.rollback()
return sendError(response, exx)
finally:
Session.close()
示例6: delete
def delete(self, action, **params):
'''
Delete an existing client machine entry
:param name: the unique name of the machine
:return: value is either true (success) or false (fail)
'''
try:
res = {}
param = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'delete')
param.update(request.params)
machine_name = getParam(param, "name", required)
res = delete_machine(machine_name)
Session.commit()
c.audit["success"] = True
return sendResult(response, res, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx:
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
finally:
Session.close()
示例7: delete
def delete(name):
'''
Delete the machine with the name and return the number of deleted machines
Should always be 1
Should be 0 if such a machine did not exist.
'''
mid = _get_machine_id(name)
_assigns = Session.query(MachineToken)\
.filter(MachineToken.machine_id == mid).delete()
num = Session.query(Machine).filter(Machine.cm_name == name).delete()
Session.commit()
# 1 -> success
return num == 1
示例8: __before__
def __before__(self, action, **params):
'''
Here we see, what action is to be called and check the authorization
'''
try:
c.audit['success'] = False
c.audit['client'] = get_client()
self.Policy = PolicyClass(request, config, c,
get_privacyIDEA_config(),
token_type_list = get_token_type_list())
if action != "check_t":
self.before_identity_check(action)
return response
except webob.exc.HTTPUnauthorized as acc:
## the exception, when an abort() is called if forwarded
log.error("%r webob.exception %r" % (action, acc))
log.error(traceback.format_exc())
Session.rollback()
Session.close()
raise acc
except Exception as exx:
log.error("%r exception %r" % (action, exx))
log.error(traceback.format_exc())
Session.rollback()
Session.close()
return sendError(response, exx, context='before')
finally:
pass
示例9: show
def show(self, action, **params):
'''
Returns a list of the client machines.
:param name: Optional parameter to only show this single machine
:return: JSON details
'''
try:
res = {}
param = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'show')
param.update(request.params)
machine_name = getParam(param, "name", optional)
res = show_machine(machine_name)
Session.commit()
c.audit["success"] = True
return sendResult(response, res, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx:
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
finally:
Session.close()
示例10: __before__
def __before__(self, action, **params):
try:
c.audit['client'] = get_client()
self.before_identity_check(action)
except Exception as exx:
log.error("%r exception %r" % (action, exx))
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, exx, context='before')
finally:
Session.close()
示例11: addoption
def addoption(self, action, **params):
'''
Add an option to a machinetoken definition
:param mtid: id of the machine token definition
:param name: machine_name
:param serial: serial number of the token
:param application: application
:param option_*: name of the option.
In case of LUKS application this can be
"option_slot"
You either need to provide the machine-token-id (mtid) directly or
you need to provide the tuple (name, serial, application)
'''
try:
num = -1
param = {}
options = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'addtoken')
param.update(request.params)
mtid = getParam(param, "mtid", optional)
machine_name = getParam(param, "name", optional)
serial = getParam(param, "serial", optional)
application = getParam(param, "application", optional)
if not (mtid or (machine_name and serial and application)):
raise ParameterError("You need to specify either mtid or"
"the tuple name, serial, application",
id=201)
for p in param.keys():
if p.startswith("option_"):
options[p] = param.get(p)
num = addoption(mtid,
name=machine_name,
serial=serial,
application=application,
options=options)
Session.commit()
c.audit["success"] = True
return sendResult(response, num, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx: # pragma: no cover
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
finally:
Session.close()
示例12: addtoken
def addtoken(self, action, **params):
'''
Add a token and a application to a machine
:param name: Name of the machine
:param serial: serial number of the token
:param application: name of the application
:param option_*: parameter is passed as additional option to
the machinetoken to be stored in
machine_t_options table.
In case of LUKS application this can be
"option_slot"
'''
try:
res = False
param = {}
options = {}
# check machine authorization
self.Policy.checkPolicyPre('machine', 'addtoken')
param.update(request.params)
machine_name = getParam(param, "name", required)
serial = getParam(param, "serial", required)
application = getParam(param, "application", required)
if application.lower() not in config.get("applications").keys():
log.error("Unknown application %r. Available applications: "
"%r" % (application,
config.get("applications").keys()))
raise Exception("Unkown application!")
for p in param.keys():
if p.startswith("option_"):
options[p] = param.get(p)
mt = addtoken(machine_name,
serial,
application,
options=options)
if mt:
res = True
Session.commit()
c.audit["success"] = True
return sendResult(response, res, 1)
except PolicyException as pe:
log.error("policy failed: %r" % pe)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(pe))
except Exception as exx: # pragma: no cover
log.error("failed: %r" % exx)
log.error(traceback.format_exc())
Session.rollback()
return sendError(response, unicode(exx), 0)
finally:
Session.close()
示例13: get_options
def get_options(machine_id=None,
token_id=None,
application=None,
machinetoken_id=None):
"""
returns a dictionary of the options for a given tuple
of machine, token and application from the table
MachineTokenOptions.
:param machine_id: id of the machine
:param token_id: id ot the token
:param application: name of the application
:param machinetoken_id: id of the machineToken-entry
:return: option dictionary
You either need to specify (machine_ind, token_id, application) or
the machinetoken_id.
"""
options = {}
if machinetoken_id:
sqlquery = Session.query(MachineTokenOptions).\
filter(MachineTokenOptions.machinetoken_id == machinetoken_id)
for option in sqlquery:
options[option.mt_key] = option.mt_value
elif (machine_id and token_id and application):
raise NotImplementedError("the tuple machine_id, token_id, "
"application is not implemented, yet.")
else:
raise Exception("You either need to specify the machinetoken_id"
"or the tuple token_id, machine_id, application.")
return options
示例14: __before__
def __before__(self, action, **params):
try:
c.audit['client'] = get_client()
self.Policy = PolicyClass(request, config, c,
get_privacyIDEA_config(),
token_type_list = get_token_type_list())
return response
except Exception as exx:
log.error("exception %r" % (action, exx))
log.error(traceback.format_exc())
Session.rollback()
Session.close()
return sendError(response, exx, context='before')
finally:
pass
示例15: __before__
def __before__(self, action, **params):
try:
c.version = get_version()
c.licenseinfo = get_copyright_info()
self.set_language()
except Exception as exx:
log.error("%r exception %r" % (action, exx))
log.error(traceback.format_exc())
Session.rollback()
Session.close()
return sendError(response, exx, context='before')
finally:
pass