tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private ResponseEntity<String> addSudoPermissionToOwner(String token, IAMServiceAccount iamServiceAccount, UserDetails userDetails,
											 String iamSvcAccName) {
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
				.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
				.put(LogMessage.ACTION, IAMServiceAccountConstants.IAM_SVCACC_CREATION_TITLE)
				.put(LogMessage.MESSAGE, String.format("Trying to add sudo permission for the service account [%s] to " +
						"the user {%s]", iamSvcAccName, iamServiceAccount.getOwnerNtid()))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		IAMServiceAccountUser iamServiceAccountUser = new IAMServiceAccountUser(iamServiceAccount.getUserName(),
				iamServiceAccount.getOwnerNtid(), TVaultConstants.SUDO_POLICY, iamServiceAccount.getAwsAccountId());
		//Add sudo permisson to the IAM service account owner
		ResponseEntity<String> addUserToIAMSvcAccResponse = addUserToIAMServiceAccount(token, userDetails,
				iamServiceAccountUser, true);
		if (HttpStatus.OK.equals(addUserToIAMSvcAccResponse.getStatusCode())) {
			// Add default rotate permission to owner
			iamServiceAccountUser = new IAMServiceAccountUser(iamServiceAccount.getUserName(),
					iamServiceAccount.getOwnerNtid(), IAMServiceAccountConstants.IAM_WRITE_PERMISSION_STRING, iamServiceAccount.getAwsAccountId());
			ResponseEntity<String> addWritePermissionToIAMSvcAccResponse = addUserToIAMServiceAccount(token, userDetails,
					iamServiceAccountUser, true);
			if (HttpStatus.OK.equals(addWritePermissionToIAMSvcAccResponse.getStatusCode())) {
				log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
						.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
						.put(LogMessage.ACTION, IAMServiceAccountConstants.IAM_SVCACC_CREATION_TITLE)
						.put(LogMessage.MESSAGE, String.format("Successfully added owner permission to [%s] for IAM service " +
								ACCOUNTSTR, iamServiceAccount.getOwnerNtid(), iamSvcAccName))
						.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
				return addWritePermissionToIAMSvcAccResponse;
			}
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
					.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
					.put(LogMessage.ACTION, IAMServiceAccountConstants.IAM_SVCACC_CREATION_TITLE)
					.put(LogMessage.MESSAGE, String.format("Failed to add write permission to [%s] for IAM service " +
							"as part of onboarding" + ACCOUNTSTR, iamServiceAccount.getOwnerNtid(), iamSvcAccName))
					.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			return addWritePermissionToIAMSvcAccResponse;
		}
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
				.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
				.put(LogMessage.ACTION, IAMServiceAccountConstants.IAM_SVCACC_CREATION_TITLE)
				.put(LogMessage.MESSAGE, String.format("Failed to add owner permission to [%s] for IAM service " +
						ACCOUNTSTR, iamServiceAccount.getOwnerNtid(), iamSvcAccName))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		return addUserToIAMSvcAccResponse;
	}
/**
	 * Method to add Sudo permission to owner as part of IAM onboarding.
	 * @param token
	 * @param iamServiceAccount
	 * @param userDetails
	 * @param iamSvcAccName
	 * @return
	 */
Method to add Sudo permission to owner as part of IAM onboarding.
Method to add Sudo permission to owner as part of IAM onboarding .
private ResponseEntity<String> addSudoPermissionToOwner(String token, IAMServiceAccount iamServiceAccount, UserDetails userDetails,
											 String iamSvcAccName) {
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
				.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
				.put(LogMessage.ACTION, IAMServiceAccountConstants.IAM_SVCACC_CREATION_TITLE)
				.put(LogMessage.MESSAGE, String.format("Trying to add sudo permission for the service account [%s] to " +
						"the user {%s]", iamSvcAccName, iamServiceAccount.getOwnerNtid()))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		IAMServiceAccountUser iamServiceAccountUser = new IAMServiceAccountUser(iamServiceAccount.getUserName(),
				iamServiceAccount.getOwnerNtid(), TVaultConstants.SUDO_POLICY, iamServiceAccount.getAwsAccountId());
		ResponseEntity<String> addUserToIAMSvcAccResponse = addUserToIAMServiceAccount(token, userDetails,
				iamServiceAccountUser, true);
		if (HttpStatus.OK.equals(addUserToIAMSvcAccResponse.getStatusCode())) {
			iamServiceAccountUser = new IAMServiceAccountUser(iamServiceAccount.getUserName(),
					iamServiceAccount.getOwnerNtid(), IAMServiceAccountConstants.IAM_WRITE_PERMISSION_STRING, iamServiceAccount.getAwsAccountId());
			ResponseEntity<String> addWritePermissionToIAMSvcAccResponse = addUserToIAMServiceAccount(token, userDetails,
					iamServiceAccountUser, true);
			if (HttpStatus.OK.equals(addWritePermissionToIAMSvcAccResponse.getStatusCode())) {
				log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
						.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
						.put(LogMessage.ACTION, IAMServiceAccountConstants.IAM_SVCACC_CREATION_TITLE)
						.put(LogMessage.MESSAGE, String.format("Successfully added owner permission to [%s] for IAM service " +
								ACCOUNTSTR, iamServiceAccount.getOwnerNtid(), iamSvcAccName))
						.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
				return addWritePermissionToIAMSvcAccResponse;
			}
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
					.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
					.put(LogMessage.ACTION, IAMServiceAccountConstants.IAM_SVCACC_CREATION_TITLE)
					.put(LogMessage.MESSAGE, String.format("Failed to add write permission to [%s] for IAM service " +
							"as part of onboarding" + ACCOUNTSTR, iamServiceAccount.getOwnerNtid(), iamSvcAccName))
					.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
			return addWritePermissionToIAMSvcAccResponse;
		}
		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
				.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
				.put(LogMessage.ACTION, IAMServiceAccountConstants.IAM_SVCACC_CREATION_TITLE)
				.put(LogMessage.MESSAGE, String.format("Failed to add owner permission to [%s] for IAM service " +
						ACCOUNTSTR, iamServiceAccount.getOwnerNtid(), iamSvcAccName))
				.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
		return addUserToIAMSvcAccResponse;
	}
private ResponseEntity < String > addSudoPermissionToOwner ( String token , IAMServiceAccount iamServiceAccount , UserDetails userDetails , String iamSvcAccName ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . IAM_SVCACC_CREATION_TITLE ) . put ( LogMessage . MESSAGE , String . format ( "Trying to add sudo permission for the service account [%s] to " + "the user {%s]" , iamSvcAccName , iamServiceAccount . getOwnerNtid ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; IAMServiceAccountUser iamServiceAccountUser = new IAMServiceAccountUser ( iamServiceAccount . getUserName ( ) , iamServiceAccount . getOwnerNtid ( ) , TVaultConstants . SUDO_POLICY , iamServiceAccount . getAwsAccountId ( ) ) ; ResponseEntity < String > addUserToIAMSvcAccResponse = addUserToIAMServiceAccount ( token , userDetails , iamServiceAccountUser , true ) ; if ( HttpStatus . OK . equals ( addUserToIAMSvcAccResponse . getStatusCode ( ) ) ) { iamServiceAccountUser = new IAMServiceAccountUser ( iamServiceAccount . getUserName ( ) , iamServiceAccount . getOwnerNtid ( ) , IAMServiceAccountConstants . IAM_WRITE_PERMISSION_STRING , iamServiceAccount . getAwsAccountId ( ) ) ; ResponseEntity < String > addWritePermissionToIAMSvcAccResponse = addUserToIAMServiceAccount ( token , userDetails , iamServiceAccountUser , true ) ; if ( HttpStatus . OK . equals ( addWritePermissionToIAMSvcAccResponse . getStatusCode ( ) ) ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . IAM_SVCACC_CREATION_TITLE ) . put ( LogMessage . MESSAGE , String . format ( "Successfully added owner permission to [%s] for IAM service " + ACCOUNTSTR , iamServiceAccount . getOwnerNtid ( ) , iamSvcAccName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return addWritePermissionToIAMSvcAccResponse ; } log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . IAM_SVCACC_CREATION_TITLE ) . put ( LogMessage . MESSAGE , String . format ( "Failed to add write permission to [%s] for IAM service " + "as part of onboarding" + ACCOUNTSTR , iamServiceAccount . getOwnerNtid ( ) , iamSvcAccName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return addWritePermissionToIAMSvcAccResponse ; } log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . IAM_SVCACC_CREATION_TITLE ) . put ( LogMessage . MESSAGE , String . format ( "Failed to add owner permission to [%s] for IAM service " + ACCOUNTSTR , iamServiceAccount . getOwnerNtid ( ) , iamSvcAccName ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return addUserToIAMSvcAccResponse ; }
Method to add Sudo permission to owner as part of IAM onboarding.
Method to add Sudo permission to owner as part of IAM onboarding .
//Add sudo permisson to the IAM service account owner // Add default rotate permission to owner