6
6
import java .util .ArrayList ;
7
7
import java .util .List ;
8
8
import java .util .Map ;
9
- import java .util .Map .Entry ;
10
9
import java .util .Set ;
11
10
import java .util .UUID ;
12
11
@@ -70,7 +69,7 @@ public void initProcessBuilderEnvironmentMap(UUID pdsJobUUID, PDSJobConfiguratio
70
69
71
70
private void calculateAndSetupEnvironment (UUID pdsJobUUID , PDSJobConfiguration config , ProcessBuilder builder , PDSProductSetup productSetup ) {
72
71
/* now init environment map */
73
- Map < String , String > environment = initCleanEnvironment (productSetup , builder );
72
+ PDSSafeProcessEnvironmentAccess environment = initCleanEnvironment (productSetup , builder );
74
73
75
74
addPdsJobRelatedVariables (pdsJobUUID , environment );
76
75
addPdsExecutorJobParameters (productSetup , config , environment );
@@ -81,55 +80,57 @@ private void calculateAndSetupEnvironment(UUID pdsJobUUID, PDSJobConfiguration c
81
80
LOG .debug ("Initialized environment variables for script of pds job: {} with: {}" , pdsJobUUID , environment );
82
81
}
83
82
84
- private Map < String , String > initCleanEnvironment (PDSProductSetup productSetup , ProcessBuilder builder ) {
83
+ private PDSSafeProcessEnvironmentAccess initCleanEnvironment (PDSProductSetup productSetup , ProcessBuilder builder ) {
85
84
Map <String , String > environment = builder .environment ();
86
85
87
86
Set <String > pdsScriptEnvWhitelist = productSetup .getEnvWhitelist ();
88
87
LOG .debug ("PDS script environment variable white list: '{}'" , pdsScriptEnvWhitelist );
89
88
90
89
environmentCleaner .clean (environment , pdsScriptEnvWhitelist );
91
90
92
- return environment ;
91
+ PDSSafeProcessEnvironmentAccess result = new PDSSafeProcessEnvironmentAccess (builder .environment ());
92
+
93
+ return result ;
93
94
94
95
}
95
96
96
- private void addPdsJobRelatedVariables (UUID pdsJobUUID , Map < String , String > map ) {
97
+ private void addPdsJobRelatedVariables (UUID pdsJobUUID , PDSSafeProcessEnvironmentAccess envAccess ) {
97
98
WorkspaceLocationData locationData = workspaceService .createLocationData (pdsJobUUID );
98
99
99
- map .put (PDS_JOB_WORKSPACE_LOCATION , locationData .getWorkspaceLocation ());
100
- map .put (PDS_JOB_RESULT_FILE , locationData .getResultFileLocation ());
101
- map .put (PDS_JOB_USER_MESSAGES_FOLDER , locationData .getUserMessagesLocation ());
102
- map .put (PDS_JOB_EVENTS_FOLDER , locationData .getEventsLocation ());
103
- map .put (PDS_JOB_METADATA_FILE , locationData .getMetaDataFileLocation ());
104
- map .put (PDS_JOB_UUID , pdsJobUUID .toString ());
105
- map .put (PDS_JOB_SOURCECODE_ZIP_FILE , locationData .getSourceCodeZipFileLocation ());
106
- map .put (PDS_JOB_BINARIES_TAR_FILE , locationData .getBinariesTarFileLocation ());
100
+ envAccess .put (PDS_JOB_WORKSPACE_LOCATION , locationData .getWorkspaceLocation ());
101
+ envAccess .put (PDS_JOB_RESULT_FILE , locationData .getResultFileLocation ());
102
+ envAccess .put (PDS_JOB_USER_MESSAGES_FOLDER , locationData .getUserMessagesLocation ());
103
+ envAccess .put (PDS_JOB_EVENTS_FOLDER , locationData .getEventsLocation ());
104
+ envAccess .put (PDS_JOB_METADATA_FILE , locationData .getMetaDataFileLocation ());
105
+ envAccess .put (PDS_JOB_UUID , pdsJobUUID .toString ());
106
+ envAccess .put (PDS_JOB_SOURCECODE_ZIP_FILE , locationData .getSourceCodeZipFileLocation ());
107
+ envAccess .put (PDS_JOB_BINARIES_TAR_FILE , locationData .getBinariesTarFileLocation ());
107
108
108
109
String extractedAssetsLocation = locationData .getExtractedAssetsLocation ();
109
110
110
- map .put (PDS_JOB_EXTRACTED_ASSETS_FOLDER , extractedAssetsLocation );
111
+ envAccess .put (PDS_JOB_EXTRACTED_ASSETS_FOLDER , extractedAssetsLocation );
111
112
112
113
String extractedSourcesLocation = locationData .getExtractedSourcesLocation ();
113
114
114
- map .put (PDS_JOB_SOURCECODE_UNZIPPED_FOLDER , extractedSourcesLocation );
115
- map .put (PDS_JOB_EXTRACTED_SOURCES_FOLDER , extractedSourcesLocation );
115
+ envAccess .put (PDS_JOB_SOURCECODE_UNZIPPED_FOLDER , extractedSourcesLocation );
116
+ envAccess .put (PDS_JOB_EXTRACTED_SOURCES_FOLDER , extractedSourcesLocation );
116
117
117
118
String extractedBinariesLocation = locationData .getExtractedBinariesLocation ();
118
- map .put (PDS_JOB_EXTRACTED_BINARIES_FOLDER , extractedBinariesLocation );
119
+ envAccess .put (PDS_JOB_EXTRACTED_BINARIES_FOLDER , extractedBinariesLocation );
119
120
120
- map .put (PDS_JOB_HAS_EXTRACTED_SOURCES , "" + workspaceService .hasExtractedSources (pdsJobUUID ));
121
- map .put (PDS_JOB_HAS_EXTRACTED_BINARIES , "" + workspaceService .hasExtractedBinaries (pdsJobUUID ));
121
+ envAccess .put (PDS_JOB_HAS_EXTRACTED_SOURCES , "" + workspaceService .hasExtractedSources (pdsJobUUID ));
122
+ envAccess .put (PDS_JOB_HAS_EXTRACTED_BINARIES , "" + workspaceService .hasExtractedBinaries (pdsJobUUID ));
122
123
123
124
}
124
125
125
- private void addPdsExecutorJobParameters (PDSProductSetup productSetup , PDSJobConfiguration config , Map < String , String > map ) {
126
+ private void addPdsExecutorJobParameters (PDSProductSetup productSetup , PDSJobConfiguration config , PDSSafeProcessEnvironmentAccess envAccess ) {
126
127
127
128
List <PDSExecutionParameterEntry > jobParams = config .getParameters ();
128
129
for (PDSExecutionParameterEntry jobParam : jobParams ) {
129
- addJobParamDataWhenAccepted (productSetup , jobParam , map );
130
+ addJobParamDataWhenAccepted (productSetup , jobParam , envAccess );
130
131
}
131
132
132
- addDefaultsForMissingParameters (productSetup , map );
133
+ addDefaultsForMissingParameters (productSetup , envAccess );
133
134
134
135
}
135
136
@@ -138,50 +139,51 @@ private void addPdsExecutorJobParameters(PDSProductSetup productSetup, PDSJobCon
138
139
* of process builder: This map does throw an exception in this case (index of
139
140
* problems)
140
141
*/
141
- private void replaceNullValuesWithEmptyStrings (Map < String , String > map ) {
142
+ private void replaceNullValuesWithEmptyStrings (PDSSafeProcessEnvironmentAccess envAccess ) {
142
143
143
144
List <String > keysForEntriesWithNullValue = new ArrayList <>();
144
145
145
- for (Entry <String , String > entry : map .entrySet ()) {
146
- if (entry .getValue () == null ) {
147
- keysForEntriesWithNullValue .add (entry .getKey ());
146
+ for (String key : envAccess .getKeys ()) {
147
+ String value = envAccess .get (key );
148
+ if (value == null ) {
149
+ keysForEntriesWithNullValue .add (key );
148
150
}
149
151
}
150
152
151
153
for (String keyForEntryWithNullValue : keysForEntriesWithNullValue ) {
152
- map .put (keyForEntryWithNullValue , "" );
154
+ envAccess .put (keyForEntryWithNullValue , "" );
153
155
154
156
LOG .warn ("Replaced null value for key: {} with empty string" , keyForEntryWithNullValue );
155
157
}
156
158
157
159
}
158
160
159
- private void addDefaultsForMissingParameters (PDSProductSetup productSetup , Map < String , String > map ) {
161
+ private void addDefaultsForMissingParameters (PDSProductSetup productSetup , PDSSafeProcessEnvironmentAccess envAccess ) {
160
162
PDSProductParameterSetup parameters = productSetup .getParameters ();
161
163
162
- addDefaultsForMissingParametersInList (parameters .getMandatory (), map );
163
- addDefaultsForMissingParametersInList (parameters .getOptional (), map );
164
+ addDefaultsForMissingParametersInList (parameters .getMandatory (), envAccess );
165
+ addDefaultsForMissingParametersInList (parameters .getOptional (), envAccess );
164
166
}
165
167
166
- private void addDefaultsForMissingParametersInList (List <PDSProductParameterDefinition > parameterDefinitions , Map < String , String > map ) {
168
+ private void addDefaultsForMissingParametersInList (List <PDSProductParameterDefinition > parameterDefinitions , PDSSafeProcessEnvironmentAccess envAccess ) {
167
169
168
170
for (PDSProductParameterDefinition parameterDefinition : parameterDefinitions ) {
169
171
if (!parameterDefinition .hasDefault ()) {
170
172
continue ;
171
173
}
172
174
String envVariableName = converter .convertKeyToEnv (parameterDefinition .getKey ());
173
175
174
- String value = map .get (envVariableName );
176
+ String value = envAccess .get (envVariableName );
175
177
176
178
if (value == null ) {
177
- map .put (envVariableName , parameterDefinition .getDefault ());
179
+ envAccess .put (envVariableName , parameterDefinition .getDefault ());
178
180
}
179
181
}
180
182
181
183
}
182
184
183
- private void addSecHubJobUUIDAsEnvironmentEntry (PDSJobConfiguration config , Map < String , String > map ) {
184
- map .put (PDSLauncherScriptEnvironmentConstants .SECHUB_JOB_UUID , fetchSecHubJobUUIDasString (config ));
185
+ private void addSecHubJobUUIDAsEnvironmentEntry (PDSJobConfiguration config , PDSSafeProcessEnvironmentAccess envAccess ) {
186
+ envAccess .put (PDSLauncherScriptEnvironmentConstants .SECHUB_JOB_UUID , fetchSecHubJobUUIDasString (config ));
185
187
}
186
188
187
189
private String fetchSecHubJobUUIDasString (PDSJobConfiguration pdsJobConfiguration ) {
@@ -193,7 +195,7 @@ private String fetchSecHubJobUUIDasString(PDSJobConfiguration pdsJobConfiguratio
193
195
return sechubJobUUID .toString ();
194
196
}
195
197
196
- private void addJobParamDataWhenAccepted (PDSProductSetup productSetup , PDSExecutionParameterEntry jobParam , Map < String , String > map ) {
198
+ private void addJobParamDataWhenAccepted (PDSProductSetup productSetup , PDSExecutionParameterEntry jobParam , PDSSafeProcessEnvironmentAccess envAccess ) {
197
199
PDSProductParameterSetup params = productSetup .getParameters ();
198
200
199
201
boolean acceptedParameter = false ;
@@ -214,7 +216,7 @@ private void addJobParamDataWhenAccepted(PDSProductSetup productSetup, PDSExecut
214
216
215
217
if (acceptedParameter ) {
216
218
String envVariableName = converter .convertKeyToEnv (jobParam .getKey ());
217
- map .put (envVariableName , jobParam .getValue ());
219
+ envAccess .put (envVariableName , jobParam .getValue ());
218
220
} else {
219
221
if (wellknown ) {
220
222
LOG .debug ("Wellknown parameter found - but not available inside script: {}" , jobParam .getKey ());
0 commit comments