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 77c6c37104..3d7cc56d60 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 @@ -43,7 +43,11 @@ public enum ScriptFunction { CS_JSON_QUERY("cs_json_query"), - GET_SP_VAR("get_sp_var"); + GET_SP_VAR("get_sp_var"), + + GET_USER_ID("get_user_id"), + + GET_WORKER_GROUP("get_worker_group"); 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 84af679595..3741e1da8e 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 @@ -54,6 +54,8 @@ public class Regex { public static final String CS_SUBSTRING_REGEX = "cs_substring\\((.+?),(.+?)(,(.+?))?\\)"; public static final String CS_TO_UPPER_REGEX = "cs_to_upper\\((.+?)\\)"; 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()"; //////////////// 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 36f928c73e..439ea02438 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 @@ -38,6 +38,8 @@ import static io.cloudslang.lang.entities.constants.Regex.GET_SP_VAR_REGEX_WITHOUT_QUOTES; import static io.cloudslang.lang.entities.constants.Regex.GET_SP_VAR_REGEX_WITH_DOUBLE_QUOTES; 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.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; @@ -95,6 +97,8 @@ private ExpressionUtils() { addPattern(ScriptFunction.CS_SUBSTRING, CS_SUBSTRING_REGEX); addPattern(ScriptFunction.CS_TO_LOWER, CS_TO_LOWER_REGEX); 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); } 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 405feedd46..7cfe8a746c 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 @@ -22,5 +22,7 @@ public interface RuntimeConstants { String BRANCH_RETURN_VALUES_KEY = "branchReturnValues"; String EXECUTION_ID = "run_id"; + String USER_ID = "get_user_id()"; + String WORKER_GROUP = "get_worker_group()"; } 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 cc82a8d75d..9b04ff54ef 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 @@ -46,7 +46,9 @@ public void init() throws IOException { ScriptFunction.CS_SUBSTRING, ScriptFunction.CS_TO_UPPER, ScriptFunction.CS_TO_LOWER, - ScriptFunction.GET_SP_VAR + ScriptFunction.GET_SP_VAR, + ScriptFunction.GET_USER_ID, + ScriptFunction.GET_WORKER_GROUP ); 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 9bb7764fc6..ee3553b183 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 @@ -22,10 +22,17 @@ @Component("csMagicVariableHelper") public class CsMagicVariableHelper { + private static final String RAS_OPERATOR_PATH = "RAS_Operator_Path"; + public Map getGlobalContext(ExecutionRuntimeServices executionRuntimeServices) { Map globalContext = new HashMap<>(); String executionId = String.valueOf(executionRuntimeServices.getExecutionId()); + String userId = executionRuntimeServices.getEffectiveRunningUser(); + String workerGroup = executionRuntimeServices.getWorkerGroupName(); globalContext.put(RuntimeConstants.EXECUTION_ID, ValueFactory.create(executionId)); + globalContext.put(RuntimeConstants.USER_ID, ValueFactory.create(userId)); + globalContext.put(RuntimeConstants.WORKER_GROUP, ValueFactory.create(workerGroup == null ? + RAS_OPERATOR_PATH : workerGroup)); return Collections.unmodifiableMap(globalContext); } } diff --git a/cloudslang-runtime/src/main/resources/scripts/get_user_id.py b/cloudslang-runtime/src/main/resources/scripts/get_user_id.py new file mode 100644 index 0000000000..a8b60ef104 --- /dev/null +++ b/cloudslang-runtime/src/main/resources/scripts/get_user_id.py @@ -0,0 +1,6 @@ +def get_user_id(): + try: + value = get_from_smaller_context("get_user_id()") + except NameError: + value = globals().get("get_user_id()") + return "" if value is None else value diff --git a/cloudslang-runtime/src/main/resources/scripts/get_worker_group.py b/cloudslang-runtime/src/main/resources/scripts/get_worker_group.py new file mode 100644 index 0000000000..8cc5731429 --- /dev/null +++ b/cloudslang-runtime/src/main/resources/scripts/get_worker_group.py @@ -0,0 +1,6 @@ +def get_worker_group(): + try: + value = get_from_smaller_context("get_worker_group()") + except NameError: + value = globals().get("get_worker_group()") + return "" if value is None else value