<commit_before>from .blueprint import setup_blueprint as setup_route
from flask import request, Response
import json
from syft.core.node.common.service.repr_service import ReprMessage

from ..auth import error_handler, token_required
from ...core.node import node


@setup_route.route("/", methods=["POST"])
# @token_required
def initial_setup():
    def route_logic():
        # Get request body
        content = loads(request.data)

        syft_message = {}
        syft_message["message_class"] = ReprMessage  # TODO: InitialSetupSettingsMessage
        syft_message["message_content"] = content
        syft_message[
            "sign_key"
        ] = node.signing_key  # TODO: Method to map token into sign-key

        # Execute task
        status_code, response_body = task_handler(
            route_function=process_as_syft_message,
            data=syft_message,
            mandatory={
                "message_class": MissingRequestKeyError,
                "message_content": MissingRequestKeyError,
                "sign_key": MissingRequestKeyError,
            },
        )
        return response_body

    # status_code, response_body = error_handler(process_as_syft_message)
    status_code, response_body = 200, {"msg": "Running initial setup!"}

    return Response(
        json.dumps(response_body), status=status_code, mimetype="application/json"
    )


@setup_route.route("/", methods=["GET"])
# @token_required
def get_setup():
    def route_logic():
        # Get request body
        content = loads(request.data)

        syft_message = {}
        syft_message["message_class"] = ReprMessage  # TODO: Get Initial Setup Messages
        syft_message["message_content"] = content
        syft_message[
            "sign_key"
        ] = node.signing_key  # TODO: Method to map token into sign-key

        # Execute task
        status_code, response_body = task_handler(
            route_function=process_as_syft_message,
            data=syft_message,
            mandatory={
                "message_class": MissingRequestKeyError,
                "message_content": MissingRequestKeyError,
                "sign_key": MissingRequestKeyError,
            },
        )
        return response_body

    # status_code, response_body = error_handler(process_as_syft_message)
    status_code, response_body = 200, {"setup": {}}

    return Response(
        json.dumps(response_body), status=status_code, mimetype="application/json"
    )<commit_msg>Update vanity api setup routes<commit_after>from .blueprint import setup_blueprint as setup_route
from flask import request, Response
import json

from syft.grid.messages.setup_messages import (
    CreateInitialSetUpMessage,
    GetSetUpMessage,
)

from ..auth import error_handler, token_required
from ...core.task_handler import route_logic


@setup_route.route("/", methods=["POST"])
@token_required
def initial_setup(current_user):
    # Get request body
    content = request.get_json()
    if not content:
        content = {}

    status_code, response_msg = error_handler(
        route_logic, CreateInitialSetUpMessage, current_user, content
    )

    response = response_msg if isinstance(response_msg, dict) else response_msg.content

    return Response(
        json.dumps(response),
        status=status_code,
        mimetype="application/json",
    )


@setup_route.route("/", methods=["GET"])
@token_required
def get_setup(current_user):
    # Get request body
    content = request.get_json()
    if not content:
        content = {}

    status_code, response_msg = error_handler(
        route_logic, GetSetUpMessage, current_user, content
    )

    response = response_msg if isinstance(response_msg, dict) else response_msg.content

    return Response(
        json.dumps(response),
        status=status_code,
        mimetype="application/json",
    )
{'fraction_non_alphanumeric': 0.08883708883708884, 'fraction_numerical': 0.001554001554001554, 'mean_word_length': 2.956967213114754, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2483079', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1064, 'n_words': 243}