class CheckIamPasswordPolicyRule extends BaseRule {

	@Override
	public RuleResult execute(Map<String, String> ruleParam,Map<String, String> resourceAttributes) {
		logger.debug("========CheckIamPasswordPolicyRule started=========");
		Map<String, String> temp = new HashMap<>();
		temp.putAll(ruleParam);
		temp.put("region", "us-west-2");

		Map<String, Object> map = null;
		Annotation annotation = null;
		AmazonIdentityManagementClient iamClient = null;
		String roleIdentifyingString = ruleParam.get(PacmanSdkConstants.Role_IDENTIFYING_STRING);
		
		logger.info(resourceAttributes.get("accountid"));
		logger.info(resourceAttributes.get("accountname"));

		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(severity, category)) {
			logger.info(PacmanRuleConstants.MISSING_CONFIGURATION);
			throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION);
		}

		try {
			map = getClientFor(AWSService.IAM, roleIdentifyingString, temp);
			iamClient = (AmazonIdentityManagementClient) map.get(PacmanSdkConstants.CLIENT);
		} catch (UnableToCreateClientException e) {
			logger.error("unable to get client for following input", e);
			throw new InvalidInputException(e.toString());
		}

		GetAccountPasswordPolicyResult result = iamClient.getAccountPasswordPolicy();
		PasswordPolicy passwordPolicy = result.getPasswordPolicy();

		if (null != passwordPolicy) {
			if (!isPasswordPolicyCompliant(passwordPolicy, ruleParam)) {

				logger.warn("Password Policy not compliant");
				annotation = Annotation.buildAnnotation(ruleParam,Annotation.Type.ISSUE);
				annotation.put(PacmanSdkConstants.DESCRIPTION,policyIssues.toString().trim());
				annotation.put(PacmanRuleConstants.SEVERITY, severity);
				annotation.put(PacmanRuleConstants.CATEGORY, category);
				
				issue.put(PacmanRuleConstants.VIOLATION_REASON, policyIssues.toString().trim());
				issueList.add(issue);
				annotation.put("issueDetails",issueList.toString());
				logger.debug("========CheckIamPasswordPolicyRule ended with an annotation {} :=========",annotation); 
				return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, annotation);

			} else {
				logger.info("Password policy ok");
			}
		} else {
			logger.warn("No password policy defined for the account");
		}
		logger.debug("========CheckIamPasswordPolicyRule ended=========");
		return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE);
	}

}