Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return result
raise ErrorResponse(
403,
"NotAuthorized",
"User has insufficient permissions.",
help_url=_docs(
"/user-guide/running-the-server/#security-considerations"
),
)
elif token is None and app.config.get("USE_JWT") is None:
# authentication is disabled
result = f(request, *args, **kwargs)
if isawaitable(result):
result = await result
return result
raise ErrorResponse(
401,
"NotAuthenticated",
"User is not authenticated.",
help_url=_docs(
"/user-guide/running-the-server/#security-considerations"
),
if isawaitable(result):
result = await result
return result
raise ErrorResponse(
403,
"NotAuthorized",
"User has insufficient permissions.",
help_url=_docs("/server.html#security-considerations"),
)
elif token is None and app.config.get("USE_JWT") is None:
# authentication is disabled
result = f(request, *args, **kwargs)
if isawaitable(result):
result = await result
return result
raise ErrorResponse(
401,
"NotAuthenticated",
"User is not authenticated.",
help_url=_docs("/server.html#security-considerations"),
)
def event_verbosity_parameter(
request: Request, default_verbosity: EventVerbosity
) -> EventVerbosity:
event_verbosity_str = request.args.get(
"include_events", default_verbosity.name
).upper()
try:
return EventVerbosity[event_verbosity_str]
except KeyError:
enum_values = ", ".join([e.name for e in EventVerbosity])
raise ErrorResponse(
400,
"BadRequest",
"Invalid parameter value for 'include_events'. "
"Should be one of {}".format(enum_values),
{"parameter": "include_events", "in": "query"},
)
raise ErrorResponse(
400,
"BadRequest",
"The training request is missing the required key " "`config`.",
)
if "nlu" not in rjs and "stories" not in rjs:
raise ErrorResponse(
400,
"BadRequest",
"To train a Rasa model you need to specify at least one type of "
"training data. Add `nlu` and/or `stories` to the request.",
)
if "stories" in rjs and "domain" not in rjs:
raise ErrorResponse(
400,
"BadRequest",
"To train a Rasa model with story training data, you also need to "
"specify the `domain`.",
def _get_events_from_request_body(request: Request) -> List[Event]:
events = request.json
if not isinstance(events, list):
events = [events]
events = [Event.from_parameters(event) for event in events]
events = [event for event in events if event]
if not events:
raise_warning(
f"Append event called, but could not extract a valid event. "
f"Request JSON: {request.json}"
)
raise ErrorResponse(
400,
"BadRequest",
"Couldn't extract a proper event from the request body.",
{"parameter": "", "in": "body"},
)
return events
def obtain_tracker_store(agent: "Agent", conversation_id: Text) -> DialogueStateTracker:
tracker = agent.tracker_store.get_or_create_tracker(conversation_id)
if not tracker:
raise ErrorResponse(
409,
"Conflict",
"Could not retrieve tracker with id '{}'. Most likely "
"because there is no domain set on the agent.".format(conversation_id),
)
return tracker
def decorated(*args, **kwargs):
# noinspection PyUnresolvedReferences
if not app.agent or not (
app.agent.is_core_ready()
if require_core_is_ready
else app.agent.is_ready()
):
raise ErrorResponse(
409,
"Conflict",
"No agent loaded. To continue processing, a "
"model of a trained agent needs to be loaded.",
help_url=_docs("/user-guide/configuring-http-api/"),
)
return f(*args, **kwargs)
def validate_request(rjs):
if "config" not in rjs:
raise ErrorResponse(
400,
"BadRequest",
"The training request is missing the required key `config`.",
{"parameter": "config", "in": "body"},
)
if "nlu" not in rjs and "stories" not in rjs:
raise ErrorResponse(
400,
"BadRequest",
"To train a Rasa model you need to specify at least one type of "
"training data. Add `nlu` and/or `stories` to the request.",
{"parameters": ["nlu", "stories"], "in": "body"},
)
if "stories" in rjs and "domain" not in rjs:
def validate_request(rjs):
if "config" not in rjs:
raise ErrorResponse(
400,
"BadRequest",
"The training request is missing the required key `config`.",
{"parameter": "config", "in": "body"},
)
if "nlu" not in rjs and "stories" not in rjs:
raise ErrorResponse(
400,
"BadRequest",
"To train a Rasa model you need to specify at least one type of "
"training data. Add `nlu` and/or `stories` to the request.",
{"parameters": ["nlu", "stories"], "in": "body"},
)
if "stories" in rjs and "domain" not in rjs:
raise ErrorResponse(
400,
"BadRequest",
"To train a Rasa model with story training data, you also need to "
"specify the `domain`.",
{"parameter": "domain", "in": "body"},
)
tracker.update(evt)
app.agent.tracker_store.save(tracker)
return response.json(tracker.current_state(verbosity))
except Exception as e:
logger.debug(traceback.format_exc())
raise ErrorResponse(
500,
"ServerError",
"An unexpected error occurred. Error: {}".format(e),
)
logger.warning(
"Append event called, but could not extract a valid event. "
"Request JSON: {}".format(request.json)
)
raise ErrorResponse(
400,
"BadRequest",
"Couldn't extract a proper event from the request body.",
{"parameter": "", "in": "body"},
)