From ef700b2688bfc6332805b6fc4c0e95516dafafd8 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Wed, 13 Mar 2024 17:46:42 +0800 Subject: [PATCH 1/3] enhance: sandbox-docker-compose --- api/.env.example | 4 ++-- docker/docker-compose.middleware.yaml | 3 +++ docker/docker-compose.yaml | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/api/.env.example b/api/.env.example index c0942412ab948f..832c7e3bab6c58 100644 --- a/api/.env.example +++ b/api/.env.example @@ -134,5 +134,5 @@ SSRF_PROXY_HTTPS_URL= BATCH_UPLOAD_LIMIT=10 # CODE EXECUTION CONFIGURATION -CODE_EXECUTION_ENDPOINT= -CODE_EXECUTION_API_KEY= +CODE_EXECUTION_ENDPOINT=http://127.0.0.1:8194 +CODE_EXECUTION_API_KEY=dify-sandbox diff --git a/docker/docker-compose.middleware.yaml b/docker/docker-compose.middleware.yaml index 8fba59c3154415..4f7965609b7089 100644 --- a/docker/docker-compose.middleware.yaml +++ b/docker/docker-compose.middleware.yaml @@ -55,9 +55,12 @@ services: sandbox: image: langgenius/dify-sandbox:latest restart: always + cap_add: + - SYS_ADMIN environment: # The DifySandbox configurations API_KEY: dify-sandbox + GIN_MODE: 'release' ports: - "8194:8194" diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 78b22a43b4a2d3..9a6b801eeae1ca 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -293,9 +293,12 @@ services: sandbox: image: langgenius/dify-sandbox:latest restart: always + cap_add: + - SYS_ADMIN environment: # The DifySandbox configurations API_KEY: dify-sandbox + GIN_MODE: release ports: - "8194:8194" From 1f4826ca01fd0d0bd9402eceaa6541e73ec73d75 Mon Sep 17 00:00:00 2001 From: takatost Date: Wed, 13 Mar 2024 18:02:07 +0800 Subject: [PATCH 2/3] fix err typo --- api/core/workflow/nodes/if_else/if_else_node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/core/workflow/nodes/if_else/if_else_node.py b/api/core/workflow/nodes/if_else/if_else_node.py index 9cb084b116dc52..44a4091a2efc6e 100644 --- a/api/core/workflow/nodes/if_else/if_else_node.py +++ b/api/core/workflow/nodes/if_else/if_else_node.py @@ -95,7 +95,7 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult: return NodeRunResult( status=WorkflowNodeExecutionStatus.FAILED, inputs=node_inputs, - process_datas=process_datas, + process_data=process_datas, error=str(e) ) @@ -107,7 +107,7 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult: return NodeRunResult( status=WorkflowNodeExecutionStatus.SUCCEEDED, inputs=node_inputs, - process_datas=process_datas, + process_data=process_datas, edge_source_handle="false" if not compare_result else "true", outputs={ "result": compare_result From e80315f5045f5b6358be519baba6f1bb3fd42b39 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Wed, 13 Mar 2024 20:40:37 +0800 Subject: [PATCH 3/3] fix: allow None AuthorizationConfig --- .../workflow/nodes/http_request/entities.py | 17 +++++++++-- .../workflow/nodes/test_http.py | 30 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/api/core/workflow/nodes/http_request/entities.py b/api/core/workflow/nodes/http_request/entities.py index ce806b6bdbad85..fbd4da384004a4 100644 --- a/api/core/workflow/nodes/http_request/entities.py +++ b/api/core/workflow/nodes/http_request/entities.py @@ -1,6 +1,6 @@ from typing import Literal, Optional, Union -from pydantic import BaseModel +from pydantic import BaseModel, validator from core.workflow.entities.base_node_data_entities import BaseNodeData from core.workflow.entities.variable_entities import VariableSelector @@ -17,7 +17,20 @@ class Config(BaseModel): header: Union[None, str] type: Literal['no-auth', 'api-key'] - config: Config + config: Optional[Config] + + @validator('config', always=True, pre=True) + def check_config(cls, v, values): + """ + Check config, if type is no-auth, config should be None, otherwise it should be a dict. + """ + if values['type'] == 'no-auth': + return None + else: + if not v or not isinstance(v, dict): + raise ValueError('config should be a dict') + + return v class Body(BaseModel): type: Literal[None, 'form-data', 'x-www-form-urlencoded', 'raw', 'json'] diff --git a/api/tests/integration_tests/workflow/nodes/test_http.py b/api/tests/integration_tests/workflow/nodes/test_http.py index 6df8f6b6733de2..584e1d80a59d38 100644 --- a/api/tests/integration_tests/workflow/nodes/test_http.py +++ b/api/tests/integration_tests/workflow/nodes/test_http.py @@ -54,6 +54,36 @@ def test_get(setup_http_mock): assert 'api-key: Basic ak-xxx' in data assert 'X-Header: 123' in data +@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True) +def test_no_auth(setup_http_mock): + node = HttpRequestNode(config={ + 'id': '1', + 'data': { + 'title': 'http', + 'desc': '', + 'variables': [{ + 'variable': 'args1', + 'value_selector': ['1', '123', 'args1'], + }], + 'method': 'get', + 'url': 'http://example.com', + 'authorization': { + 'type': 'no-auth', + 'config': None, + }, + 'headers': 'X-Header:123', + 'params': 'A:b', + 'body': None, + } + }, **BASIC_NODE_DATA) + + result = node.run(pool) + + data = result.process_data.get('request', '') + + assert '?A=b' in data + assert 'X-Header: 123' in data + @pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True) def test_template(setup_http_mock): node = HttpRequestNode(config={