def get_unresolved_pending_certs(): """ Retrieve a list of unresolved pending certs given a list of ids Filters out non-existing pending certs """ query = database.session_query(PendingCertificate).filter(PendingCertificate.resolved.is_(False)) return database.find_all(query, PendingCertificate, {}).all()
def render(args): sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') certificate_id = args.pop('certificate_id', None) if certificate_id: query = database.session_query(Source).join(Certificate, Source.certificate) query = query.filter(Certificate.id == certificate_id) else: query = database.session_query(Source) if filt: terms = filt.split(';') query = database.filter(query, Source, terms) query = database.find_all(query, Source, args) if sort_by and sort_dir: query = database.sort(query, Source, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): """ Helper that helps us render the REST Api responses. :param args: :return: """ query = database.session_query(Authority) sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') if filt: terms = filt.split(';') if 'active' in filt: # this is really weird but strcmp seems to not work here?? query = query.filter(Authority.active == terms[1]) else: query = database.filter(query, Authority, terms) # we make sure that a user can only use an authority they either own are are a member of - admins can see all if not g.current_user.is_admin: authority_ids = [] for role in g.current_user.roles: if role.authority: authority_ids.append(role.authority.id) query = query.filter(Authority.id.in_(authority_ids)) query = database.find_all(query, Authority, args) if sort_by and sort_dir: query = database.sort(query, Authority, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') certificate_id = args.pop('certificate_id', None) if certificate_id: query = database.session_query(Notification).join( Certificate, Notification.certificate) query = query.filter(Certificate.id == certificate_id) else: query = database.session_query(Notification) if filt: terms = filt.split(';') if terms[0] == 'active' and terms[1] == 'false': query = query.filter(Notification.active == False) # noqa elif terms[0] == 'active' and terms[1] == 'true': query = query.filter(Notification.active == True) # noqa else: query = database.filter(query, Notification, terms) query = database.find_all(query, Notification, args) if sort_by and sort_dir: query = database.sort(query, Notification, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): """ Helper to parse REST Api requests :param args: :return: """ query = database.session_query(Domain).join(Certificate, Domain.certificate) sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') certificate_id = args.pop('certificate_id', None) if filt: terms = filt.split(';') query = database.filter(query, Domain, terms) if certificate_id: query = query.filter(Certificate.id == certificate_id) query = database.find_all(query, Domain, args) if sort_by and sort_dir: query = database.sort(query, Domain, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): sort_by = args.pop("sort_by") sort_dir = args.pop("sort_dir") page = args.pop("page") count = args.pop("count") filt = args.pop("filter") certificate_id = args.pop("certificate_id", None) if certificate_id: query = database.session_query(Notification).join(Certificate, Notification.certificate) query = query.filter(Certificate.id == certificate_id) else: query = database.session_query(Notification) if filt: terms = filt.split(";") if terms[0] == "active" and terms[1] == "false": query = query.filter(Notification.active == False) # noqa elif terms[0] == "active" and terms[1] == "true": query = query.filter(Notification.active == True) # noqa else: query = database.filter(query, Notification, terms) query = database.find_all(query, Notification, args) if sort_by and sort_dir: query = database.sort(query, Notification, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') certificate_id = args.pop('certificate_id', None) if certificate_id: query = database.session_query(Notification).join(Certificate, Notification.certificate) query = query.filter(Certificate.id == certificate_id) else: query = database.session_query(Notification) if filt: terms = filt.split(';') if terms[0] == 'active' and terms[1] == 'false': query = query.filter(Notification.active == False) # noqa elif terms[0] == 'active' and terms[1] == 'true': query = query.filter(Notification.active == True) # noqa else: query = database.filter(query, Notification, terms) query = database.find_all(query, Notification, args) if sort_by and sort_dir: query = database.sort(query, Notification, sort_by, sort_dir) return database.paginate(query, page, count)
def render(args): """ Helper that paginates and filters data when requested through the REST Api :param args: :return: """ query = database.session_query(User) sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') if filt: terms = filt.split(';') query = database.filter(query, User, terms) query = database.find_all(query, User, args) if sort_by and sort_dir: query = database.sort(query, User, sort_by, sort_dir) return database.paginate(query, page, count)
def get_all(): """ Retrieves all notification currently known by Lemur. :return: """ query = database.session_query(Notification) return database.find_all(query, Notification, {}).all()
def get_all(): """ Retrieves all source currently known by Lemur. :return: """ query = database.session_query(Source) return database.find_all(query, Source, {}).all()
def get_all(): """ Retrieve all users from the database. :return: """ query = database.session_query(User) return database.find_all(query, User, {}).all()
def get_all(): """ Retrieve all logs from the database. :return: """ query = database.session_query(Log) return database.find_all(query, Log, {}).all()
def get_all(): """ Retrieves all destination currently known by Lemur. :return: """ query = database.session_query(Destination) return database.find_all(query, Destination, {}).all()
def get_all(): """ Fetches all domains :return: """ query = database.session_query(Domain) return database.find_all(query, Domain, {}).all()
def get_all(): """ Get all authorities that are currently in Lemur. :rtype : List :return: """ query = database.session_query(Authority) return database.find_all(query, Authority, {}).all()
def get_all(): """ Get all endpoints that are currently in Lemur. :rtype : List :return: """ query = database.session_query(Endpoint) return database.find_all(query, Endpoint, {}).all()
def is_domain_sensitive(name): """ Return True if domain is marked sensitive :param name: :return: """ query = database.session_query(Domain) query = query.filter(and_(Domain.sensitive, Domain.name == name)) return database.find_all(query, Domain, {}).all()
def get_by_attributes(conditions): """ Retrieves certificate(s) by conditions given in a hash of given key=>value pairs. :param serial: :return: """ # Ensure that each of the given conditions corresponds to actual columns # if not, silently remove it for attr in conditions.keys(): if attr not in Certificate.__table__.columns: conditions.pop(attr) query = database.session_query(Certificate) return database.find_all(query, Certificate, conditions).all()
def get_pending_certs(pending_ids): """ Retrieve a list of pending certs given a list of ids Filters out non-existing pending certs """ pending_certs = [] if 'all' in pending_ids: query = database.session_query(PendingCertificate) return database.find_all(query, PendingCertificate, {}).all() else: for pending_id in pending_ids: pending_cert = get(pending_id) if pending_cert: pending_certs.append(pending_cert) return pending_certs
def get_pending_certs(pending_ids): """ Retrieve a list of pending certs given a list of ids Filters out non-existing pending certs """ pending_certs = [] if "all" in pending_ids: query = database.session_query(PendingCertificate) return database.find_all(query, PendingCertificate, {}).all() else: for pending_id in pending_ids: pending_cert = get(pending_id) if pending_cert: pending_certs.append(pending_cert) return pending_certs
def render(args): """ Helper that filters subsets of roles depending on the parameters passed to the REST Api :param args: :return: """ query = database.session_query(Role) sort_by = args.pop('sort_by') sort_dir = args.pop('sort_dir') page = args.pop('page') count = args.pop('count') filt = args.pop('filter') user_id = args.pop('user_id', None) authority_id = args.pop('authority_id', None) if user_id: query = query.filter(Role.users.any(User.id == user_id)) if authority_id: query = query.filter(Role.authority_id == authority_id) # we make sure that user can see the role - admins can see all if not g.current_user.is_admin: ids = [] for role in g.current_user.roles: ids.append(role.id) query = query.filter(Role.id.in_(ids)) if filt: terms = filt.split(';') query = database.filter(query, Role, terms) query = database.find_all(query, Role, args) if sort_by and sort_dir: query = database.sort(query, Role, sort_by, sort_dir) return database.paginate(query, page, count)