Exemple #1
0
from CTFd.api.v1.scoreboard import scoreboard_namespace
from CTFd.api.v1.statistics import statistics_namespace
from CTFd.api.v1.submissions import submissions_namespace
from CTFd.api.v1.tags import tags_namespace
from CTFd.api.v1.teams import teams_namespace
from CTFd.api.v1.tokens import tokens_namespace
from CTFd.api.v1.topics import topics_namespace
from CTFd.api.v1.unlocks import unlocks_namespace
from CTFd.api.v1.users import users_namespace

api = Blueprint("api", __name__, url_prefix="/api/v1")
CTFd_API_v1 = Api(api,
                  version="v1",
                  doc=current_app.config.get("SWAGGER_UI_ENDPOINT"))

CTFd_API_v1.schema_model("APISimpleErrorResponse",
                         APISimpleErrorResponse.schema())
CTFd_API_v1.schema_model("APIDetailedSuccessResponse",
                         APIDetailedSuccessResponse.schema())
CTFd_API_v1.schema_model("APISimpleSuccessResponse",
                         APISimpleSuccessResponse.schema())

CTFd_API_v1.add_namespace(challenges_namespace, "/challenges")
CTFd_API_v1.add_namespace(tags_namespace, "/tags")
CTFd_API_v1.add_namespace(topics_namespace, "/topics")
CTFd_API_v1.add_namespace(awards_namespace, "/awards")
CTFd_API_v1.add_namespace(hints_namespace, "/hints")
CTFd_API_v1.add_namespace(flags_namespace, "/flags")
CTFd_API_v1.add_namespace(submissions_namespace, "/submissions")
CTFd_API_v1.add_namespace(scoreboard_namespace, "/scoreboard")
CTFd_API_v1.add_namespace(teams_namespace, "/teams")
CTFd_API_v1.add_namespace(users_namespace, "/users")
Exemple #2
0
        'type': 'apiKey',
        'in': 'header',
        'name': 'Authorization'
    }
}

api_bp = flask.Blueprint('api', __name__, None)
api = Api(api_bp,
          title='JobsScheduler API',
          version='0.1',
          description='JobsScheduler',
          security='apikey',
          doc='/swagger/',
          authorizations=authorizations)

JOB_MODEL = api.schema_model('job', JOB_SCHEMA)
JOBS_MODEL = api.schema_model('jobs', JOBS_SCHEMA)

JOB_INFO_MODEL = api.schema_model('job_info', JOB_INFO_SCHEMA)
JOBS_INFO_MODEL = api.schema_model('jobs_info', JOBS_INFO_SCHEMA)

JOB_PATCH_SCHEMA = copy.deepcopy(JOB_SCHEMA)
JOB_PATCH_SCHEMA['required'] = []


@api.route('/ping')
class Ping(Resource):
    @api.doc(security=[])
    def get(self):
        return {'pong': True}
Exemple #3
0
                return obj.total_seconds()
        except TypeError:
            pass
        return json.JSONEncoder.default(self, obj)


class AnyJson(fields.Raw):
    def format(self, value):
        if type(value) == dict:
            return value
        else:
            return json.loads(value)


# Loads event and bucket schema from JSONSchema in aw_core
event = api.schema_model("Event", schema.get_json_schema("event"))
bucket = api.schema_model("Bucket", schema.get_json_schema("bucket"))
buckets_export = api.schema_model("Export", schema.get_json_schema("export"))

# TODO: Construct all the models from JSONSchema?
#       A downside to contructing from JSONSchema: flask-restplus does not have marshalling support

info = api.model(
    "Info",
    {
        "hostname": fields.String(),
        "version": fields.String(),
        "testing": fields.Boolean(),
        "device_id": fields.String(),
    },
)
Exemple #4
0
                return obj.total_seconds()
        except TypeError:
            pass
        return json.JSONEncoder.default(self, obj)


class AnyJson(fields.Raw):
    def format(self, value):
        if type(value) == dict:
            return value
        else:
            return json.loads(value)


# Loads event and bucket schema from JSONSchema in aw_core
event = api.schema_model('Event', schema.get_json_schema("event"))
bucket = api.schema_model('Bucket', schema.get_json_schema("bucket"))
buckets_export = api.schema_model('Export', schema.get_json_schema("export"))

# TODO: Construct all the models from JSONSchema?
#       A downside to contructing from JSONSchema: flask-restplus does not have marshalling support

info = api.model(
    'Info', {
        'hostname': fields.String(),
        'version': fields.String(),
        'testing': fields.Boolean(),
        'device_id': fields.String(),
    })

create_bucket = api.model(
        """
        Get the values to populate the filter form
        """
        return get_msg_form(config['filter_form_values_path'])


@api.route('/form')
class MessageFormat(Resource):
    def get(self):
        """
        Get the format of a message
        """
        return get_msg_form(config['format_path'])


msg = api.schema_model('Msg', get_msg_form(config['format_path']))


@api.route('/number_of_msgs')
class TotalMsgs(Resource):
    def get(self):
        """
        Get the total number of messages
        """
        return {'number_of_msgs': number_of_msgs()}


@api.route('/newest_msg')
class NewestMsg(Resource):
    def get(self):
        """
app.config['ENV'] = os.getenv('FLASK_ENV')
api = Api(app,
          version='1.0',
          title='Wiki page API',
          description='REST API to mongodb',
          doc="/api/wiki/doc/")
api = api.namespace("Wiki page",
                    description='Stored content for wiki project',
                    path="/")  # swagger ui representation
DAO = WikiPageDAO(
)  # a data access object which provides interface to database

with open(SCHEMA_PATH, 'r') as schema_file:
    s = schema_file.read()
    schema = json.loads(s)
schema_model = api.schema_model('model',
                                schema['$jsonSchema'])  # used for validation


@app.after_request
def after_request(response):
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers',
                         'Content-Type,Authorization')
    response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
    return response


# parametres which you should use in filters
query_params = {
    '_id':
    "Object id",