@@ -36,19 +36,39 @@ def _output_schema_is_valid(_schema):
3636 if not isinstance (_schema , Mapping ):
3737 # malformed schema
3838 return False
39+
40+ if "type" not in _schema :
41+ # legacy schema format
42+ return False
43+
3944 try :
45+ # the validator is smart enough to handle
46+ # schema that is similar to the input schema
4047 schema .validate (
4148 _schema ,
4249 schema .get_action_output_schema (),
4350 cls = schema .get_validator ("custom" ),
4451 )
4552 except jsonschema .ValidationError as e :
4653 LOG .debug ("output_schema not valid: %s" , e )
47- # likely a legacy partial object schema (only defines properties)
4854 return False
55+
4956 return True
5057
5158
59+ def _normalize_legacy_output_schema (_schema ):
60+ if not isinstance (_schema , Mapping ):
61+ return _schema
62+
63+ _normalized_schema = {
64+ "type" : "object" ,
65+ "properties" : _schema ,
66+ "additionalProperties" : True ,
67+ }
68+
69+ return _normalized_schema
70+
71+
5272def _validate_runner (runner_schema , result ):
5373 LOG .debug ("Validating runner output: %s" , runner_schema )
5474
@@ -183,15 +203,31 @@ def mask_secret_output(ac_ex, output_value):
183203 or output_key not in output_value
184204 # no action output_schema defined
185205 or not output_schema
186- # malformed action output_schema
187- or not _output_schema_is_valid (output_schema )
188206 ):
189207 # nothing to mask
190208 return output_value
191209
210+ # backward compatibility for legacy output_schema so secrets stay masked
211+ if not _output_schema_is_valid (output_schema ):
212+ # normalized the legacy schema to a full JSON schema and check if it is valid
213+ normalized_output_schema = _normalize_legacy_output_schema (output_schema )
214+
215+ if not _output_schema_is_valid (normalized_output_schema ):
216+ # nothing to mask
217+ return output_value
218+
219+ # mask secret for the legacy output schema
220+ output_value [output_key ] = _get_masked_value (
221+ normalized_output_schema , output_value [output_key ]
222+ )
223+
224+ return output_value
225+
226+ # mask secret for the output schema
192227 output_value [output_key ] = _get_masked_value (
193228 output_schema , output_value [output_key ]
194229 )
230+
195231 return output_value
196232
197233
0 commit comments