mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-12-02 11:18:19 +08:00
fix(api/fields/workflow_fields.py): Add check in environment variables (#6621)
This commit is contained in:
parent
ca696fe94c
commit
55c2b61921
@ -1,10 +1,12 @@
|
||||
from flask_restful import fields
|
||||
|
||||
from core.app.segments import SecretVariable, Variable
|
||||
from core.app.segments import SecretVariable, SegmentType, Variable
|
||||
from core.helper import encrypter
|
||||
from fields.member_fields import simple_account_fields
|
||||
from libs.helper import TimestampField
|
||||
|
||||
ENVIRONMENT_VARIABLE_SUPPORTED_TYPES = (SegmentType.STRING, SegmentType.NUMBER, SegmentType.SECRET)
|
||||
|
||||
|
||||
class EnvironmentVariableField(fields.Raw):
|
||||
def format(self, value):
|
||||
@ -16,14 +18,18 @@ class EnvironmentVariableField(fields.Raw):
|
||||
'value': encrypter.obfuscated_token(value.value),
|
||||
'value_type': value.value_type.value,
|
||||
}
|
||||
elif isinstance(value, Variable):
|
||||
if isinstance(value, Variable):
|
||||
return {
|
||||
'id': value.id,
|
||||
'name': value.name,
|
||||
'value': value.value,
|
||||
'value_type': value.value_type.value,
|
||||
}
|
||||
return value
|
||||
if isinstance(value, dict):
|
||||
value_type = value.get('value_type')
|
||||
if value_type not in ENVIRONMENT_VARIABLE_SUPPORTED_TYPES:
|
||||
raise ValueError(f'Unsupported environment variable value type: {value_type}')
|
||||
return value
|
||||
|
||||
|
||||
environment_variable_fields = {
|
||||
|
Loading…
Reference in New Issue
Block a user