Skip to content

Commit

Permalink
Merge pull request #1426 from CloudSlang/support-for-get-run-id
Browse files Browse the repository at this point in the history
add support for get_run_id() as magic variable
  • Loading branch information
QueueUpX authored Nov 22, 2023
2 parents e897c3c + ea8fb43 commit 42334c7
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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*)(#!!)(([^#])(.*))*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public Map<String, Value> 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);
}
}
6 changes: 6 additions & 0 deletions cloudslang-runtime/src/main/resources/scripts/get_run_id.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScoreEvent> events) {
Expand Down

0 comments on commit 42334c7

Please sign in to comment.