Skip to content

[SFN] Handling of Unsupported ASL Bindings #14

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ state_machine: program_decl EOF;

program_decl: LBRACE top_layer_stmt (COMMA top_layer_stmt)* RBRACE;

top_layer_stmt: comment_decl | version_decl | startat_decl | states_decl | timeout_seconds_decl;
top_layer_stmt:
comment_decl
| version_decl
| startat_decl
| states_decl
| timeout_seconds_decl
| unknown_binding_decl
;

startat_decl: STARTAT COLON keyword_or_string;

Expand Down Expand Up @@ -60,13 +67,13 @@ state_stmt:
| tolerated_failure_count_path_decl
| tolerated_failure_percentage_decl
| tolerated_failure_percentage_path_decl
| unknown_binding_decl
;

states_decl: STATES COLON LBRACE state_decl (COMMA state_decl)* RBRACE;

state_name: keyword_or_string;

// TODO: avoid redefinitions? -> check listener ok?
state_decl: state_name COLON state_decl_body;

state_decl_body: LBRACE state_stmt (COMMA state_stmt)* RBRACE;
Expand Down Expand Up @@ -481,4 +488,7 @@ keyword_or_string:
| ERRORNAMEStatesItemReaderFailed
| ERRORNAMEStatesResultWriterFailed
| ERRORNAMEStatesRuntime
;
;

// Consume any unknown binding and it's object.
unknown_binding_decl: STRING COLON json_value_decl;

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -971,5 +971,14 @@ def exitKeyword_or_string(self, ctx:ASLParser.Keyword_or_stringContext):
pass


# Enter a parse tree produced by ASLParser#unknown_binding_decl.
def enterUnknown_binding_decl(self, ctx:ASLParser.Unknown_binding_declContext):
pass

# Exit a parse tree produced by ASLParser#unknown_binding_decl.
def exitUnknown_binding_decl(self, ctx:ASLParser.Unknown_binding_declContext):
pass



del ASLParser
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,10 @@ def visitKeyword_or_string(self, ctx:ASLParser.Keyword_or_stringContext):
return self.visitChildren(ctx)


# Visit a parse tree produced by ASLParser#unknown_binding_decl.
def visitUnknown_binding_decl(self, ctx:ASLParser.Unknown_binding_declContext):
return self.visitChildren(ctx)



del ASLParser
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from typing import Optional

from antlr4 import ParserRuleContext
Expand Down Expand Up @@ -237,6 +238,8 @@
from localstack.services.stepfunctions.asl.component.states import States
from localstack.services.stepfunctions.asl.parse.typed_props import TypedProps

LOG = logging.getLogger(__name__)


class Preprocessor(ASLParserVisitor):
@staticmethod
Expand Down Expand Up @@ -915,3 +918,12 @@ def visitProgram_decl(self, ctx: ASLParser.Program_declContext) -> Program:

def visitState_machine(self, ctx: ASLParser.State_machineContext) -> Program:
return self.visit(ctx.program_decl())

def visitUnknown_binding_decl(self, ctx: ASLParser.Unknown_binding_declContext) -> None:
binding_name = self._inner_string_of(parse_tree=ctx.STRING())
json_decl = ctx.json_value_decl()
json_str: str = json_decl.getText()
LOG.warning(
f"Unsupported declaration '{binding_name}' with value '{json_str}' "
f"will not be evaluated during program execution."
)
26 changes: 26 additions & 0 deletions tests/aws/services/stepfunctions/v2/base/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,29 @@ def test_state_pass_regex_json_path(
definition,
exec_input,
)

@markers.aws.validated
def test_unknown_bindings(
self,
aws_client,
create_iam_role_for_sfn,
create_state_machine,
sfn_snapshot,
):
template = BaseTemplate.load_sfn_template(BaseTemplate.BASE_PASS_RESULT)

if not is_aws_cloud():
template["UnknownBinding"] = "StringValue"
template["States"]["State_1"]["UnknownBinding"] = {"KeyValue": [], "End": {}}
Comment on lines +411 to +412
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider using a more descriptive key name than 'UnknownBinding' to clarify its purpose


definition = json.dumps(template)

exec_input = json.dumps({})
create_and_record_execution(
aws_client.stepfunctions,
create_iam_role_for_sfn,
create_state_machine,
sfn_snapshot,
definition,
exec_input,
)
68 changes: 68 additions & 0 deletions tests/aws/services/stepfunctions/v2/base/test_base.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -1108,5 +1108,73 @@
}
}
}
},
"tests/aws/services/stepfunctions/v2/base/test_base.py::TestSnfBase::test_unknown_bindings": {
"recorded-date": "19-06-2024, 15:51:06",
"recorded-content": {
"get_execution_history": {
"events": [
{
"executionStartedEventDetails": {
"input": {},
"inputDetails": {
"truncated": false
},
"roleArn": "snf_role_arn"
},
"id": 1,
"previousEventId": 0,
"timestamp": "timestamp",
"type": "ExecutionStarted"
},
{
"id": 2,
"previousEventId": 0,
"stateEnteredEventDetails": {
"input": {},
"inputDetails": {
"truncated": false
},
"name": "State_1"
},
"timestamp": "timestamp",
"type": "PassStateEntered"
},
{
"id": 3,
"previousEventId": 2,
"stateExitedEventDetails": {
"name": "State_1",
"output": {
"Arg1": "argument1"
},
"outputDetails": {
"truncated": false
}
},
"timestamp": "timestamp",
"type": "PassStateExited"
},
{
"executionSucceededEventDetails": {
"output": {
"Arg1": "argument1"
},
"outputDetails": {
"truncated": false
}
},
"id": 4,
"previousEventId": 3,
"timestamp": "timestamp",
"type": "ExecutionSucceeded"
}
],
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
},
"tests/aws/services/stepfunctions/v2/base/test_base.py::TestSnfBase::test_state_pass_result_null_input_output_paths": {
"last_validated_date": "2024-02-07T13:52:29+00:00"
},
"tests/aws/services/stepfunctions/v2/base/test_base.py::TestSnfBase::test_unknown_bindings": {
"last_validated_date": "2024-06-19T15:51:06+00:00"
}
}