better structure of the query and and removing ilike
This commit is contained in:
parent
d58b32a19c
commit
709a9808aa
|
@ -560,16 +560,27 @@ def query_common_name(common_name, args):
|
|||
:return:
|
||||
"""
|
||||
owner = args.pop("owner")
|
||||
if not owner:
|
||||
owner = "%"
|
||||
|
||||
# only not expired certificates
|
||||
current_time = arrow.utcnow()
|
||||
|
||||
if common_name == "%" and not owner:
|
||||
result = (
|
||||
Certificate.query.filter(Certificate.cn.ilike(common_name))
|
||||
.filter(Certificate.owner.ilike(owner))
|
||||
.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
|
||||
Certificate.query.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
|
||||
.all()
|
||||
)
|
||||
elif common_name == "%":
|
||||
# all valid certs from the owner
|
||||
result = (
|
||||
Certificate.query.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
|
||||
.filter(Certificate.owner == owner)
|
||||
.all()
|
||||
)
|
||||
else:
|
||||
# search based on owner and cn
|
||||
result = (
|
||||
Certificate.query.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
|
||||
.filter(Certificate.cn.like(common_name))
|
||||
.filter(Certificate.owner == owner)
|
||||
.all()
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue