tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private boolean deleteIAMSvcAccountSecretFolders(String token, String awsAccountId, String iamSvcAccName) {

		String uniqueSvcAccName = awsAccountId + "_" + iamSvcAccName;
		JsonObject iamMetadataJson = getIAMMetadata(token, uniqueSvcAccName);

		if (null!= iamMetadataJson && iamMetadataJson.has("secret")) {
			if (!iamMetadataJson.get("secret").isJsonNull()) {
				log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
						put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
						put(LogMessage.ACTION, "deleteIAMSvcAccountSecretFolders").
						put(LogMessage.MESSAGE, String.format("Trying to delete secret folders for the IAM Service " +
								"account [%s]", uniqueSvcAccName)).
						put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
						build()));

				JsonArray svcSecretArray = null;
				try {
					svcSecretArray = iamMetadataJson.get("secret").getAsJsonArray();
				} catch (IllegalStateException e) {
					log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
							put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
							put(LogMessage.ACTION, "deleteIAMSvcAccountSecretFolders").
							put(LogMessage.MESSAGE, String.format("Failed to get secret folders. Invalid metadata " +
									"for [%s].", uniqueSvcAccName)).
							put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
							build()));
					return false;
				}

				// To handle deleting all secret (if more than 2 secrets)/ at least 2 secrets folders on offboard
				int secretCount = svcSecretArray.size();
				if (secretCount < 2) {
					secretCount = 2;
				}
				if (null != svcSecretArray) {
					int deleteCount = 0;
					for (int i = 0; i < secretCount; i++) {
						String folderPath = IAMServiceAccountConstants.IAM_SVCC_ACC_PATH + uniqueSvcAccName + "/secret_" + (i+1);
						Response deleteFolderResponse = reqProcessor.process(DELETEPATH,
								PATHSTR + folderPath + "\"}", token);
						if (deleteFolderResponse.getHttpstatus().equals(HttpStatus.NO_CONTENT)
								|| deleteFolderResponse.getHttpstatus().equals(HttpStatus.OK)) {
							log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
									put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
									put(LogMessage.ACTION, "deleteIAMSvcAccountSecretFolders").
									put(LogMessage.MESSAGE, String.format("Deleted secret folder [%d] for the IAM Service " +
											"account [%s]", (i+1), uniqueSvcAccName)).
									put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
									build()));
							deleteCount++;
						}
					}
					if (deleteCount == secretCount) {
						return true;
					}
					else {
						return false;
					}
				}
			}
		}
		return true;
	}
/**
	 * To delete IAM secret folders as part of Offboarding.
	 * @param token
	 * @param awsAccountId
	 * @param iamSvcAccName
	 * @return
	 */
To delete IAM secret folders as part of Offboarding.
To delete IAM secret folders as part of Offboarding .
private boolean deleteIAMSvcAccountSecretFolders(String token, String awsAccountId, String iamSvcAccName) {
		String uniqueSvcAccName = awsAccountId + "_" + iamSvcAccName;
		JsonObject iamMetadataJson = getIAMMetadata(token, uniqueSvcAccName);
		if (null!= iamMetadataJson && iamMetadataJson.has("secret")) {
			if (!iamMetadataJson.get("secret").isJsonNull()) {
				log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
						put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
						put(LogMessage.ACTION, "deleteIAMSvcAccountSecretFolders").
						put(LogMessage.MESSAGE, String.format("Trying to delete secret folders for the IAM Service " +
								"account [%s]", uniqueSvcAccName)).
						put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
						build()));
				JsonArray svcSecretArray = null;
				try {
					svcSecretArray = iamMetadataJson.get("secret").getAsJsonArray();
				} catch (IllegalStateException e) {
					log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
							put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
							put(LogMessage.ACTION, "deleteIAMSvcAccountSecretFolders").
							put(LogMessage.MESSAGE, String.format("Failed to get secret folders. Invalid metadata " +
									"for [%s].", uniqueSvcAccName)).
							put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
							build()));
					return false;
				}
				int secretCount = svcSecretArray.size();
				if (secretCount < 2) {
					secretCount = 2;
				}
				if (null != svcSecretArray) {
					int deleteCount = 0;
					for (int i = 0; i < secretCount; i++) {
						String folderPath = IAMServiceAccountConstants.IAM_SVCC_ACC_PATH + uniqueSvcAccName + "/secret_" + (i+1);
						Response deleteFolderResponse = reqProcessor.process(DELETEPATH,
								PATHSTR + folderPath + "\"}", token);
						if (deleteFolderResponse.getHttpstatus().equals(HttpStatus.NO_CONTENT)
								|| deleteFolderResponse.getHttpstatus().equals(HttpStatus.OK)) {
							log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
									put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
									put(LogMessage.ACTION, "deleteIAMSvcAccountSecretFolders").
									put(LogMessage.MESSAGE, String.format("Deleted secret folder [%d] for the IAM Service " +
											"account [%s]", (i+1), uniqueSvcAccName)).
									put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
									build()));
							deleteCount++;
						}
					}
					if (deleteCount == secretCount) {
						return true;
					}
					else {
						return false;
					}
				}
			}
		}
		return true;
	}
private boolean deleteIAMSvcAccountSecretFolders ( String token , String awsAccountId , String iamSvcAccName ) { String uniqueSvcAccName = awsAccountId + "_" + iamSvcAccName ; JsonObject iamMetadataJson = getIAMMetadata ( token , uniqueSvcAccName ) ; if ( null != iamMetadataJson && iamMetadataJson . has ( "secret" ) ) { if ( ! iamMetadataJson . get ( "secret" ) . isJsonNull ( ) ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "deleteIAMSvcAccountSecretFolders" ) . put ( LogMessage . MESSAGE , String . format ( "Trying to delete secret folders for the IAM Service " + "account [%s]" , uniqueSvcAccName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; JsonArray svcSecretArray = null ; try { svcSecretArray = iamMetadataJson . get ( "secret" ) . getAsJsonArray ( ) ; } catch ( IllegalStateException e ) { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "deleteIAMSvcAccountSecretFolders" ) . put ( LogMessage . MESSAGE , String . format ( "Failed to get secret folders. Invalid metadata " + "for [%s]." , uniqueSvcAccName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return false ; } int secretCount = svcSecretArray . size ( ) ; if ( secretCount < 2 ) { secretCount = 2 ; } if ( null != svcSecretArray ) { int deleteCount = 0 ; for ( int i = 0 ; i < secretCount ; i ++ ) { String folderPath = IAMServiceAccountConstants . IAM_SVCC_ACC_PATH + uniqueSvcAccName + "/secret_" + ( i + 1 ) ; Response deleteFolderResponse = reqProcessor . process ( DELETEPATH , PATHSTR + folderPath + "\"}" , token ) ; if ( deleteFolderResponse . getHttpstatus ( ) . equals ( HttpStatus . NO_CONTENT ) || deleteFolderResponse . getHttpstatus ( ) . equals ( HttpStatus . OK ) ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "deleteIAMSvcAccountSecretFolders" ) . put ( LogMessage . MESSAGE , String . format ( "Deleted secret folder [%d] for the IAM Service " + "account [%s]" , ( i + 1 ) , uniqueSvcAccName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; deleteCount ++ ; } } if ( deleteCount == secretCount ) { return true ; } else { return false ; } } } } return true ; }
To delete IAM secret folders as part of Offboarding.
To delete IAM secret folders as part of Offboarding .
// To handle deleting all secret (if more than 2 secrets)/ at least 2 secrets folders on offboard