class InventoryUtil {

	public static Map<String,List<KMSKeyVH>> fetchKMSKeys(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) {

		Map<String,List<KMSKeyVH>> kmsKeys = new LinkedHashMap<>();
		AWSKMS awskms;
		String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"KMS\" , \"region\":\"" ;
		for(Region region : RegionUtils.getRegions()) {
			try{
				if(!skipRegions.contains(region.getName())){
					awskms = AWSKMSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
					List<KeyListEntry> regionKeys = awskms.listKeys().getKeys();
					List<AliasListEntry> regionKeyAliases = awskms.listAliases().getAliases();
					if(!regionKeys.isEmpty()) {
						List<KMSKeyVH> kmsKeysList = new ArrayList<>();
						for(KeyListEntry key : regionKeys) {
							KMSKeyVH kmsKey = new KMSKeyVH();
							try {
								DescribeKeyResult result = awskms.describeKey(new DescribeKeyRequest().withKeyId(key.getKeyId()));
								kmsKey.setKey(result.getKeyMetadata());
								kmsKey.setTags(awskms.listResourceTags(new ListResourceTagsRequest().withKeyId(key.getKeyId())).getTags());
							} catch (Exception e) {
								log.debug(e.getMessage());
							}
							try {
								kmsKey.setRotationStatus(awskms.getKeyRotationStatus(new GetKeyRotationStatusRequest().withKeyId(key.getKeyId())).getKeyRotationEnabled());
							} catch (Exception e) {
								log.debug(e.getMessage());
							}
							if(!regionKeyAliases.isEmpty() ) {
								for(AliasListEntry alias: regionKeyAliases) {
									if(key.getKeyId().equals(alias.getTargetKeyId())) {
										kmsKey.setAlias(alias);
										break;
									}
								}
							}
							kmsKeysList.add(kmsKey);
						}
						log.debug(InventoryConstants.ACCOUNT + accountId +" Type : KMSKey "+region.getName() + " >> "+kmsKeysList.size());
						kmsKeys.put(accountId+delimiter+accountName+delimiter+region.getName(),kmsKeysList);

					}
				}
			}catch(Exception e){
				log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
				ErrorManageUtil.uploadError(accountId,region.getName(),"kms",e.getMessage());
			}
		}
		return kmsKeys;
	}

	private  InventoryUtil();

}