-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ASA 9675] DAST rescan #176
Changes from 9 commits
ad059da
a674252
c8e7f04
6d3d3a8
0cdd2b4
c5ab042
2023526
74be3c8
8475892
c3e7318
5186b7a
b9471ed
c45a8a1
c7fa232
ad434e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,77 +223,141 @@ private static boolean hasEntitlement(String scanType, IAuthenticationProvider p | |
return false; | ||
} | ||
|
||
public static String updatedScanType(String type) { | ||
switch (type) { | ||
case "Static Analyzer": | ||
return STATIC_TECH; | ||
case "Dynamic Analyzer": | ||
return DYNAMIC_TECH; | ||
case CoreConstants.SOFTWARE_COMPOSITION_ANALYZER: | ||
return SCA_TECH; | ||
} | ||
return type; | ||
} | ||
|
||
/** | ||
* Checks if the given scanId is valid for scanning. | ||
* Update the scan data. | ||
* | ||
* @param scanId The scanId to test. | ||
* @param applicationId The applicationId to verify. | ||
* @param type The scanType to verify. | ||
* @param scanId The scanId of the scan whose configuration has to update. | ||
* @param params The map of properties which has to update . | ||
* @param provider The IAuthenticationProvider for authentication. | ||
* @return True if the scanId is valid. False is returned if the scanId is not valid, the request fails, or an exception occurs. | ||
* @param progress The IProgress for setting the status messages. | ||
*/ | ||
public static boolean isScanId(String scanId, String applicationId, String type, IAuthenticationProvider provider) { | ||
public static void updateScanData(Map<String, String> params, String scanId, IAuthenticationProvider provider, IProgress progress) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other comments, it's not clear why this is being added as a utility method, as opposed to the IScanServiceProvider that performs related functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will move it to the cloudScanServiceProvider class. |
||
if (provider.isTokenExpired()) { | ||
return true; | ||
return; | ||
} | ||
|
||
String request_url = provider.getServer() + API_BASIC_DETAILS; | ||
request_url += "?$filter=Id%20eq%20" + scanId + "&%24select=AppId%2C%20Technology"; | ||
String request_url = provider.getServer() + String.format(API_SCANNER,scanId); | ||
Map<String, String> request_headers = provider.getAuthorizationHeader(true); | ||
request_headers.put("accept", "application/json"); | ||
request_headers.put("Content-Type", "application/json"); | ||
|
||
HttpClient client = new HttpClient(provider.getProxy(), provider.getacceptInvalidCerts()); | ||
try { | ||
HttpResponse response = client.get(request_url, request_headers, null); | ||
|
||
if (response.isSuccess()) { | ||
JSONObject obj = (JSONObject) response.getResponseBodyAsJSON(); | ||
JSONArray array = (JSONArray) obj.get(ITEMS); | ||
if (array.isEmpty()) { | ||
return false; | ||
} else { | ||
JSONObject body = (JSONObject) array.getJSONObject(0); | ||
String appId = body.getString(CoreConstants.APP_ID); | ||
String technologyName = body.getString("Technology"); | ||
return appId.equals(applicationId) && technologyName.equals(updatedScanType(type)); | ||
} | ||
HttpResponse response = client.put(request_url, request_headers, params); | ||
if (response.getResponseCode() == HttpsURLConnection.HTTP_NO_CONTENT) { | ||
progress.setStatus(new Message(Message.INFO, Messages.getMessage(UPDATE_JOB))); | ||
} | ||
} catch (IOException | JSONException e) { | ||
// Ignore and return false. | ||
progress.setStatus(new Message(Message.ERROR, Messages.getMessage(ERROR_UPDATE_JOB, e.getLocalizedMessage()))); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static String updatedScanType(String type) { | ||
public static String scanTypeShortForm(String type) { | ||
switch (type) { | ||
case "Static Analyzer": | ||
return STATIC_TECH; | ||
return "Sast"; | ||
case "Dynamic Analyzer": | ||
return DYNAMIC_TECH; | ||
return "Dast"; | ||
case CoreConstants.SOFTWARE_COMPOSITION_ANALYZER: | ||
return SCA_TECH; | ||
return "Sca"; | ||
} | ||
return type; | ||
} | ||
|
||
public static void updateScanData(Map<String, String> params, String scanId, IAuthenticationProvider provider, IProgress progress) { | ||
/** | ||
* Fetch the detailed description of a scan. | ||
* | ||
* @param type The selected scan type | ||
* @param scanId The scanId to test | ||
* @param provider The IAuthenticationProvider for authentication. | ||
* @return JSONObject. | ||
*/ | ||
public static JSONObject getScanDetails(String type, String scanId, IAuthenticationProvider provider) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the need for the addition of this method here when we already have the CloudScanServiceProvider that does the same thing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is difference in the APIs. The method which is there in the CloudScanServiceProvider call the general API "GET /api/v4/Scans $filter=Id eq scanId" to fetch the scan details but new method of ServiceUtil calls the scan specific API "GET /api/v4/Sast/scanId ". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Matt, Should we move this new method into CloudScanServiceProvider class as it is perform related function? |
||
if (provider.isTokenExpired()) { | ||
return; | ||
return null; | ||
} | ||
|
||
String request_url = provider.getServer() + String.format(API_SCANNER,scanId); | ||
String request_url = provider.getServer() + String.format(API_SCANNER_DETAILS, scanTypeShortForm(type), scanId); | ||
Map<String, String> request_headers = provider.getAuthorizationHeader(true); | ||
request_headers.put("accept", "application/json"); | ||
request_headers.put("Content-Type", "application/json"); | ||
|
||
HttpClient client = new HttpClient(provider.getProxy(), provider.getacceptInvalidCerts()); | ||
try { | ||
HttpResponse response = client.put(request_url, request_headers, params); | ||
if (response.getResponseCode() == HttpsURLConnection.HTTP_NO_CONTENT) { | ||
progress.setStatus(new Message(Message.INFO, Messages.getMessage(UPDATE_JOB))); | ||
HttpResponse response = client.get(request_url, request_headers, null); | ||
|
||
if (response.isSuccess()) { | ||
return (JSONObject) response.getResponseBodyAsJSON(); | ||
} | ||
} catch (IOException | JSONException e) { | ||
progress.setStatus(new Message(Message.ERROR, Messages.getMessage(ERROR_UPDATE_JOB, e.getLocalizedMessage()))); | ||
// Ignore and return false. | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Fetch the details of all the executions of a scan. | ||
* | ||
* @param scanId The scanId to test | ||
* @param provider The IAuthenticationProvider for authentication. | ||
* @return JSONArray. | ||
*/ | ||
public static JSONArray getBaseScanDetails(String scanId, IAuthenticationProvider provider) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method would be better as a part of the IScanServiceProvider (i.e. CloudScanServiceProvider) as opposed to being added as a utility method here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will move it to the cloudScanServiceProvider class. |
||
if (provider.isTokenExpired()) { | ||
return null; | ||
} | ||
|
||
String request_url = provider.getServer() + String.format(API_EXECUTION_DETAILS, scanId); | ||
request_url += "?$filter=IsValidForIncremental%20eq%20true&%24select=Id%2C%20CreatedAt%2C%20IsValidForIncremental&%24orderby=CreatedAt%20desc"; | ||
Map<String, String> request_headers = provider.getAuthorizationHeader(true); | ||
request_headers.put("accept", "application/json"); | ||
request_headers.put("Content-Type", "application/json"); | ||
|
||
HttpClient client = new HttpClient(provider.getProxy(), provider.getacceptInvalidCerts()); | ||
try { | ||
HttpResponse response = client.get(request_url, request_headers, null); | ||
|
||
if (response.isSuccess()) { | ||
return (JSONArray) response.getResponseBodyAsJSON(); | ||
} | ||
} catch (IOException | JSONException e) { | ||
// Ignore and move on. | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Fetch the build version of the A360 server. | ||
* | ||
* @param provider The IAuthenticationProvider for authentication. | ||
* @return The build server of the server. | ||
*/ | ||
public static String getServiceVersion(IAuthenticationProvider provider) { | ||
String request_url = provider.getServer() + "/assets/versions.json"; | ||
HttpClient client = new HttpClient(provider.getProxy(), provider.getacceptInvalidCerts()); | ||
try { | ||
HttpResponse response = client.get(request_url, null, null); | ||
if (response.isSuccess()) { | ||
JSONObject body = (JSONObject) response.getResponseBodyAsJSON(); | ||
return body.getString("MainVersion"); | ||
} | ||
} catch (IOException | JSONException e) { | ||
return "0"; //$NON-NLS-1$ | ||
} | ||
return null; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason for the removal of this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is being made to include the ".git" folder when creating a zip archive of the parent folder from a Git repository.
Task detail: https://jira02.hclpnp.com/browse/ASA-9830