Skip to content

Commit

Permalink
Fixed the Lock and Unlock method
Browse files Browse the repository at this point in the history
Change the call to the SAST scans to use the internal API.
Added the cxOrigin to the API.
  • Loading branch information
Pedro Portilha committed Feb 27, 2024
1 parent c35bb0d commit 987d924
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 45 deletions.
65 changes: 20 additions & 45 deletions Checkmarx.API/CxClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private HttpClient Login(string baseURL = "http://localhost/cxrestapi/",
// Ignore certificate for http client
if (ignoreCertificate)
{
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
}

httpClient = new HttpClient(httpClientHandler)
Expand Down Expand Up @@ -1819,35 +1819,14 @@ private void UploadSourceCode(long projectId, byte[] sourceCodeZipContent)

private long? triggerNewScan(long projectId, bool forceScan, bool runPublicScan, string comment)
{
using (var request = new HttpRequestMessage(HttpMethod.Post, "sast/scans"))
return SASTClient.SastScans_PostByscanAsync(new SastScanRequestWriteDTO
{
request.Headers.Add("Accept", "application/json;v=1.0");
request.Headers.Add("cxOrigin", "Checkmarx.API");

var requestBody = JsonConvert.SerializeObject(new ScanDetails
{
ProjectId = projectId,
Comment = comment ?? string.Empty,
ForceScan = forceScan,
IsIncremental = false,
IsPublic = runPublicScan
});

using (var stringContent = new StringContent(requestBody, Encoding.UTF8, "application/json"))
{
request.Content = stringContent;
HttpResponseMessage response = httpClient.SendAsync(request).Result;

if (response.StatusCode != HttpStatusCode.Created)
{
throw new ApplicationException(response.Content.ReadAsStringAsync().Result);
}

// Doesn't this come in the response??
var fetchScanId = response.Headers.Location.ToString().Split("/").Last();
return Convert.ToInt64(fetchScanId);
}
}
ProjectId = projectId,
Comment = comment ?? string.Empty,
ForceScan = forceScan,
IsIncremental = false,
IsPublic = runPublicScan
}).Result.Id;
}

private void checkSoapResponse(cxPortalWebService93.CxWSBasicRepsonse result)
Expand Down Expand Up @@ -1964,46 +1943,42 @@ public ICollection<Scan> GetSASTScanSummary(int projectId, string scanState = nu
}
}

public bool LockScan(long scanId, string comment = null)
public void LockScan(long scanId, string comment = null)
{
checkConnection();

bool sucess = true;

if (_isV9)
{
var response = _cxPortalWebServiceSoapClientV9.LockScanAsync(_soapSessionId, scanId).Result;

if (!string.IsNullOrWhiteSpace(comment))
_cxPortalWebServiceSoapClientV9.UpdateScanCommentAsync(_soapSessionId, scanId, comment);
checkSoapResponse(_cxPortalWebServiceSoapClientV9.UpdateScanCommentAsync(_soapSessionId, scanId, comment).Result);

sucess = response.IsSuccesfull;
checkSoapResponse(response);
}
else
{
_cxPortalWebServiceSoapClient.LockScanAsync(_soapSessionId, scanId).Wait();
}
var response = _cxPortalWebServiceSoapClient.LockScanAsync(_soapSessionId, scanId).Result;

return sucess;
if (!string.IsNullOrWhiteSpace(comment))
throw new NotImplementedException("Adding comment is not support for this version");

checkSoapResponse(response);
}
}

public bool UnlockScan(long scanId)
public void UnlockScan(long scanId)
{
checkConnection();

bool sucess = true;

if (_isV9)
{
var response = _cxPortalWebServiceSoapClientV9.UnlockScanAsync(_soapSessionId, scanId).Result;
sucess = response.IsSuccesfull;
checkSoapResponse(_cxPortalWebServiceSoapClientV9.UnlockScanAsync(_soapSessionId, scanId).Result);
}
else
{
_cxPortalWebServiceSoapClient.UnlockScanAsync(_soapSessionId, scanId).Wait();
checkSoapResponse(_cxPortalWebServiceSoapClient.UnlockScanAsync(_soapSessionId, scanId).REs);

Check failure on line 1980 in Checkmarx.API/CxClient.cs

View workflow job for this annotation

GitHub Actions / build, pack & publish

'Task<CxWSBasicRepsonse>' does not contain a definition for 'REs' and no accessible extension method 'REs' accepting a first argument of type 'Task<CxWSBasicRepsonse>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 1980 in Checkmarx.API/CxClient.cs

View workflow job for this annotation

GitHub Actions / build, pack & publish

'Task<CxWSBasicRepsonse>' does not contain a definition for 'REs' and no accessible extension method 'REs' accepting a first argument of type 'Task<CxWSBasicRepsonse>' could be found (are you missing a using directive or an assembly reference?)
}

return sucess;
}

public enum ScanRetrieveKind
Expand Down
2 changes: 2 additions & 0 deletions Checkmarx.API/SAST/SASTRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6404,6 +6404,8 @@ public virtual async System.Threading.Tasks.Task<LinkedResource> SastScans_PostB
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json;v=1.0"));

content_.Headers.Add("cxOrigin", "Checkmarx.API");

PrepareRequest(client_, request_, urlBuilder_);

var url_ = urlBuilder_.ToString();
Expand Down

0 comments on commit 987d924

Please sign in to comment.