|
40 | 40 | import jenkins.model.Jenkins; |
41 | 41 | import jenkins.tasks.SimpleBuildStep; |
42 | 42 | import net.sf.json.JSONObject; |
| 43 | + |
43 | 44 | import org.apache.commons.io.FileUtils; |
44 | 45 | import org.apache.commons.io.IOUtils; |
45 | 46 | import org.apache.commons.lang3.StringEscapeUtils; |
46 | 47 | import org.apache.commons.lang3.StringUtils; |
| 48 | +import org.apache.commons.lang3.SystemUtils; |
47 | 49 | import org.jetbrains.annotations.NotNull; |
48 | 50 | import org.jetbrains.annotations.Nullable; |
49 | 51 | import org.kohsuke.stapler.*; |
@@ -1320,7 +1322,15 @@ private CxScanConfig resolveConfiguration(Run<?, ?> run, DescriptorImpl descript |
1320 | 1322 | } else { |
1321 | 1323 | ret.setProxy(false); |
1322 | 1324 | } |
1323 | | - teamPath = getTeamNameFromId(cxConnectionDetails, descriptor, groupId); |
| 1325 | + |
| 1326 | + /* |
| 1327 | + * Pipeline script can provide grouoId or teamPath |
| 1328 | + * teamPath will take precedence if it is not empty. |
| 1329 | + * Freestyle job always send groupId, hence initializing teamPath using groupId |
| 1330 | + */ |
| 1331 | + if (!StringUtil.isNullOrEmpty(groupId) && StringUtil.isNullOrEmpty(teamPath)) { |
| 1332 | + teamPath = getTeamNameFromId(cxConnectionDetails, descriptor, groupId); |
| 1333 | + } |
1324 | 1334 | //project |
1325 | 1335 | ret.setProjectName(env.expand(projectName.trim())); |
1326 | 1336 | ret.setTeamPath(teamPath); |
@@ -1534,6 +1544,20 @@ private AstScaConfig getScaConfig(Run<?, ?> run, EnvVars env, DependencyScanConf |
1534 | 1544 | result.setTenant(dsConfig.scaTenant); |
1535 | 1545 | result.setTeamPath(dsConfig.scaTeamPath); |
1536 | 1546 | result.setIncludeSources(dsConfig.isIncludeSources); |
| 1547 | + |
| 1548 | + //add SCA Resolver code here |
| 1549 | + if (dsConfig.enableScaResolver != null |
| 1550 | + && SCAScanType.SCA_RESOLVER.toString().equalsIgnoreCase(dsConfig.enableScaResolver.toString())) { |
| 1551 | + scaResolverPathExist(dsConfig.pathToScaResolver); |
| 1552 | + validateScaResolverParams(dsConfig.scaResolverAddParameters); |
| 1553 | + result.setEnableScaResolver(true); |
| 1554 | + } |
| 1555 | + else |
| 1556 | + result.setEnableScaResolver(false); |
| 1557 | + |
| 1558 | + result.setPathToScaResolver(dsConfig.pathToScaResolver); |
| 1559 | + result.setScaResolverAddParameters(dsConfig.scaResolverAddParameters); |
| 1560 | + |
1537 | 1561 | UsernamePasswordCredentials credentials = CxConnectionDetails.getCredentialsById(dsConfig.scaCredentialsId, run); |
1538 | 1562 | if (credentials != null) { |
1539 | 1563 | result.setUsername(credentials.getUsername()); |
@@ -1908,6 +1932,50 @@ private boolean isSkipScan(final Run<?, ?> run) { |
1908 | 1932 | } |
1909 | 1933 | return allowedCauses.isEmpty(); |
1910 | 1934 | } |
| 1935 | + |
| 1936 | + private boolean scaResolverPathExist(String pathToResolver) { |
| 1937 | + pathToResolver = pathToResolver + File.separator + "ScaResolver"; |
| 1938 | + if(!SystemUtils.IS_OS_UNIX) |
| 1939 | + pathToResolver = pathToResolver + ".exe"; |
| 1940 | + |
| 1941 | + File file = new File(pathToResolver); |
| 1942 | + if(!file.exists()) |
| 1943 | + { |
| 1944 | + throw new CxClientException("SCA Resolver path does not exist. Path="+file.getAbsolutePath()); |
| 1945 | + } |
| 1946 | + return true; |
| 1947 | + } |
| 1948 | + |
| 1949 | + private void validateScaResolverParams(String additionalParams) { |
| 1950 | + |
| 1951 | + String[] arguments = additionalParams.split(" "); |
| 1952 | + Map<String, String> params = new HashMap<>(); |
| 1953 | + |
| 1954 | + for (int i = 0; i < arguments.length ; i++) { |
| 1955 | + if(arguments[i].startsWith("-") && (i+1 != arguments.length && !arguments[i+1].startsWith("-"))) |
| 1956 | + params.put(arguments[i], arguments[i+1]); |
| 1957 | + else |
| 1958 | + params.put(arguments[i], ""); |
| 1959 | + } |
| 1960 | + |
| 1961 | + String dirPath = params.get("-s"); |
| 1962 | + if(StringUtils.isEmpty(dirPath)) |
| 1963 | + throw new CxClientException("Source code path (-s <source code path>) is not provided."); |
| 1964 | + fileExists(dirPath); |
| 1965 | + |
| 1966 | + String projectName = params.get("-n"); |
| 1967 | + if(StringUtils.isEmpty(projectName)) |
| 1968 | + throw new CxClientException("Project name parameter (-n <project name>) must be provided to ScaResolver."); |
| 1969 | + |
| 1970 | + } |
| 1971 | + |
| 1972 | + private void fileExists(String file) { |
| 1973 | + |
| 1974 | + File resultPath = new File(file); |
| 1975 | + if (!resultPath.exists()) { |
| 1976 | + throw new CxClientException("Path does not exist. Path= " + resultPath.getAbsolutePath()); |
| 1977 | + } |
| 1978 | + } |
1911 | 1979 |
|
1912 | 1980 | /** |
1913 | 1981 | * Called when this plugin is initialized during Jenkins startup. Invoked by Jenkins using reflection. |
|
0 commit comments