Skip to content
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 @@ -7,13 +7,17 @@

from localstack.services.stepfunctions.asl.antlr.runtime.ASLLexer import ASLLexer
from localstack.services.stepfunctions.asl.antlr.runtime.ASLParser import ASLParser
from localstack.services.stepfunctions.asl.antlr.runtime.ASLParserVisitor import ASLParserVisitor
from localstack.services.stepfunctions.asl.antlr.runtime.ASLParserVisitor import (
ASLParserVisitor,
)
from localstack.services.stepfunctions.asl.antlt4utils.antlr4utils import (
from_string_literal,
is_production,
is_terminal,
)
from localstack.services.stepfunctions.asl.component.common.assign.assign_decl import AssignDecl
from localstack.services.stepfunctions.asl.component.common.assign.assign_decl import (
AssignDecl,
)
from localstack.services.stepfunctions.asl.component.common.assign.assign_decl_binding import (
AssignDeclBinding,
)
Expand All @@ -36,17 +40,25 @@
AssignTemplateValueTerminalLit,
AssignTemplateValueTerminalStringJSONata,
)
from localstack.services.stepfunctions.asl.component.common.catch.catch_decl import CatchDecl
from localstack.services.stepfunctions.asl.component.common.catch.catcher_decl import CatcherDecl
from localstack.services.stepfunctions.asl.component.common.catch.catcher_props import CatcherProps
from localstack.services.stepfunctions.asl.component.common.catch.catch_decl import (
CatchDecl,
)
from localstack.services.stepfunctions.asl.component.common.catch.catcher_decl import (
CatcherDecl,
)
from localstack.services.stepfunctions.asl.component.common.catch.catcher_props import (
CatcherProps,
)
from localstack.services.stepfunctions.asl.component.common.comment import Comment
from localstack.services.stepfunctions.asl.component.common.error_name.custom_error_name import (
CustomErrorName,
)
from localstack.services.stepfunctions.asl.component.common.error_name.error_equals_decl import (
ErrorEqualsDecl,
)
from localstack.services.stepfunctions.asl.component.common.error_name.error_name import ErrorName
from localstack.services.stepfunctions.asl.component.common.error_name.error_name import (
ErrorName,
)
from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name import (
StatesErrorName,
)
Expand Down Expand Up @@ -79,10 +91,18 @@
Parameters,
Parargs,
)
from localstack.services.stepfunctions.asl.component.common.path.input_path import InputPath
from localstack.services.stepfunctions.asl.component.common.path.items_path import ItemsPath
from localstack.services.stepfunctions.asl.component.common.path.output_path import OutputPath
from localstack.services.stepfunctions.asl.component.common.path.result_path import ResultPath
from localstack.services.stepfunctions.asl.component.common.path.input_path import (
InputPath,
)
from localstack.services.stepfunctions.asl.component.common.path.items_path import (
ItemsPath,
)
from localstack.services.stepfunctions.asl.component.common.path.output_path import (
OutputPath,
)
from localstack.services.stepfunctions.asl.component.common.path.result_path import (
ResultPath,
)
from localstack.services.stepfunctions.asl.component.common.payload.payloadvalue.payload_value import (
PayloadValue,
)
Expand Down Expand Up @@ -116,7 +136,9 @@
QueryLanguage,
QueryLanguageMode,
)
from localstack.services.stepfunctions.asl.component.common.result_selector import ResultSelector
from localstack.services.stepfunctions.asl.component.common.result_selector import (
ResultSelector,
)
from localstack.services.stepfunctions.asl.component.common.retry.backoff_rate_decl import (
BackoffRateDecl,
)
Expand All @@ -133,9 +155,15 @@
from localstack.services.stepfunctions.asl.component.common.retry.max_delay_seconds_decl import (
MaxDelaySecondsDecl,
)
from localstack.services.stepfunctions.asl.component.common.retry.retrier_decl import RetrierDecl
from localstack.services.stepfunctions.asl.component.common.retry.retrier_props import RetrierProps
from localstack.services.stepfunctions.asl.component.common.retry.retry_decl import RetryDecl
from localstack.services.stepfunctions.asl.component.common.retry.retrier_decl import (
RetrierDecl,
)
from localstack.services.stepfunctions.asl.component.common.retry.retrier_props import (
RetrierProps,
)
from localstack.services.stepfunctions.asl.component.common.retry.retry_decl import (
RetryDecl,
)
from localstack.services.stepfunctions.asl.component.common.string.string_expression import (
StringContextPath,
StringExpression,
Expand Down Expand Up @@ -291,15 +319,23 @@
Error,
ErrorPath,
)
from localstack.services.stepfunctions.asl.component.state.state_fail.state_fail import StateFail
from localstack.services.stepfunctions.asl.component.state.state_pass.result import Result
from localstack.services.stepfunctions.asl.component.state.state_pass.state_pass import StatePass
from localstack.services.stepfunctions.asl.component.state.state_fail.state_fail import (
StateFail,
)
from localstack.services.stepfunctions.asl.component.state.state_pass.result import (
Result,
)
from localstack.services.stepfunctions.asl.component.state.state_pass.state_pass import (
StatePass,
)
from localstack.services.stepfunctions.asl.component.state.state_props import StateProps
from localstack.services.stepfunctions.asl.component.state.state_succeed.state_succeed import (
StateSucceed,
)
from localstack.services.stepfunctions.asl.component.state.state_type import StateType
from localstack.services.stepfunctions.asl.component.state.state_wait.state_wait import StateWait
from localstack.services.stepfunctions.asl.component.state.state_wait.state_wait import (
StateWait,
)
from localstack.services.stepfunctions.asl.component.state.state_wait.wait_function.seconds import (
Seconds,
SecondsJSONata,
Expand All @@ -311,18 +347,24 @@
Timestamp,
TimestampPath,
)
from localstack.services.stepfunctions.asl.parse.intrinsic.intrinsic_parser import IntrinsicParser
from localstack.services.stepfunctions.asl.parse.intrinsic.intrinsic_parser import (
IntrinsicParser,
)
from localstack.services.stepfunctions.asl.parse.typed_props import TypedProps

LOG = logging.getLogger(__name__)


class Preprocessor(ASLParserVisitor):
_query_language_per_scope: list[QueryLanguage] = []
def __init__(self):
self._query_language_per_scope: list[QueryLanguage] = []

def _get_current_query_language(self) -> QueryLanguage:
return self._query_language_per_scope[-1]

def _get_top_level_query_language(self) -> QueryLanguage:
return self._query_language_per_scope[0]

def _open_query_language_scope(self, parse_tree: ParseTree) -> None:
production = is_production(parse_tree)
if production is None:
Expand All @@ -347,11 +389,11 @@ def _open_query_language_scope(self, parse_tree: ParseTree) -> None:
query_language = QueryLanguage()
# Otherwise, check for logical conflicts and add the latest or inherited value to as the next scope.
else:
current_query_language = self._get_current_query_language()
top_query_language = self._get_top_level_query_language()
if query_language is None:
query_language = current_query_language
query_language = top_query_language
if (
current_query_language.query_language_mode == QueryLanguageMode.JSONata
top_query_language.query_language_mode == QueryLanguageMode.JSONata
and query_language.query_language_mode == QueryLanguageMode.JSONPath
):
raise ValueError(
Expand Down Expand Up @@ -1507,5 +1549,6 @@ def visitString_intrinsic_function(
intrinsic_function_derivation = ctx.STRINGINTRINSICFUNC().getText()[1:-1]
function, _ = IntrinsicParser.parse(intrinsic_function_derivation)
return StringIntrinsicFunction(
intrinsic_function_derivation=intrinsic_function_derivation, function=function
intrinsic_function_derivation=intrinsic_function_derivation,
function=function,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"StartAt": "Pass",
"States": {
"Pass": {
"Type": "Pass",
"End": true,
"QueryLanguage": "JSONPath"
}
},
"QueryLanguage": "JSONata"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"StartAt": "Map",
"QueryLanguage": "JSONPath",
"States": {
"Map": {
"Type": "Map",
"QueryLanguage": "JSONata",
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "INLINE"
},
"StartAt": "Pass",
"States": {
"Pass": {
"QueryLanguage": "JSONPath",
"Type": "Pass",
"End": true
}
}
},
"End": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ class ValidationTemplate(TemplateLoader):
INVALID_BASE_NO_STARTAT: Final[str] = os.path.join(
_THIS_FOLDER, "statemachines/invalid_base_no_startat.json5"
)
INVALID_DOWNGRADE_QUERY_LANGUAGE: Final[str] = os.path.join(
_THIS_FOLDER, "statemachines/invalid_downgrade_query_language.json5"
)
VALID_BASE_PASS: Final[str] = os.path.join(_THIS_FOLDER, "statemachines/valid_base_pass.json5")
VALID_QUERY_LANGUAGE_PASS: Final[str] = os.path.join(
_THIS_FOLDER, "statemachines/valid_query_language_pass.json5"
)
24 changes: 21 additions & 3 deletions tests/aws/services/stepfunctions/v2/test_sfn_api_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ def test_validate_state_machine_definition_not_a_definition(

@pytest.mark.parametrize(
"validation_template",
[ValidationTemplate.VALID_BASE_PASS, ValidationTemplate.INVALID_BASE_NO_STARTAT],
ids=["VALID_BASE_PASS", "INVALID_BASE_NO_STARTAT"],
[
ValidationTemplate.VALID_BASE_PASS,
ValidationTemplate.INVALID_DOWNGRADE_QUERY_LANGUAGE,
ValidationTemplate.VALID_QUERY_LANGUAGE_PASS,
ValidationTemplate.INVALID_BASE_NO_STARTAT,
],
ids=[
"VALID_BASE_PASS",
"INVALID_DOWNGRADE_QUERY_LANGUAGE",
"VALID_QUERY_LANGUAGE_PASS",
"INVALID_BASE_NO_STARTAT",
],
)
@markers.aws.validated
def test_validate_state_machine_definition_type_standard(
Expand All @@ -53,9 +63,17 @@ def test_validate_state_machine_definition_type_standard(
[
ValidationTemplate.VALID_BASE_PASS,
ValidationTemplate.INVALID_BASE_NO_STARTAT,
ValidationTemplate.INVALID_DOWNGRADE_QUERY_LANGUAGE,
ValidationTemplate.VALID_QUERY_LANGUAGE_PASS,
CallbackTemplates.SQS_WAIT_FOR_TASK_TOKEN,
],
ids=["VALID_BASE_PASS", "INVALID_BASE_NO_STARTAT", "ILLEGAL_WFTT"],
ids=[
"VALID_BASE_PASS",
"INVALID_BASE_NO_STARTAT",
"INVALID_DOWNGRADE_QUERY_LANGUAGE",
"VALID_QUERY_LANGUAGE_PASS",
"ILLEGAL_WFTT",
],
)
@markers.aws.validated
def test_validate_state_machine_definition_type_express(
Expand Down
Loading
Loading