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

add support for get_run_id() as magic variable #1426

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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