fix(api/fields/workflow_fields.py): Add check in environment variables (#6621)

This commit is contained in:
-LAN- 2024-07-25 11:30:52 +08:00 committed by GitHub
parent ca696fe94c
commit 55c2b61921
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 = {