-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added xsc api and receiving agent and not taking only default.
- Loading branch information
Showing
15 changed files
with
332 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/jfrog/xray/client/impl/xsc/XcsSystemClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.jfrog.xray.client.impl.xsc; | ||
|
||
import java.io.IOException; | ||
|
||
public class XcsSystemClient { | ||
private final String SYSTEM_ENDPOINT = "/system/version"; | ||
private final XscHttpClient httpClient; | ||
public XcsSystemClient(XscHttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
} | ||
|
||
public String getXscVersion() { | ||
try { | ||
String response = this.httpClient.get(SYSTEM_ENDPOINT).toString(); | ||
return this.httpClient.extractValueFromResponse(response, "xsc_version"); | ||
} | ||
catch(IOException e) { | ||
System.out.println(e.getMessage()); | ||
return ""; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/jfrog/xray/client/impl/xsc/XscClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.jfrog.xray.client.impl.xsc; | ||
import org.apache.http.client.AuthCache; | ||
import org.apache.http.impl.client.BasicCredentialsProvider; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
import org.jfrog.build.api.util.Log; | ||
|
||
public class XscClient { | ||
|
||
private XscHttpClient httpClient; | ||
private XcsSystemClient xscSystemClient; | ||
private XscEventClient xscEventClient; | ||
|
||
public XscClient(PoolingHttpClientConnectionManager connectionManager, BasicCredentialsProvider credentialsProvider, String accessToken, AuthCache authCache, HttpClientBuilder clientBuilder, int connectionRetries, Log log,String url) { | ||
this.httpClient = new XscHttpClient(connectionManager, credentialsProvider, accessToken, authCache, clientBuilder, connectionRetries, log, url); | ||
this.xscSystemClient = new XcsSystemClient(this.httpClient); | ||
this.xscEventClient = new XscEventClient(this.httpClient); | ||
} | ||
|
||
|
||
public XscEventClient scan(){ | ||
return this.xscEventClient; | ||
} | ||
|
||
public XcsSystemClient system(){ | ||
return this.xscSystemClient; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/jfrog/xray/client/impl/xsc/XscEventClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.jfrog.xray.client.impl.xsc; | ||
|
||
import com.jfrog.xray.client.impl.xsc.types.EndScanRequest; | ||
import com.jfrog.xray.client.impl.xsc.types.ScanRequest; | ||
|
||
public class XscEventClient { | ||
private final String EVENT_ENDPOINT = "/event"; | ||
private final XscHttpClient httpClient; | ||
|
||
public XscEventClient(XscHttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
} | ||
|
||
public String startScan(ScanRequest scanRequest){ | ||
try { | ||
String response = httpClient.post(EVENT_ENDPOINT, scanRequest).toString(); | ||
return httpClient.extractValueFromResponse(response, "multi_scan_id"); | ||
}catch (Exception e){ | ||
return ""; | ||
} | ||
} | ||
|
||
public void endScan(EndScanRequest scanRequest){ | ||
try { | ||
httpClient.put(EVENT_ENDPOINT, scanRequest); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/jfrog/xray/client/impl/xsc/XscHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.jfrog.xray.client.impl.xsc; | ||
import com.jfrog.xray.client.impl.XrayClient; | ||
import org.apache.http.client.AuthCache; | ||
import org.apache.http.impl.client.BasicCredentialsProvider; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
import org.jfrog.build.api.util.Log; | ||
|
||
|
||
public class XscHttpClient extends XrayClient { | ||
private static final String XSC_BASE_URL = "/xsc/api/v1"; | ||
|
||
|
||
public XscHttpClient(PoolingHttpClientConnectionManager connectionManager, BasicCredentialsProvider credentialsProvider, String accessToken, AuthCache authCache, HttpClientBuilder clientBuilder, int connectionRetries, Log log,String url) { | ||
super(connectionManager, credentialsProvider, accessToken, authCache, clientBuilder, connectionRetries, log, url+ XSC_BASE_URL ); | ||
} | ||
|
||
public String extractValueFromResponse(String json, String key) { | ||
String searchKey = "\"" + key + "\":\""; | ||
int startIndex = json.indexOf(searchKey); | ||
if (startIndex == -1) { | ||
return null; // Key not found | ||
} | ||
startIndex += searchKey.length(); | ||
int endIndex = json.indexOf("\"", startIndex); | ||
if (endIndex == -1) { | ||
return null; | ||
} | ||
return json.substring(startIndex, endIndex); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/jfrog/xray/client/impl/xsc/types/EndScanRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.jfrog.xray.client.impl.xsc.types; | ||
|
||
public class EndScanRequest extends ScanRequest { | ||
private Integer totalFindings; | ||
private Integer totalIgnoredFindings; | ||
private Integer totalScanDuration; // Changed to String | ||
private String multiScanId; | ||
|
||
public EndScanRequest( | ||
ScanEventType eventType, | ||
ScanEventStatus eventStatus, | ||
String product, | ||
String productVersion, | ||
String jpdVersion, | ||
String jfrogUser, | ||
String osPlatform, | ||
String osArchitecture, | ||
String machineId, | ||
String analyzerManagerVersion, | ||
Boolean isDefaultConfig, | ||
Integer totalFindings, | ||
Integer totalIgnoredFindings, | ||
Integer totalScanDuration, | ||
String multiScanId) { | ||
super(eventType, eventStatus, product, productVersion, jpdVersion, jfrogUser, osPlatform, osArchitecture, machineId, analyzerManagerVersion, isDefaultConfig); | ||
this.totalScanDuration = totalScanDuration; | ||
this.totalFindings = totalFindings; | ||
this.totalIgnoredFindings = totalIgnoredFindings; | ||
this.multiScanId = multiScanId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + | ||
"\"event_type\":" + this.eventType.getType() + "," + | ||
"\"event_status\":\"" + this.eventStatus.getStatus() + "\"," + | ||
"\"product\":\"" + this.product + "\"," + | ||
"\"product_version\":\"" + this.productVersion + "\"," + | ||
"\"jpd_version\":\"" + this.jpdVersion + "\"," + | ||
"\"jfrog_user\":\"" + this.jfrogUser + "\"," + | ||
"\"os_platform\":\"" + this.osPlatform + "\"," + | ||
"\"os_architecture\":\"" + this.osArchitecture + "\"," + | ||
"\"is_default_config\":" + this.isDefaultConfig + "," + | ||
"\"machine_id\":\"" + this.machineId + "\"," + | ||
"\"analyzer_manager_version\":\"" + this.analyzerManagerVersion + "\"," + | ||
"\"total_findings\":" + totalFindings + "," + | ||
"\"total_ignored_findings\":" + totalIgnoredFindings + "," + | ||
"\"total_scan_duration\":\"" + totalScanDuration + "\"," + | ||
"\"multi_scan_id\":\"" + multiScanId + "\"" + | ||
"}"; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/jfrog/xray/client/impl/xsc/types/ScanEventStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.jfrog.xray.client.impl.xsc.types; | ||
|
||
|
||
public enum ScanEventStatus { | ||
STARTED("started"), | ||
COMPLETED("completed"), | ||
CANCELLED("cancelled"), | ||
FAILED("failed"); | ||
|
||
private final String status; | ||
|
||
ScanEventStatus(String status) { | ||
this.status = status; | ||
} | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return status; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/jfrog/xray/client/impl/xsc/types/ScanEventType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.jfrog.xray.client.impl.xsc.types; | ||
|
||
|
||
public enum ScanEventType { | ||
SOURCE_CODE(1); | ||
|
||
private final int type; | ||
|
||
ScanEventType(int type) { | ||
this.type = type; | ||
} | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Integer.toString(type); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/jfrog/xray/client/impl/xsc/types/ScanRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.jfrog.xray.client.impl.xsc.types; | ||
|
||
|
||
|
||
public class ScanRequest { | ||
|
||
protected ScanEventType eventType; | ||
protected ScanEventStatus eventStatus; | ||
protected String product; | ||
protected String productVersion; | ||
protected String jpdVersion; | ||
protected String jfrogUser; | ||
protected String osPlatform; | ||
protected String osArchitecture; | ||
protected String machineId; | ||
protected String analyzerManagerVersion; | ||
protected Boolean isDefaultConfig; | ||
|
||
|
||
public ScanRequest(ScanEventType eventType, ScanEventStatus eventStatus, String product, | ||
String productVersion, String jpdVersion, String jfrogUser, | ||
String osPlatform, String osArchitecture, String machineId, | ||
String analyzerManagerVersion, Boolean isDefaultConfig) { | ||
this.eventType = eventType; | ||
this.eventStatus = eventStatus; | ||
this.product = product; | ||
this.productVersion = productVersion; | ||
this.jpdVersion = jpdVersion; | ||
this.jfrogUser = jfrogUser; | ||
this.osPlatform = osPlatform; | ||
this.osArchitecture = osArchitecture; | ||
this.machineId = machineId; | ||
this.analyzerManagerVersion = analyzerManagerVersion; | ||
this.isDefaultConfig = isDefaultConfig; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "{" + | ||
"\"event_type\":" + this.eventType.getType() + "," + | ||
"\"event_status\":\"" + this.eventStatus.getStatus() + "\"," + | ||
"\"product\":\"" + this.product + "\"," + | ||
"\"product_version\":\"" + this.productVersion + "\"," + | ||
"\"jpd_version\":\"" + this.jpdVersion + "\"," + | ||
"\"jfrog_user\":\"" + this.jfrogUser + "\"," + | ||
"\"os_platform\":\"" + this.osPlatform + "\"," + | ||
"\"os_architecture\":\"" + this.osArchitecture + "\"," + | ||
"\"is_default_config\":" + this.isDefaultConfig + "," + | ||
"\"machine_id\":\"" + this.machineId + "\"," + | ||
"\"analyzer_manager_version\":\"" + this.analyzerManagerVersion + "\"" + | ||
"}"; | ||
} | ||
} |
Oops, something went wrong.