class CheckForRDSSnapshotWithPublicAccess extends BaseRule {

    @Override
    public RuleResult execute(Map<String, String> ruleParam,
            Map<String, String> resourceAttributes) {

        logger.debug("========CheckForRDSSnapshotWithPublicAccess started=========");
        Annotation annotation = null;
        String resourceId = null;
        String region = null;
        String accountId = null;
        String checkId = StringUtils.trim(ruleParam
                .get(PacmanRuleConstants.CHECK_ID));

        String severity = ruleParam.get(PacmanRuleConstants.SEVERITY);
        String category = ruleParam.get(PacmanRuleConstants.CATEGORY);

        String serviceEsURL = null;
        
        String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_CHECK_SERVICE_SEARCH_URL_PARAM);
        
        if(!StringUtils.isEmpty(formattedUrl)){
            serviceEsURL =  formattedUrl;
        }

        MDC.put("executionId", ruleParam.get("executionId")); 
        MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); 

        List<LinkedHashMap<String, Object>> issueList = new ArrayList<>();
        LinkedHashMap<String, Object> issue = new LinkedHashMap<>();

        if (!PacmanUtils.doesAllHaveValue(checkId, severity, category,
                serviceEsURL)) {
            logger.info(PacmanRuleConstants.MISSING_CONFIGURATION);
            throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION);
        }

        if (resourceAttributes != null) {
            region = resourceAttributes.get(PacmanRuleConstants.REGION);
            accountId = resourceAttributes.get(PacmanSdkConstants.ACCOUNT_ID);
            resourceId = StringUtils.trim(resourceAttributes
                    .get("dbsnapshotarn"));
            Map<String, String> rdsSnapshotMap = new HashMap<>();
            try {
                rdsSnapshotMap = PacmanUtils.getRDSSnapshotWithCheckId(checkId,
                        resourceId, serviceEsURL, region, accountId);
            } catch (Exception e) {
                logger.error("unable to determine" , e);
                throw new RuleExecutionFailedExeption("unable to determine" + e);
            }
            if (!rdsSnapshotMap.isEmpty()) {
                annotation = Annotation.buildAnnotation(ruleParam,
                        Annotation.Type.ISSUE);
                annotation.put(PacmanSdkConstants.DESCRIPTION,
                        "Amazon RDS snapshot with public access found !!");
                annotation.put(PacmanRuleConstants.SEVERITY, severity);
                annotation.put(PacmanRuleConstants.CATEGORY, category);
                annotation.put("status", rdsSnapshotMap.get("status"));
                annotation.put("dbInstanceOrClusterId",
                        rdsSnapshotMap.get("dbInstanceOrClusterId"));

                issue.put(PacmanRuleConstants.VIOLATION_REASON,
                        "Amazon RDS snapshot with public access found");
                issue.put(PacmanRuleConstants.CHECKID, checkId);
                issue.put(PacmanRuleConstants.SOURCE_VERIFIED,
                        "trusted advisor");
                issueList.add(issue);

                annotation.put("issueDetails", issueList.toString());
                logger.debug("========CheckForRDSSnapshotWithPublicAccess ended with annotation {} :=========",annotation);
                return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,
                        PacmanRuleConstants.FAILURE_MESSAGE, annotation);
            }
        }
        logger.debug("========CheckForRDSSnapshotWithPublicAccess ended=========");
        return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,
                PacmanRuleConstants.SUCCESS_MESSAGE);
    }

}