本文整理汇总了Python中privacyidea.model.meta.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类privacyidea.model.meta.Session
的用法示例。
在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deleteToken
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
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
示例2: delete
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
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
示例3: get_options
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
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
示例4: get_token_in_realm
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def get_token_in_realm(realm, active=True):
'''
This returns the number of tokens in one realm.
You can either query only active token or also disabled tokens.
'''
if active:
sqlQuery = Session.query(TokenRealm, Realm, Token).filter(and_(
TokenRealm.realm_id == Realm.id,
Realm.name == u'' + realm,
Token.privacyIDEAIsactive == True,
TokenRealm.token_id == Token.privacyIDEATokenId)).count()
else:
sqlQuery = Session.query(TokenRealm, Realm).filter(and_(
TokenRealm.realm_id == Realm.id,
Realm.name == realm)).count()
return sqlQuery
示例5: _get_machinetoken_id
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def _get_machinetoken_id(machine_id, token_id, application):
r = None
sqlquery = Session.query(MachineToken.id)\
.filter(and_(MachineToken.token_id == token_id,
MachineToken.machine_id == machine_id,
MachineToken.application == application))
for row in sqlquery:
r = row.id
return r
示例6: deltoken
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def deltoken(machine_name, serial, application):
"""
Delete a machine token.
Also deletes the corresponding MachineTokenOptions
"""
machine_id = _get_machine_id(machine_name)
token_id = _get_token_id(serial)
mtid = _get_machinetoken_id(machine_id, token_id, application)
num = Session.query(MachineToken).\
filter(and_(MachineToken.token_id == token_id,
MachineToken.machine_id == machine_id,
MachineToken.application == application)).delete()
Session.query(MachineTokenOptions).\
filter(MachineTokenOptions.machinetoken_id == mtid).delete()
Session.commit()
# 1 -> success
return num == 1
示例7: deltoken
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
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
示例8: _retrieveConfigDB
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def _retrieveConfigDB(Key):
## prepend "lonotp." if required
key = Key
if (not key.startswith("privacyidea.")):
if (not key.startswith("encprivacyidea.")):
key = "privacyidea." + Key
myVal = None
key = u'' + key
for theConf in Session.query(Config).filter(Config.Key == key):
myVal = theConf.Value
myVal = _expandHere(myVal)
return myVal
示例9: show
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def show(name=None, client_ip=None):
res = {}
cond_list = []
if name:
cond_list.append(Machine.cm_name == name)
if client_ip:
cond_list.append(Machine.cm_ip == client_ip)
condition = and_(*cond_list)
sqlquery = Session.query(Machine).filter(condition)
for machine in sqlquery:
res[machine.cm_name] = machine.to_json()
return res
示例10: lookup_challenge
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def lookup_challenge(self, state=0):
'''
database lookup to find all challenges belonging to a token and or
if exist with a transaction state
:param state: the optional parameter identified the state/transactionId
:return: the list of challenges
'''
challenges = []
if state == 0:
challenges = Session.query(Challenge).\
filter(Challenge.tokenserial == self.token.getSerial()).\
all()
else:
challenges = Session.query(Challenge).\
filter(Challenge.tokenserial == self.token.getSerial()).\
filter(Challenge.transid == state).\
all()
return challenges
示例11: get_challenges
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def get_challenges(serial=None, transid=None):
'''
get_challenges - give all challenges for a given token
:param serial: serial of the token
:param transid: transaction id, if None, all will be retrieved
:return: return a list of challenge dict
'''
challenges = []
if transid is None and serial is None:
return challenges
if transid is None:
db_challenges = Session.query(Challenge)\
.filter(Challenge.tokenserial == u'' + serial)\
.order_by(desc(Challenge.id))\
.all()
else:
db_challenges = Session.query(Challenge)\
.filter(Challenge.transid == transid)\
.all()
challenges.extend(db_challenges)
return challenges
示例12: set_config
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def set_config(key, value, typ, description=None):
'''
create an intial config entry, if it does not exist
:param key: the key
:param value: the value
:param description: the description of the key
:return: nothing
'''
count = Session.query(model.Config).filter(
model.Config.Key == "privacyidea." + key).count()
if count == 0:
config_entry = model.Config(key, value, Type=typ, Description=description)
Session.add(config_entry)
return
示例13: _removeConfigDB
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def _removeConfigDB(key):
if (not key.startswith("privacyidea.")):
if not key.startswith('encprivacyidea.'):
key = u"privacyidea." + key
confEntries = Session.query(Config).filter(Config.Key == unicode(key))
num = confEntries.count()
if num == 1:
theConf = confEntries[0]
try:
#Session.add(theConf)
Session.delete(theConf)
except Exception as e:
log.error('failed')
raise ConfigAdminError("remove Config failed for %r: %r"
% (key, e), id=1133)
return num
示例14: delete_challenges
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def delete_challenges(self, challenges):
'''
delete challenges, which match those listed ones
:param challenges: list of (dict|int|str) challenges
:return: result of the delete operation
'''
challenge_ids = []
for challenge in challenges:
if type(challenge) == dict:
if challenge.has_key('id'):
challenge_id = challenge.get('id')
elif type(challenge) == Challenge:
challenge_id = challenge.get('id')
elif type(challenge) in (unicode , str , int):
challenge_id = challenge
try:
challenge_ids.append(int(challenge_id))
except ValueError:
## ignore
LOG.warning("failed to concert the challengeId %r to int()" %
challenge_id)
res = 1
# 1. get all challeges which are to be deleted
# 2. self.token.select_challenges()
if len(challenge_ids) > 0:
del_challes = Session.query(Challenge).\
filter(Challenge.tokenserial == u'' + self.token.getSerial()).\
filter(Challenge.id.in_(challenge_ids)).all()
for dell in del_challes:
Session.delete(dell)
#pass
return res
示例15: deloption
# 需要导入模块: from privacyidea.model.meta import Session [as 别名]
# 或者: from privacyidea.model.meta.Session import query [as 别名]
def deloption(mtid=None,
name=None,
serial=None,
application=None,
key=None):
"""
delete option from a machine token definition
:param mtid: id of the machinetoken
:param name: the machine name
:param serial: the serial number of the token
:param app: the application
"""
if not mtid:
mtid = _get_machinetoken_id(_get_machine_id(name),
_get_token_id(serial),
application)
num = Session.query(MachineTokenOptions).\
filter(and_(MachineTokenOptions.machinetoken_id == mtid,
MachineTokenOptions.mt_key == key)).delete()
Session.commit()
return num == 1