From 96cc374cdc55165958285a64895ce9182be8c815 Mon Sep 17 00:00:00 2001 From: GIlca Date: Tue, 21 Nov 2023 16:52:03 +0200 Subject: [PATCH 1/2] add support for get_run_id() as magic variable --- .../cloudslang/lang/entities/bindings/ScriptFunction.java | 4 +++- .../java/io/cloudslang/lang/entities/constants/Regex.java | 1 + .../io/cloudslang/lang/entities/utils/ExpressionUtils.java | 2 ++ .../java/io/cloudslang/lang/runtime/RuntimeConstants.java | 1 + .../io/cloudslang/lang/runtime/services/ScriptsService.java | 3 ++- .../lang/runtime/steps/CsMagicVariableHelper.java | 1 + cloudslang-runtime/src/main/resources/scripts/get_run_id.py | 6 ++++++ 7 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 cloudslang-runtime/src/main/resources/scripts/get_run_id.py diff --git a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/bindings/ScriptFunction.java b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/bindings/ScriptFunction.java index 3d7cc56d6..db294421c 100644 --- a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/bindings/ScriptFunction.java +++ b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/bindings/ScriptFunction.java @@ -47,7 +47,9 @@ public enum ScriptFunction { GET_USER_ID("get_user_id"), - GET_WORKER_GROUP("get_worker_group"); + GET_WORKER_GROUP("get_worker_group"), + + GET_RUN_ID("get_run_id"); private final String value; diff --git a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/constants/Regex.java b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/constants/Regex.java index 3741e1da8..1f3fd1747 100644 --- a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/constants/Regex.java +++ b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/constants/Regex.java @@ -56,6 +56,7 @@ public class Regex { public static final String CS_TO_LOWER_REGEX = "cs_to_lower\\((.+?)\\)"; public static final String GET_USER_ID_REGEX = "get_user_id()"; public static final String GET_WORKER_GROUP_REGEX = "get_worker_group()"; + public static final String GET_RUN_ID_REGEX = "get_run_id()"; //////////////// description public static final String DESCRIPTION_START_LINE = "(\\s*)(#!!)(([^#])(.*))*"; diff --git a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/utils/ExpressionUtils.java b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/utils/ExpressionUtils.java index 439ea0243..6f6598487 100644 --- a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/utils/ExpressionUtils.java +++ b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/utils/ExpressionUtils.java @@ -40,6 +40,7 @@ import static io.cloudslang.lang.entities.constants.Regex.GET_SP_VAR_REGEX_WITH_SINGLE_QUOTES; import static io.cloudslang.lang.entities.constants.Regex.GET_USER_ID_REGEX; import static io.cloudslang.lang.entities.constants.Regex.GET_WORKER_GROUP_REGEX; +import static io.cloudslang.lang.entities.constants.Regex.GET_RUN_ID_REGEX; import static io.cloudslang.lang.entities.constants.Regex.SYSTEM_PROPERTY_REGEX_DOUBLE_QUOTE; import static io.cloudslang.lang.entities.constants.Regex.SYSTEM_PROPERTY_REGEX_SINGLE_QUOTE; import static io.cloudslang.lang.entities.constants.Regex.SYSTEM_PROPERTY_REGEX_WITHOUT_QUOTES; @@ -99,6 +100,7 @@ private ExpressionUtils() { addPattern(ScriptFunction.CS_TO_UPPER, CS_TO_UPPER_REGEX); addPattern(ScriptFunction.GET_USER_ID, GET_USER_ID_REGEX); addPattern(ScriptFunction.GET_WORKER_GROUP, GET_WORKER_GROUP_REGEX); + addPattern(ScriptFunction.GET_RUN_ID, GET_RUN_ID_REGEX); } private static void addPattern(ScriptFunction function, String regex) { diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/RuntimeConstants.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/RuntimeConstants.java index 7cfe8a746..402edc0f3 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/RuntimeConstants.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/RuntimeConstants.java @@ -24,5 +24,6 @@ public interface RuntimeConstants { String EXECUTION_ID = "run_id"; String USER_ID = "get_user_id()"; String WORKER_GROUP = "get_worker_group()"; + String RUN_ID = "get_run_id()"; } diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/services/ScriptsService.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/services/ScriptsService.java index 9b04ff54e..95d7acca6 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/services/ScriptsService.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/services/ScriptsService.java @@ -48,7 +48,8 @@ public void init() throws IOException { ScriptFunction.CS_TO_LOWER, ScriptFunction.GET_SP_VAR, ScriptFunction.GET_USER_ID, - ScriptFunction.GET_WORKER_GROUP + ScriptFunction.GET_WORKER_GROUP, + ScriptFunction.GET_RUN_ID ); for (ScriptFunction function: list) { diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/CsMagicVariableHelper.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/CsMagicVariableHelper.java index ee3553b18..00d8522d9 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/CsMagicVariableHelper.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/CsMagicVariableHelper.java @@ -33,6 +33,7 @@ public Map getGlobalContext(ExecutionRuntimeServices executionRun globalContext.put(RuntimeConstants.USER_ID, ValueFactory.create(userId)); globalContext.put(RuntimeConstants.WORKER_GROUP, ValueFactory.create(workerGroup == null ? RAS_OPERATOR_PATH : workerGroup)); + globalContext.put(RuntimeConstants.RUN_ID, ValueFactory.create(executionId)); return Collections.unmodifiableMap(globalContext); } } diff --git a/cloudslang-runtime/src/main/resources/scripts/get_run_id.py b/cloudslang-runtime/src/main/resources/scripts/get_run_id.py new file mode 100644 index 000000000..e00560bce --- /dev/null +++ b/cloudslang-runtime/src/main/resources/scripts/get_run_id.py @@ -0,0 +1,6 @@ +def get_run_id(): + try: + value = get_from_smaller_context("get_run_id()") + except NameError: + value = globals().get("get_run_id()") + return "" if value is None else value \ No newline at end of file From ea8fb434c7d1011f7f8f8cfd3ea4a0815e91c941 Mon Sep 17 00:00:00 2001 From: GIlca Date: Wed, 22 Nov 2023 09:53:11 +0200 Subject: [PATCH 2/2] fix test --- .../test/java/io/cloudslang/lang/systemtests/EventDataTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/cloudslang-tests/src/test/java/io/cloudslang/lang/systemtests/EventDataTest.java b/cloudslang-tests/src/test/java/io/cloudslang/lang/systemtests/EventDataTest.java index ec582dcff..284e511e9 100644 --- a/cloudslang-tests/src/test/java/io/cloudslang/lang/systemtests/EventDataTest.java +++ b/cloudslang-tests/src/test/java/io/cloudslang/lang/systemtests/EventDataTest.java @@ -216,6 +216,7 @@ private void populateMagicVariables(String runId) { CONTEXT_STEP_PUBLISH_01.put(RuntimeConstants.EXECUTION_ID, runId); CONTEXT_STEP_PUBLISH_01.put(RuntimeConstants.USER_ID, ""); CONTEXT_STEP_PUBLISH_01.put(RuntimeConstants.WORKER_GROUP, "RAS_Operator_Path"); + CONTEXT_STEP_PUBLISH_01.put(RuntimeConstants.RUN_ID, runId); } private void validateSensitiveDataNotReveiledInContext(List events) {