Skip to content

Commit

Permalink
Merge branch 'feat/workflow-backend' into deploy/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Mar 13, 2024
2 parents 5ab1207 + e80315f commit 0a12ddc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 6 deletions.
4 changes: 2 additions & 2 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions api/core/workflow/nodes/http_request/entities.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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']
Expand Down
4 changes: 2 additions & 2 deletions api/core/workflow/nodes/if_else/if_else_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand All @@ -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
Expand Down
30 changes: 30 additions & 0 deletions api/tests/integration_tests/workflow/nodes/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.middleware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 0a12ddc

Please sign in to comment.