Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow output_schema to validate non-object action output (int, bool, etc) #5319

Merged
merged 44 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1bbf0be
protect more datatypes in output_value inspection
cognifloyd Aug 4, 2021
44874e4
add tests for output_schema validation
cognifloyd Aug 4, 2021
61f10a6
adjust test comments
cognifloyd Aug 4, 2021
a129c8d
Fix var usage
cognifloyd Aug 4, 2021
d12042b
Merge branch 'master' into patch-7
cognifloyd Aug 4, 2021
6524d74
Add recursive _get_masked_value function
cognifloyd Aug 6, 2021
3becc3e
return quickly if output_value[output_key] is wrong type
cognifloyd Aug 6, 2021
49508d2
Add coments explaining output_schema validating objects
cognifloyd Aug 6, 2021
dd05bc0
check for unhandled_keys before compiling regex
cognifloyd Aug 6, 2021
2bb40d7
Allow action output_schema to be a full jsonschema
cognifloyd Aug 6, 2021
8f830b6
Regenerate action schema for new action_output format
cognifloyd Aug 6, 2021
2bfc098
Merge branch 'master' into patch-7
cognifloyd Oct 5, 2021
6b02ed4
Merge branch 'master' into patch-7
cognifloyd Mar 29, 2022
6e7ec73
try simplifying output_schema
cognifloyd Mar 29, 2022
95062c0
turn runner output_schema into full jsonschema
cognifloyd Mar 29, 2022
2461a4d
turn test runner/action output_schema into full jsonschema
cognifloyd Mar 30, 2022
94e78b4
schema validation: inject defaults only if dependencies are met.
cognifloyd Mar 30, 2022
cc32381
schema validation: runner schema is always a full schema now
cognifloyd Mar 30, 2022
36cb3b1
adjust more output_schema tests
cognifloyd Mar 30, 2022
066ff8b
Complete output_schemas including additionalProperties
cognifloyd Mar 30, 2022
dd9e032
Clean up action_output_schema usage
cognifloyd Mar 30, 2022
10c828c
secret_masking typing fixes
cognifloyd Mar 30, 2022
cab0548
drop legacy partial object output_schema support
cognifloyd Mar 30, 2022
b904b12
Clarify why mask_output returns early
cognifloyd Mar 30, 2022
d15db88
Fix test output_schema in python_runner tests
cognifloyd Mar 30, 2022
3cf35af
Add more malformed output_schema tests
cognifloyd Mar 30, 2022
dc6af0e
More reliable output_schema._schema_is_valid
cognifloyd Mar 30, 2022
9dd7245
Refactor for clarity
cognifloyd Mar 30, 2022
5fc52f2
add changelog entry
cognifloyd Mar 30, 2022
0f52eda
revert action_output_schema additional_properties change
cognifloyd Mar 30, 2022
4144013
add test for top-level output secret masking
cognifloyd Mar 30, 2022
398d273
Reduce duplication in output_schema tests
cognifloyd Mar 30, 2022
accd679
Fix typo in ouptut_schema tests
cognifloyd Mar 30, 2022
dfad436
Fix issues with output_schema array handling
cognifloyd Mar 31, 2022
8e925d0
Add debug log for schema validation errors
cognifloyd Mar 31, 2022
91ddd42
test output_schema with additionalProperties schema
cognifloyd Mar 31, 2022
5618d34
fix output_schema with patternProperties schema
cognifloyd Mar 31, 2022
3e1a052
reformat with black
cognifloyd Mar 31, 2022
d5222eb
Merge branch 'master' into patch-7
cognifloyd Mar 31, 2022
c640f07
Merge branch 'master' into patch-7
cognifloyd Jul 5, 2022
6654603
Merge branch 'master' into patch-7
cognifloyd Jul 10, 2022
3bb046e
Merge branch 'master' into patch-7
cognifloyd Jul 10, 2022
975c242
highlight that the output_schema change is a breaking change
cognifloyd Jul 16, 2022
40c0a4e
Merge branch 'master' into patch-7
cognifloyd Jul 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,45 @@ Added
* Added graceful shutdown for workflow engine. #5463
Contributed by @khushboobhatia01

Changed
~~~~~~~

* BREAKING CHANGE for anyone that uses ``output_schema``, which is disabled by default.
If you have ``[system].validate_output_schema = True`` in st2.conf AND you have added
``output_schema`` to any of your packs, then you must update your action metadata.

``output_schema`` must be a full jsonschema now. If a schema is not well-formed, we ignore it.
Now, ``output`` can be types other than object such as list, bool, int, etc.
This also means that all of an action's output can be masked as a secret.

To get the same behavior, you'll need to update your output schema.
For example, this schema:

.. code-block:: yaml

output_schema:
property1:
type: bool
property2:
type: str

should be updated like this:
cognifloyd marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: yaml

output_schema:
type: object
properties:
property1:
type: bool
property2:
type: str
additionalProperties: false

#5319

Contributed by @cognifloyd

3.7.0 - May 05, 2022
--------------------

Expand Down Expand Up @@ -143,6 +182,7 @@ Added
* Added garbage collection for rule_enforcement and trace models #5596/5602
Contributed by Amanda McGuinness (@amanda11 intive)


* Added garbage collection for workflow execution and task execution objects #4924
Contributed by @srimandaleeka01 and @amanda11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
type: array
output_key: published
output_schema:
published:
type: "object"
tasks:
type: "array"
type: object
properties:
published:
type: "object"
tasks:
type: "array"
additionalProperties: false
33 changes: 18 additions & 15 deletions contrib/runners/http_runner/http_runner/runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@
type: string
output_key: body
output_schema:
status_code:
type: integer
body:
anyOf:
- type: "object"
- type: "string"
- type: "integer"
- type: "number"
- type: "boolean"
- type: "array"
- type: "null"
parsed:
type: boolean
headers:
type: object
type: object
properties:
status_code:
type: integer
body:
anyOf:
- type: "object"
- type: "string"
- type: "integer"
- type: "number"
- type: "boolean"
- type: "array"
- type: "null"
parsed:
type: boolean
headers:
type: object
additionalProperties: false
29 changes: 16 additions & 13 deletions contrib/runners/orquesta_runner/orquesta_runner/runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
default: []
output_key: output
output_schema:
errors:
anyOf:
- type: "object"
- type: "array"
output:
anyOf:
- type: "object"
- type: "string"
- type: "integer"
- type: "number"
- type: "boolean"
- type: "array"
- type: "null"
type: object
properties:
errors:
anyOf:
- type: "object"
- type: "array"
output:
anyOf:
- type: "object"
- type: "string"
- type: "integer"
- type: "number"
- type: "boolean"
- type: "array"
- type: "null"
additionalProperties: false
39 changes: 21 additions & 18 deletions contrib/runners/python_runner/python_runner/runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
runner_module: python_runner
output_key: result
output_schema:
result:
anyOf:
- type: "object"
- type: "string"
- type: "integer"
- type: "number"
- type: "boolean"
- type: "array"
- type: "null"
stderr:
type: string
required: true
stdout:
type: string
required: true
exit_code:
type: integer
required: true
type: object
properties:
result:
anyOf:
- type: "object"
- type: "string"
- type: "integer"
- type: "number"
- type: "boolean"
- type: "array"
- type: "null"
stderr:
type: string
required: true
stdout:
type: string
required: true
exit_code:
type: integer
required: true
additionalProperties: false
runner_parameters:
debug:
description: Enable runner debug mode.
Expand Down
12 changes: 8 additions & 4 deletions contrib/runners/python_runner/tests/unit/test_output_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@
MOCK_EXECUTION = mock.Mock()
MOCK_EXECUTION.id = "598dbf0c0640fd54bffc688b"

FAIL_SCHEMA = {
"notvalid": {
"type": "string",
FAIL_OUTPUT_SCHEMA = {
"type": "object",
"properties": {
"notvalid": {
"type": "string",
},
},
"additionalProperties": False,
}


Expand Down Expand Up @@ -78,7 +82,7 @@ def test_fail_incorrect_output_schema(self):
runner.pre_run()
(status, output, _) = runner.run({"row_index": 5})
with self.assertRaises(jsonschema.ValidationError):
output_schema._validate_runner(FAIL_SCHEMA, output)
output_schema._validate_runner(FAIL_OUTPUT_SCHEMA, output)

def _get_mock_runner_obj(self, pack=None, sandbox=None):
runner = python_runner.get_runner()
Expand Down
Loading