@Test public void testFetchRuleComplianceInfo() throws Exception { String ruleComplianceJson = "{\"data\":{\"response\":[{\"severity\":\"low\",\"name\":\"EBS snapshots should be tagged with mandatory tags \",\"compliance_percent\":50,\"lastScan\":\"2018-08-01T18:00:50.263Z\",\"ruleCategory\":\"tagging\",\"resourcetType\":\"snapshot\",\"ruleId\":\"PacMan_TaggingRule_version-1_SnapshotTaggingRule_snapshot\",\"assetsScanned\":55085,\"passed\":27619,\"failed\":27466,\"contribution_percent\":100},{\"severity\":\"low\",\"name\":\"Security groups should be tagged with mandatory tags\",\"compliance_percent\":18,\"lastScan\":\"2018-08-01T23:00:47.392Z\",\"ruleCategory\":\"tagging\",\"resourcetType\":\"sg\",\"ruleId\":\"PacMan_TaggingRule_version-1_SgTaggingRule_sg\",\"assetsScanned\":7129,\"passed\":1297,\"failed\":5832,\"contribution_percent\":100},{\"severity\":\"high\",\"name\":\"Amazon EBS volumes should not be underutilized \",\"compliance_percent\":84,\"lastScan\":\"2018-08-01T18:04:23.044Z\",\"ruleCategory\":\"costOptimization\",\"resourcetType\":\"volume\",\"ruleId\":\"PacMan_Underutilized-Amazon-EBS-Volumes_version-1_Underutilized-EBS-Volumes_volume\",\"assetsScanned\":35938,\"passed\":30191,\"failed\":5747,\"contribution_percent\":100},{\"severity\":\"low\",\"name\":\"EBS volumes should be tagged with mandatory tags \",\"compliance_percent\":84,\"lastScan\":\"2018-08-01T23:00:55.626Z\",\"ruleCategory\":\"tagging\",\"resourcetType\":\"volume\",\"ruleId\":\"PacMan_TaggingRule_version-1_VolumeTaggingRule_volume\",\"assetsScanned\":35938,\"passed\":30227,\"failed\":5711,\"contribution_percent\":100},{\"severity\":\"low\",\"name\":\"Any Ec2 instance should not have S3 vulnerability \",\"compliance_percent\":30,\"lastScan\":\"2018-08-01T18:00:26.570Z\",\"ruleCategory\":\"security\",\"resourcetType\":\"ec2\",\"ruleId\":\"PacMan_Ec2WithSeverityVulnerability_version-1_Ec2WithS3Vulnerability_ec2\",\"assetsScanned\":7192,\"passed\":2172,\"failed\":5020,\"contribution_percent\":100}]}}"; when(HttpUtil.post(anyString(),anyString(),anyString(),anyString())).thenReturn(ruleComplianceJson); List<Map<String, Object>> complianceInfo = AssetGroupUtil.fetchRuleComplianceInfo("", "", Arrays.asList("infra"),""); assertThat(complianceInfo.size(), is(5)); assertThat(complianceInfo.get(0).get("domain").toString(), is("infra")); assertThat(complianceInfo.get(0).get("ruleId").toString(), is("PacMan_TaggingRule_version-1_SnapshotTaggingRule_snapshot")); }
public static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> ruleInfoList = new ArrayList<>(); try { for (String domain : domains) { String ruleCommplianceInfo = HttpUtil.post(compapiuri + "/noncompliancepolicy", "{\"ag\":\"" + ag + "\",\"filter\":{\"domain\":\"" + domain + "\"}}",token,"Bearer"); JsonObject response = new JsonParser().parse(ruleCommplianceInfo).getAsJsonObject(); JsonArray ruleInfoListJson = response.get("data").getAsJsonObject().get("response").getAsJsonArray(); JsonObject ruleinfoJson; Map<String, Object> ruleInfo; for (JsonElement _ruleinfo : ruleInfoListJson) { ruleinfoJson = _ruleinfo.getAsJsonObject(); ruleInfo = new HashMap<>(); ruleInfo.put(DOMAIN, domain); ruleInfo.put("ruleId", ruleinfoJson.get("ruleId").getAsString()); ruleInfo.put("compliance_percent", ruleinfoJson.get("compliance_percent").getAsDouble()); ruleInfo.put(TOTAL, ruleinfoJson.get("assetsScanned").getAsLong()); ruleInfo.put(COMPLIANT, ruleinfoJson.get("passed").getAsLong()); ruleInfo.put(NON_COMPLIANT, ruleinfoJson.get("failed").getAsLong()); ruleInfo.put("contribution_percent", ruleinfoJson.get("contribution_percent").getAsDouble()); ruleInfoList.add(ruleInfo); } } } catch (Exception e) { LOGGER.error("Error retrieving Rule Compliance Info" , e); throw e; } return ruleInfoList; }
AssetGroupUtil { public static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> ruleInfoList = new ArrayList<>(); try { for (String domain : domains) { String ruleCommplianceInfo = HttpUtil.post(compapiuri + "/noncompliancepolicy", "{\"ag\":\"" + ag + "\",\"filter\":{\"domain\":\"" + domain + "\"}}",token,"Bearer"); JsonObject response = new JsonParser().parse(ruleCommplianceInfo).getAsJsonObject(); JsonArray ruleInfoListJson = response.get("data").getAsJsonObject().get("response").getAsJsonArray(); JsonObject ruleinfoJson; Map<String, Object> ruleInfo; for (JsonElement _ruleinfo : ruleInfoListJson) { ruleinfoJson = _ruleinfo.getAsJsonObject(); ruleInfo = new HashMap<>(); ruleInfo.put(DOMAIN, domain); ruleInfo.put("ruleId", ruleinfoJson.get("ruleId").getAsString()); ruleInfo.put("compliance_percent", ruleinfoJson.get("compliance_percent").getAsDouble()); ruleInfo.put(TOTAL, ruleinfoJson.get("assetsScanned").getAsLong()); ruleInfo.put(COMPLIANT, ruleinfoJson.get("passed").getAsLong()); ruleInfo.put(NON_COMPLIANT, ruleinfoJson.get("failed").getAsLong()); ruleInfo.put("contribution_percent", ruleinfoJson.get("contribution_percent").getAsDouble()); ruleInfoList.add(ruleInfo); } } } catch (Exception e) { LOGGER.error("Error retrieving Rule Compliance Info" , e); throw e; } return ruleInfoList; } }
AssetGroupUtil { public static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> ruleInfoList = new ArrayList<>(); try { for (String domain : domains) { String ruleCommplianceInfo = HttpUtil.post(compapiuri + "/noncompliancepolicy", "{\"ag\":\"" + ag + "\",\"filter\":{\"domain\":\"" + domain + "\"}}",token,"Bearer"); JsonObject response = new JsonParser().parse(ruleCommplianceInfo).getAsJsonObject(); JsonArray ruleInfoListJson = response.get("data").getAsJsonObject().get("response").getAsJsonArray(); JsonObject ruleinfoJson; Map<String, Object> ruleInfo; for (JsonElement _ruleinfo : ruleInfoListJson) { ruleinfoJson = _ruleinfo.getAsJsonObject(); ruleInfo = new HashMap<>(); ruleInfo.put(DOMAIN, domain); ruleInfo.put("ruleId", ruleinfoJson.get("ruleId").getAsString()); ruleInfo.put("compliance_percent", ruleinfoJson.get("compliance_percent").getAsDouble()); ruleInfo.put(TOTAL, ruleinfoJson.get("assetsScanned").getAsLong()); ruleInfo.put(COMPLIANT, ruleinfoJson.get("passed").getAsLong()); ruleInfo.put(NON_COMPLIANT, ruleinfoJson.get("failed").getAsLong()); ruleInfo.put("contribution_percent", ruleinfoJson.get("contribution_percent").getAsDouble()); ruleInfoList.add(ruleInfo); } } } catch (Exception e) { LOGGER.error("Error retrieving Rule Compliance Info" , e); throw e; } return ruleInfoList; } private  AssetGroupUtil(); }
AssetGroupUtil { public static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> ruleInfoList = new ArrayList<>(); try { for (String domain : domains) { String ruleCommplianceInfo = HttpUtil.post(compapiuri + "/noncompliancepolicy", "{\"ag\":\"" + ag + "\",\"filter\":{\"domain\":\"" + domain + "\"}}",token,"Bearer"); JsonObject response = new JsonParser().parse(ruleCommplianceInfo).getAsJsonObject(); JsonArray ruleInfoListJson = response.get("data").getAsJsonObject().get("response").getAsJsonArray(); JsonObject ruleinfoJson; Map<String, Object> ruleInfo; for (JsonElement _ruleinfo : ruleInfoListJson) { ruleinfoJson = _ruleinfo.getAsJsonObject(); ruleInfo = new HashMap<>(); ruleInfo.put(DOMAIN, domain); ruleInfo.put("ruleId", ruleinfoJson.get("ruleId").getAsString()); ruleInfo.put("compliance_percent", ruleinfoJson.get("compliance_percent").getAsDouble()); ruleInfo.put(TOTAL, ruleinfoJson.get("assetsScanned").getAsLong()); ruleInfo.put(COMPLIANT, ruleinfoJson.get("passed").getAsLong()); ruleInfo.put(NON_COMPLIANT, ruleinfoJson.get("failed").getAsLong()); ruleInfo.put("contribution_percent", ruleinfoJson.get("contribution_percent").getAsDouble()); ruleInfoList.add(ruleInfo); } } } catch (Exception e) { LOGGER.error("Error retrieving Rule Compliance Info" , e); throw e; } return ruleInfoList; } private  AssetGroupUtil(); @SuppressWarnings("unchecked") static Map<String, List<String>> fetchAssetGroups(String asstApiUri,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchTypeCounts(String asstApiUri, String ag,String token); static Map<String, Object> fetchPatchingCompliance(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchComplianceInfo(String apiUrl, String ag, List<String> domains ,String token); static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag,
            List<String> domains ,String token); static Map<String, Object> fetchVulnSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchTaggingSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchCertSummary(String compapiuri, String ag ,String token); static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token); }
AssetGroupUtil { public static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag, List<String> domains ,String token) throws Exception { List<Map<String, Object>> ruleInfoList = new ArrayList<>(); try { for (String domain : domains) { String ruleCommplianceInfo = HttpUtil.post(compapiuri + "/noncompliancepolicy", "{\"ag\":\"" + ag + "\",\"filter\":{\"domain\":\"" + domain + "\"}}",token,"Bearer"); JsonObject response = new JsonParser().parse(ruleCommplianceInfo).getAsJsonObject(); JsonArray ruleInfoListJson = response.get("data").getAsJsonObject().get("response").getAsJsonArray(); JsonObject ruleinfoJson; Map<String, Object> ruleInfo; for (JsonElement _ruleinfo : ruleInfoListJson) { ruleinfoJson = _ruleinfo.getAsJsonObject(); ruleInfo = new HashMap<>(); ruleInfo.put(DOMAIN, domain); ruleInfo.put("ruleId", ruleinfoJson.get("ruleId").getAsString()); ruleInfo.put("compliance_percent", ruleinfoJson.get("compliance_percent").getAsDouble()); ruleInfo.put(TOTAL, ruleinfoJson.get("assetsScanned").getAsLong()); ruleInfo.put(COMPLIANT, ruleinfoJson.get("passed").getAsLong()); ruleInfo.put(NON_COMPLIANT, ruleinfoJson.get("failed").getAsLong()); ruleInfo.put("contribution_percent", ruleinfoJson.get("contribution_percent").getAsDouble()); ruleInfoList.add(ruleInfo); } } } catch (Exception e) { LOGGER.error("Error retrieving Rule Compliance Info" , e); throw e; } return ruleInfoList; } private  AssetGroupUtil(); @SuppressWarnings("unchecked") static Map<String, List<String>> fetchAssetGroups(String asstApiUri,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchTypeCounts(String asstApiUri, String ag,String token); static Map<String, Object> fetchPatchingCompliance(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchComplianceInfo(String apiUrl, String ag, List<String> domains ,String token); static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag,
            List<String> domains ,String token); static Map<String, Object> fetchVulnSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchTaggingSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchCertSummary(String compapiuri, String ag ,String token); static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token);  }