Merge branch 'master' into up_reqs_3292018

This commit is contained in:
Curtis 2018-03-29 09:11:23 -07:00 committed by GitHub
commit de9c00b293
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

View File

@ -298,16 +298,20 @@ def render(args):
if filt: if filt:
terms = filt.split(';') terms = filt.split(';')
term = '%{0}%'.format(terms[1])
# Exact matches for quotes. Only applies to name, issuer, and cn
if terms[1].startswith('"') and terms[1].endswith('"'):
term = terms[1][1:-1]
if 'issuer' in terms: if 'issuer' in terms:
# we can't rely on issuer being correct in the cert directly so we combine queries # we can't rely on issuer being correct in the cert directly so we combine queries
sub_query = database.session_query(Authority.id)\ sub_query = database.session_query(Authority.id)\
.filter(Authority.name.ilike('%{0}%'.format(terms[1])))\ .filter(Authority.name.ilike(term))\
.subquery() .subquery()
query = query.filter( query = query.filter(
or_( or_(
Certificate.issuer.ilike('%{0}%'.format(terms[1])), Certificate.issuer.ilike(term),
Certificate.authority_id.in_(sub_query) Certificate.authority_id.in_(sub_query)
) )
) )
@ -321,12 +325,20 @@ def render(args):
elif 'cn' in terms: elif 'cn' in terms:
query = query.filter( query = query.filter(
or_( or_(
Certificate.cn.ilike('%{0}%'.format(terms[1])), Certificate.cn.ilike(term),
Certificate.domains.any(Domain.name.ilike('%{0}%'.format(terms[1]))) Certificate.domains.any(Domain.name.ilike(term))
) )
) )
elif 'id' in terms: elif 'id' in terms:
query = query.filter(Certificate.id == cast(terms[1], Integer)) query = query.filter(Certificate.id == cast(terms[1], Integer))
elif 'name' in terms:
query = query.filter(
or_(
Certificate.name.ilike(term),
Certificate.domains.any(Domain.name.ilike(term)),
Certificate.cn.ilike(term),
)
)
else: else:
query = database.filter(query, Certificate, terms) query = database.filter(query, Certificate, terms)