<commit_before># stdlib
from typing import Any
from typing import Optional

# third party
from fastapi import APIRouter
from fastapi import Body
from fastapi import Depends
from fastapi.responses import JSONResponse
from nacl.encoding import HexEncoder
from nacl.signing import SigningKey

# syft absolute
from syft.core.node.common.action.exception_action import ExceptionMessage

# syft
from syft.core.node.common.node_service.node_setup.node_setup_messages import (
    UpdateSetupMessage,
)
from syft.core.node.common.node_service.node_setup.node_setup_service import (
    GetSetUpMessage,
)

# grid absolute
from grid.api.dependencies.current_user import get_current_user
from grid.api.users.models import UserPrivate
from grid.core.node import node

router = APIRouter()


@router.post("", status_code=200, response_class=JSONResponse)
def update_settings(
    contact: str = Body(..., example="<EMAIL>"),
    domain_name: str = Body(..., example="OpenGrid"),
    description: str = Body(..., example="A Domain Node Description ..."),
    daa_document: Optional[bool] = False,
    current_user: UserPrivate = Depends(get_current_user),
) -> Any:
    user_key = SigningKey(current_user.private_key.encode(), encoder=HexEncoder)

    # Build Syft Message
    msg = UpdateSetupMessage(
        address=node.address,
        contact=contact,
        domain_name=domain_name,
        description=description,
        daa=daa_document,
        reply_to=node.address,
    ).sign(signing_key=user_key)

    # Process syft message
    reply = node.recv_immediate_msg_with_reply(msg=msg).message

    # Handle Response types
    resp = {}
    if isinstance(reply, ExceptionMessage):
        resp = {"error": reply.exception_msg}
    else:
        resp = {"message": reply.content}
    return resp


@router.get("", status_code=200, response_class=JSONResponse)
def get_setup() -> Any:
    msg = GetSetUpMessage(address=node.address, reply_to=node.address).sign(
        signing_key=node.signing_key
    )

    reply = node.recv_immediate_msg_with_reply(msg=msg)
    return JSONResponse(reply.message.content)<commit_msg>FIX POST /settings parameters<commit_after># stdlib
from typing import Any
from typing import Optional

# third party
from fastapi import APIRouter
from fastapi import Body
from fastapi import Depends
from fastapi.responses import JSONResponse
from nacl.encoding import HexEncoder
from nacl.signing import SigningKey

# syft absolute
from syft.core.node.common.action.exception_action import ExceptionMessage

# syft
from syft.core.node.common.node_service.node_setup.node_setup_messages import (
    UpdateSetupMessage,
)
from syft.core.node.common.node_service.node_setup.node_setup_service import (
    GetSetUpMessage,
)

# grid absolute
from grid.api.dependencies.current_user import get_current_user
from grid.api.users.models import UserPrivate
from grid.core.node import node

router = APIRouter()


@router.post("", status_code=200, response_class=JSONResponse)
def update_settings(
    contact: str = Body(..., example="<EMAIL>"),
    domain_name: str = Body(..., example="OpenGrid"),
    description: str = Body(..., example="A Domain Node Description ..."),
    daa: Optional[bool] = False,
    daa_document: Optional[str] = Body("", example="http://<daa_template>.com"),
    current_user: UserPrivate = Depends(get_current_user),
) -> Any:
    user_key = SigningKey(current_user.private_key.encode(), encoder=HexEncoder)

    # Build Syft Message
    msg = UpdateSetupMessage(
        address=node.address,
        contact=contact,
        domain_name=domain_name,
        description=description,
        daa=daa,
        daa_document=daa_document,
        reply_to=node.address,
    ).sign(signing_key=user_key)

    # Process syft message
    reply = node.recv_immediate_msg_with_reply(msg=msg).message

    # Handle Response types
    resp = {}
    if isinstance(reply, ExceptionMessage):
        resp = {"error": reply.exception_msg}
    else:
        resp = {"message": reply.content}
    return resp


@router.get("", status_code=200, response_class=JSONResponse)
def get_setup() -> Any:
    msg = GetSetUpMessage(address=node.address, reply_to=node.address).sign(
        signing_key=node.signing_key
    )

    reply = node.recv_immediate_msg_with_reply(msg=msg)
    return JSONResponse(reply.message.content)
{'fraction_non_alphanumeric': 0.10119595216191353, 'fraction_numerical': 0.0027598896044158236, 'mean_word_length': 4.177380952380952, 'pattern_counts': {'":': 4, '<': 6, '<?xml version=': 0, '>': 10, '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': '3515941', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1298, 'n_words': 295}