88package io .harness .iacm .execution ;
99
1010import static io .harness .ci .commonconstants .CIExecutionConstants .WORKSPACE_ID ;
11- import static io .harness .data .structure .EmptyPredicate .isEmpty ;
1211
1312import io .harness .beans .entities .Workspace ;
1413import io .harness .beans .entities .WorkspaceVariables ;
@@ -54,57 +53,44 @@ public void createExecution(Ambiance ambiance, String workspaceId) {
5453
5554 private Map <String , String > getWorkspaceVariables (Ambiance ambiance , String org , String projectId , String accountId ,
5655 String workspaceID , String command , Workspace workspaceInfo ) {
57- String pluginEnvPrefix = "PLUGIN_" ;
58-
5956 WorkspaceVariables [] variables = getIACMWorkspaceVariables (org , projectId , accountId , workspaceID );
6057 HashMap <String , String > pluginEnvs = new HashMap <>();
6158
62- HashMap <String , String > env = new HashMap <>();
63- HashMap <String , String > tfInputEnvs = new HashMap <>();
59+ // Plugin system env variables
60+ pluginEnvs .put ("PLUGIN_ROOT_DIR" , workspaceInfo .getRepository_path ());
61+ pluginEnvs .put ("PLUGIN_TF_VERSION" , workspaceInfo .getProvisioner_version ());
62+ pluginEnvs .put ("PLUGIN_ENDPOINT_VARIABLES" , getTerraformEndpointsInfo (ambiance , workspaceID ));
63+
64+ if (!Objects .equals (command , "" )) {
65+ pluginEnvs .put ("PLUGIN_COMMAND" , command );
66+ }
6467
6568 for (WorkspaceVariables variable : variables ) {
6669 switch (variable .getKind ()) {
6770 case "env" :
6871 if (Objects .equals (variable .getValue_type (), "secret" )) {
69- env .put (variable .getKey (), "${ngSecretManager.obtain(\" " + variable .getKey () + "\" , -871314908)}" );
72+ pluginEnvs .put ("PLUGIN_WS_ENV_VAR_" + variable .getKey (),
73+ "${ngSecretManager.obtain(\" " + variable .getValue () + "\" , " + ambiance .getExpressionFunctorToken ()
74+ + ")}" );
7075 } else {
71- env .put (variable .getKey (), variable .getValue ());
76+ pluginEnvs .put ("PLUGIN_WS_ENV_VAR_" + variable .getKey (), variable .getValue ());
7277 }
7378 break ;
7479 case "tf" :
7580 if (Objects .equals (variable .getValue_type (), "secret" )) {
76- tfInputEnvs .put (variable .getKey (), "${ngSecretManager.obtain(\" " + variable .getKey () + "\" , -871314908)}" );
81+ pluginEnvs .put ("PLUGIN_WS_TF_VAR_" + variable .getKey (),
82+ "${ngSecretManager.obtain(\" " + variable .getValue () + "\" , " + ambiance .getExpressionFunctorToken ()
83+ + ")}" );
7784 } else {
78- tfInputEnvs .put (variable .getKey (), variable .getValue ());
85+ pluginEnvs .put ("PLUGIN_WS_TF_VAR_" + variable .getKey (), variable .getValue ());
7986 }
8087 break ;
8188 default :
8289 break ;
8390 }
8491 }
8592
86- // Plugin system env variables
87- pluginEnvs .put ("ROOT_DIR" , workspaceInfo .getRepository_path ());
88- pluginEnvs .put ("TF_VERSION" , workspaceInfo .getProvisioner_version ());
89- pluginEnvs .put ("ENDPOINT_VARIABLES" , getTerraformEndpointsInfo (ambiance , workspaceID ));
90- pluginEnvs .put ("VARS" , transformMapToString (tfInputEnvs ));
91- pluginEnvs .put ("ENV_VARS" , transformMapToString (env ));
92-
93- if (!Objects .equals (command , "" )) {
94- pluginEnvs .put ("COMMAND" , command );
95- }
96- return prepareEnvsMaps (pluginEnvs , pluginEnvPrefix );
97- }
98-
99- private Map <String , String > prepareEnvsMaps (Map <String , String > envs , String prefix ) {
100- Map <String , String > envVars = new HashMap <>();
101- if (!isEmpty (envs )) {
102- for (Map .Entry <String , String > entry : envs .entrySet ()) {
103- String key = prefix + entry .getKey ();
104- envVars .put (key , entry .getValue ());
105- }
106- }
107- return envVars ;
93+ return pluginEnvs ;
10894 }
10995
11096 private WorkspaceVariables [] getIACMWorkspaceVariables (
@@ -128,6 +114,7 @@ public Map<String, String> getIACMEnvVariables(Ambiance ambiance, PluginStepInfo
128114 String command = extractOperation (stepInfo );
129115 return buildIACMEnvVariables (ambiance , workspaceId , command );
130116 }
117+
131118 private Map <String , String > buildIACMEnvVariables (Ambiance ambiance , String workspaceId , String command ) {
132119 NGAccess ngAccess = AmbianceUtils .getNgAccess (ambiance );
133120
0 commit comments