def list_policies(user, filter_, sort=None, page=0, limit=DEFAULT_PAGE_LIMIT): """ API endpoint to provide a list of policies """ policies = db.session.query( model.Policy.id, model.Policy.name, model.Policy.department, ) if 'name' in filter_: policies = policies.filter(model.Policy.name.ilike(filter_['name'])) if 'department' in filter_: policies = policies.filter( model.Policy.department.ilike(filter_['department'])) if sort: policies = db_sort(policies, sort) return { 'data': [ policy._asdict() for policy in policies.limit(limit).offset(page * limit) ], 'total': policies.count(), }
def list_jobs(user, filter_, sort=None, page=0, limit=DEFAULT_PAGE_LIMIT): cron_jobs = model.SchedulerCronJob.query if 'name' in filter_: cron_jobs = cron_jobs.filter( model.SchedulerCronJob.name.ilike(filter_['name']), ) if sort: cron_jobs = db_sort(cron_jobs, sort) return { 'data': [i.to_dict() for i in cron_jobs.limit(limit).offset(page * limit)], 'total': cron_jobs.count() }
def list_servers(filter_, sort=None, page=0, limit=DEFAULT_PAGE_LIMIT): servers = model.Server.query if 'name' in filter_: servers = servers.filter(model.Server.name.ilike(filter_['name'])) if sort: servers = db_sort(servers, sort) return { 'data': [ server.to_dict() | { '_href': _server_href(server) } for server in servers.limit(limit).offset(page * limit) ], 'total': servers.count(), }
def list_regions(keycloak: KeycloakClient, user, filter_, sort=None, page=0, limit=DEFAULT_PAGE_LIMIT): if keycloak.user_check_role(user, ADMIN_ROLE): regions = model.Region.query else: user_groups = [group['id'] for group in keycloak.user_group_list(user)] regions = model.Region.query.filter( sqlalchemy.or_( model.Region.users_group.is_(None), model.Region.users_group.in_(user_groups), model.Region.owner_group.in_(user_groups), )) if 'name' in filter_: regions = regions.filter(model.Region.name.ilike(filter_['name'])) if 'location' in filter_: regions = regions.filter( model.Region.location.ilike(filter_['location'])) if 'enabled' in filter_: regions = regions.filter(model.Region.enabled == filter_['enabled']) if 'reservations_enabled' in filter_: regions = regions.filter(model.Region.reservations_enabled == filter_['reservations_enabled']) if sort: regions = db_sort(regions, sort) return { 'data': [ region.to_dict() | { '_href': _region_href(region) } for region in regions.limit(limit).offset(page * limit) ], 'total': regions.count(), }
def list_products(user, filter_, sort=None, page=0, limit=DEFAULT_PAGE_LIMIT): products = model.Product.query if 'name' in filter_: products = products.filter(model.Product.name.ilike(filter_['name'])) if 'enabled' in filter_: products = products.filter(model.Product.enabled == filter_['enabled']) if sort: products = db_sort(products, sort) return { 'data': [ product.to_dict() | { '_href': _product_href(product) } for product in products.limit(limit).offset(page * limit) ], 'total': products.count(), }
def list_templates(filter_, sort=None, page=0, limit=DEFAULT_PAGE_LIMIT): templates = model.Template.query if 'name' in filter_: templates = templates.filter(model.Template.name.ilike( filter_['name'])) if 'server_id' in filter_: templates = templates.filter( model.Template.server_id == filter_['server_id']) if sort: templates = db_sort(templates, sort) return { 'data': [ template.to_dict() | { '_href': _template_href(template) } for template in templates.limit(limit).offset(page * limit) ], 'total': templates.count(), }