Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.10 AS base
LABEL org.wayscript.image.authors="founders@wayscript.com"

RUN apt-get update && apt-get -yu dist-upgrade
RUN apt-get update && apt-get -yu dist-upgrade freetds-dev

ENV SRC_DIR /usr/local/src/project
WORKDIR ${SRC_DIR}
Expand Down
2 changes: 2 additions & 0 deletions src/wayscript/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
WEBHOOKS = "webhooks"
WORKSPACES_ROUTE = "workspaces"
WORKSPACE_INTEGRATIONS_ROUTE = "workspace-integrations"
TERMINAL_ROUTE = "terminal"



ROUTES = {
"auth": {"refresh": f"{AUTH_ROUTE}/refresh"},
"lairs": {"detail": f"{LAIRS_ROUTE}/$id"},
"processes": { "detail_expanded": f"{PROCESSES_ROUTE}/$id/detail"},
"terminal": { "output": f"{TERMINAL_ROUTE}/output"},
"webhooks": {"http_trigger_response": f"{WEBHOOKS}/http-trigger/response/$id"},
"workspaces": {
"detail": f"{WORKSPACES_ROUTE}/$id",
Expand Down
12 changes: 12 additions & 0 deletions src/wayscript/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ def _refresh_access_token(self):
set_process_execution_user_token(access_token)
self.session.headers["authorization"] = f"Bearer {access_token}"

@retry_on_401_wrapper
def _send_terminal_output(self, process_id: str, service_id: str, output: str):
"""Send terminal output for current process, for WayScript internal use"""
payload = {
'service_id': service_id,
'process_id': process_id,
'output': output
}
url = self._get_url(subpath="terminal", route="output")
response = self.session.post(url, json=payload)
return response

@retry_on_401_wrapper
def get_process_detail_expanded(self, _id: str):
"""Request process expanded detail endpoint"""
Expand Down
24 changes: 24 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
import responses
import json
from uuid import uuid4

from wayscript import settings, utils

Expand Down Expand Up @@ -30,3 +32,25 @@ def test__get_url_generates_correct_endpoints(method, _id, expected_subpath, htt
assert responses.calls[0].request.url == expected_url


@responses.activate
def test__send_terminal_output():
"""Test that _send_terminal_output sends the correct payload to the proper url"""
process_id = str(uuid4())
service_id = str(uuid4())
output = "Hello World"

expected_payload = {
"process_id": process_id,
"service_id": service_id,
"output": output,
}
expected_url = f"{settings.WAYSCRIPT_ORIGIN}/terminal/output"
responses.add("POST", expected_url,
json={}, status=200)

client = utils.WayScriptClient()
client._send_terminal_output(process_id, service_id, output)

assert len(responses.calls) == 1
assert responses.calls[0].request.url == expected_url
assert json.loads(responses.calls[0].request.body) == expected_payload