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:
|
:return:
|
||||||
"""
|
"""
|
||||||
owner = args.pop("owner")
|
owner = args.pop("owner")
|
||||||
if not owner:
|
|
||||||
owner = "%"
|
|
||||||
|
|
||||||
# only not expired certificates
|
# only not expired certificates
|
||||||
current_time = arrow.utcnow()
|
current_time = arrow.utcnow()
|
||||||
|
|
||||||
|
if common_name == "%" and not owner:
|
||||||
result = (
|
result = (
|
||||||
Certificate.query.filter(Certificate.cn.ilike(common_name))
|
Certificate.query.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
|
||||||
.filter(Certificate.owner.ilike(owner))
|
.all()
|
||||||
.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
|
)
|
||||||
|
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()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue