class SSLCertificateExpiryRule extends BaseRule {

	public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) {
		logger.debug("========SSLCertificateExpiryRule started=========");
		Annotation annotation = null;
		String validTo = null;
		long expiredDuration;
		long targetExpiredDuration;
		String targetExpiryDurationInString = ruleParam.get(PacmanRuleConstants.EXPIRED_DURATION);
		
		String severity = ruleParam.get(PacmanRuleConstants.SEVERITY);
		String category = ruleParam.get(PacmanRuleConstants.CATEGORY);
		
		MDC.put("executionId", ruleParam.get("executionId")); // this is the logback Mapped Diagnostic Contex
		MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); // this is the logback Mapped Diagnostic Contex
		
		List<LinkedHashMap<String,Object>>issueList = new ArrayList<>();
		LinkedHashMap<String,Object>issue = new LinkedHashMap<>();

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

		if (resourceAttributes != null) {
			validTo = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.VALID_TO));

			expiredDuration = calculateSslExpiredDuration(validTo);
			targetExpiredDuration = Long.parseLong(targetExpiryDurationInString);
			if (expiredDuration > 0) {
				if (expiredDuration <= targetExpiredDuration) {
					annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE);
					annotation.put(PacmanSdkConstants.DESCRIPTION,"SSL Expiry within "+ targetExpiryDurationInString+ " days found!!");
					annotation.put(PacmanRuleConstants.SEVERITY, severity);
					annotation.put(PacmanRuleConstants.CATEGORY, category);
					
					issue.put(PacmanRuleConstants.VIOLATION_REASON, "SSL Expiry within "+ targetExpiryDurationInString+ " days found!!");
					issueList.add(issue);
					annotation.put("issueDetails",issueList.toString());
					logger.debug("========SSLCertificateExpiryRule ended with annotation {} : =========",annotation);
					return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation);
				}
			} else {
				logger.info("Elb with SSL validity not expired");
			}
		}
		logger.debug("========SSLCertificateExpiryRule ended=========");
		return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE);
	}

}