adopting ilike and not relying on ==

reducing redundancy
This commit is contained in:
Hossein Shafagh 2020-10-27 12:42:16 -07:00
parent 259a8808f1
commit d59a558d58
1 changed files with 8 additions and 22 deletions

View File

@ -563,34 +563,20 @@ def query_common_name(common_name, args):
# only not expired certificates # only not expired certificates
current_time = arrow.utcnow() current_time = arrow.utcnow()
query = Certificate.query.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))\
.filter(not_(Certificate.revoked))\
.filter(not_(Certificate.replaced.any())) # ignore rotated certificates to avoid duplicates
if common_name == "%" and not owner: if common_name == "%" and not owner:
result = ( return query.all()
Certificate.query.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
.filter(not_(Certificate.revoked))
.filter(not_(Certificate.replaced.any())) # ignore rotated certificates to avoid duplicates
.all()
)
elif common_name == "%": elif common_name == "%":
# all valid certs from the owner # all valid certs from the owner
result = ( query = query.filter(Certificate.owner.ilike(owner))
Certificate.query.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
.filter(Certificate.owner == owner)
.filter(not_(Certificate.revoked))
.filter(not_(Certificate.replaced.any())) # ignore rotated certificates to avoid duplicates
.all()
)
else: else:
# search based on owner and cn # search based on owner and cn
result = ( query = query.filter(Certificate.cn.ilike(common_name)).filter(Certificate.owner.ilike(owner))
Certificate.query.filter(Certificate.not_after >= current_time.format("YYYY-MM-DD"))
.filter(Certificate.cn.ilike(common_name))
.filter(Certificate.owner == owner)
.filter(not_(Certificate.revoked))
.filter(not_(Certificate.replaced.any())) # ignore rotated certificates to avoid duplicates
.all()
)
return result return query.all()
def create_csr(**csr_config): def create_csr(**csr_config):