from flask import request, session, g from flask_restplus import Resource import math from cortex import app from cortex.corpus import Corpus from cortex.api import api_manager, api_login_required from cortex.api.exceptions import InvalidPermissionException, NoResultsFoundException from cortex.api.serializers.dns import dns_serializer dns_namespace = api_manager.namespace('dns', description='DNS API') @dns_namespace.route('/<string:host>') @api_manager.doc(params={'host': 'Fully qualified domain name to lookup'}) class DNSLookupItem(Resource): """ API for DNS lookups """ @api_login_required() @api_manager.marshal_with(dns_serializer) def get(self, host): corpus = Corpus(g.db, app.config) return corpus.dns_lookup(host)
type=str, required=False, default=None, help='User who started the task') tasks_arguments.add_argument('module', type=str, required=False, default=None, help='The module who started the task') tasks_arguments.add_argument('status', type=int, required=False, default=None, help='The status code of the task') tasks_namespace = api_manager.namespace('tasks', description='Tasks API') @tasks_namespace.route('/') class TasksCollection(Resource): """ API Handler for multiple rows for tasks. """ @api_login_required() @api_manager.expect(pagination_arguments, tasks_arguments) @api_manager.marshal_with(page_tasks_serializer, mask='{page,pages,per_page,total,items}') def get(self): """ Returns a paginated list of rows from the tasks lists. """
from flask import request, session from flask_restplus import Resource import math from cortex.api import api_manager, api_login_required from cortex.api.exceptions import InvalidPermissionException, NoResultsFoundException from cortex.api.parsers import pagination_arguments from cortex.api.serializers.systems_info_view import page_systems_info_view_serializer, systems_info_view_serializer from cortex.lib.user import does_user_have_permission, does_user_have_system_permission, does_user_have_any_system_permission import cortex.lib.systems systems_info_view_namespace = api_manager.namespace( 'systems_info_view', description='System\'s Info View API') @systems_info_view_namespace.route('/') class SystemsInfoViewCollection(Resource): """ API Handler for multiple rows from the systems_info_view. """ @api_login_required('get') @api_manager.expect(pagination_arguments) @api_manager.marshal_with(page_systems_info_view_serializer, mask='{page,pages,per_page,total,items{id,name}}' ) def get(self): """ Returns a paginated list of rows from the systems_info_view. """ args = pagination_arguments.parse_args(request)
import MySQLdb as mysql from flask import g, request, session from flask_restx import Resource, inputs, reqparse from cortex.api import api_login_required, api_manager from cortex.api.exceptions import InvalidPermissionException from cortex.api.parsers import (pagination_arguments, process_pagination_arguments, pagination_response) from cortex.api.serializers.certificates import (certificates_full_serializer, page_certificates_serializer) from cortex.lib.user import does_user_have_permission certificates_namespace = api_manager.namespace('certificates', description='Certificate API') certificates_arguments = reqparse.RequestParser() certificates_arguments.add_argument('cn_or_san', type=str, required=False, default=None, help='A subject CN or SAN to search for') certificates_arguments.add_argument( 'expired', type=inputs.boolean, required=False, default=None, help='Show only (true) or hide (false) expired certificates') certificates_arguments.add_argument( 'self_signed', type=inputs.boolean,
from flask import request, session, jsonify, g from flask_restplus import Resource import math import json from cortex import app from cortex.api import api_manager, api_login_required from cortex.api.exceptions import InvalidPermissionException, NoResultsFoundException from cortex.lib.user import does_user_have_permission import cortex.lib.core import MySQLdb as mysql puppet_modules_info_namespace = api_manager.namespace('puppet', description='Puppet API') @puppet_modules_info_namespace.route('/modules_info') class Puppet(Resource): """ API Handler for POST requests """ @app.disable_csrf_check def post(self): if 'X-Auth-Token' in request.headers: if app.config['CORTEX_API_AUTH_TOKEN'] == request.headers['X-Auth-Token']: # Read the request data outcome = request.json # Get the database cursor curd = g.db.cursor(mysql.cursors.DictCursor) # Turn off autocommit cause a lot of insertions are going to be used