Package com.rapid7.appspider
Class ApiSerializer
- java.lang.Object
-
- com.rapid7.appspider.ApiSerializer
-
public final class ApiSerializer extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ApiSerializercreateInstanceOrThrow(LoggerFacade logger)Optional<org.json.JSONObject>findByConfigName(org.json.JSONArray configs, String configName)returns the JSONObject for the item in configs with "Name" matching name if found; otherwise Optional.empty()Optional<Boolean>getBooleansFrom(org.json.JSONObject jsonObject, String... keys)returns true if all given keys in jsonObject are trueOptional<List<ClientIdNamePair>>getClientIdNamePairs(org.json.JSONArray clients)returns a list of ClientIdNamePair objects extracted from given JSONArrayOptional<List<String>>getConfigNames(org.json.JSONArray configs)returns List{String} of all scan config names found in configsbooleangetIsSuccess(org.json.JSONObject jsonObject)returns the value of "IsSuccess" from the provided jsonObject if non-null; otherwise, falsebooleangetResultIsSuccess(org.json.JSONObject jsonObject)returns the value of "IsSuccess" and "Result" from the provided jsonObject if non-null; otherwise, falseOptional<String>getScanConfigId(org.json.JSONObject config)StringgetScanConfigXml(freemarker.template.Template template, String name, URL targetURL)constructs scan config XML document using template with provided name and targetScanResultgetScanResult(org.json.JSONObject jsonObject)Optional<String>getStatus(org.json.JSONObject jsonObject)returns the value of "Status" from the provided jsonObject if non-null and Status is not empty; otherwiseOptional<String>getTokenOrEmpty(org.json.JSONObject jsonObject)if jsonObject contains "IsSuccess" with value of true then value of "Token" if non-empty is returned within an Optional; otherwise Optional.empty()
-
-
-
Method Detail
-
createInstanceOrThrow
public static ApiSerializer createInstanceOrThrow(LoggerFacade logger)
-
getTokenOrEmpty
public Optional<String> getTokenOrEmpty(org.json.JSONObject jsonObject)
if jsonObject contains "IsSuccess" with value of true then value of "Token" if non-empty is returned within an Optional; otherwise Optional.empty()- Parameters:
jsonObject- JSON object containing "IsSuccess" and "Token"- Returns:
- Optional containing "Token" if "IsSuccess" has value of true and Token is not empty; otherwise Optional.empty()
-
getIsSuccess
public boolean getIsSuccess(org.json.JSONObject jsonObject)
returns the value of "IsSuccess" from the provided jsonObject if non-null; otherwise, false- Parameters:
jsonObject- JSON object containing the "IsSuccess" value to extract- Returns:
- value of "IsSuccess" from the provided jsonObject if non-null; otherwise, false
-
getScanResult
public ScanResult getScanResult(org.json.JSONObject jsonObject)
-
getResultIsSuccess
public boolean getResultIsSuccess(org.json.JSONObject jsonObject)
returns the value of "IsSuccess" and "Result" from the provided jsonObject if non-null; otherwise, false- Parameters:
jsonObject- JSON object containing the "IsSuccess" value to extract- Returns:
- value of "IsSuccess" from the provided jsonObject if non-null; otherwise, false
-
getStatus
public Optional<String> getStatus(org.json.JSONObject jsonObject)
returns the value of "Status" from the provided jsonObject if non-null and Status is not empty; otherwise- Parameters:
jsonObject- JSON object containing "Status" key- Returns:
- Optional containing value of "Status" from jsonObject if not empty on success; otherwise, Optional.empty()
-
getConfigNames
public Optional<List<String>> getConfigNames(org.json.JSONArray configs)
returns List{String} of all scan config names found in configs- Parameters:
configs- JSONArray of scan config JSONObjects containing "Name" key- Returns:
- Optional containing List{String} which in turn contains all "Name" keys found in configs - if configs is non-null; Otherwise, Optional.empty()
-
getScanConfigXml
public String getScanConfigXml(freemarker.template.Template template, String name, URL targetURL) throws IOException, freemarker.template.TemplateException
constructs scan config XML document using template with provided name and target- Parameters:
template- template used to produce XMLname- name of the new scan configtargetURL- target of the scan config- Returns:
- String representing scan config in XML format
- Throws:
IOException- thrown if I/O error occurs during template processingfreemarker.template.TemplateException- if a problem occurs during template processingIllegalArgumentException- if any of the provided arguments are null, or in the case of Strings emptyMalformedURLException- if target is not a va
-
findByConfigName
public Optional<org.json.JSONObject> findByConfigName(org.json.JSONArray configs, String configName)
returns the JSONObject for the item in configs with "Name" matching name if found; otherwise Optional.empty()- Parameters:
configs- JSONArray to search throughconfigName- name of config to find- Returns:
- Optional containing the matching JSONObject on success; otherwise Optional.empty()
-
getBooleansFrom
public Optional<Boolean> getBooleansFrom(org.json.JSONObject jsonObject, String... keys)
returns true if all given keys in jsonObject are true- Parameters:
jsonObject- json object containing keyskeys- keys for the boolean fields of jsonObject- Returns:
- true if all keys are present and true
-
getClientIdNamePairs
public Optional<List<ClientIdNamePair>> getClientIdNamePairs(org.json.JSONArray clients)
returns a list of ClientIdNamePair objects extracted from given JSONArray- Parameters:
clients- JSONArray containing items with format { ClientId = String, ClientName = String }- Returns:
- on success list of ClientIdNamePairs extracted from clients; otherwise, Optional.empty()
-
-