tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private ResponseEntity<String> updateMetadataForRemoveGroupFromIAMSvcAcc(String token,
			IAMServiceAccountGroup iamServiceAccountGroup, UserDetails userDetails, OIDCGroup oidcGroup,
			List<String> currentpolicies, String currentpoliciesString) {
		String iamUniqueSvcAccountName = iamServiceAccountGroup.getAwsAccountId() + "_" + iamServiceAccountGroup.getIamSvcAccName();
		String path = new StringBuilder(IAMServiceAccountConstants.IAM_SVCC_ACC_PATH).append(iamUniqueSvcAccountName).toString();
		Map<String,String> params = new HashMap<>();
		params.put("type", "groups");
		params.put("name",iamServiceAccountGroup.getGroupname());
		params.put("path",path);
		params.put("access","delete");
		Response metadataResponse = ControllerUtil.updateMetadata(params,token);
		if(metadataResponse !=null && (HttpStatus.NO_CONTENT.equals(metadataResponse.getHttpstatus()) || HttpStatus.OK.equals(metadataResponse.getHttpstatus()))){
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
					put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
					put(LogMessage.ACTION, IAMServiceAccountConstants.REMOVE_GROUP_FROM_IAMSVCACC_MSG).
					put(LogMessage.MESSAGE, String.format("Group[%s] is successfully removed from IAM Service Account [%s].", iamServiceAccountGroup.getGroupname(),iamServiceAccountGroup.getIamSvcAccName())).
					put(LogMessage.STATUS, metadataResponse.getHttpstatus().toString()).
					put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
					build()));
			return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Group is successfully removed from IAM Service Account\"]}");
		}else {
			return revertGroupPermissionForIAMSvcAcc(token, iamServiceAccountGroup, userDetails, oidcGroup,
					currentpolicies, currentpoliciesString, metadataResponse);
		}
	}
/**
	 * Method to update metadata and revert group permission if metadata update failed.
	 *
	 * @param token
	 * @param iamServiceAccountGroup
	 * @param userDetails
	 * @param oidcGroup
	 * @param currentpolicies
	 * @param currentpoliciesString
	 * @return
	 */
Method to update metadata and revert group permission if metadata update failed.
Method to update metadata and revert group permission if metadata update failed .
private ResponseEntity<String> updateMetadataForRemoveGroupFromIAMSvcAcc(String token,
			IAMServiceAccountGroup iamServiceAccountGroup, UserDetails userDetails, OIDCGroup oidcGroup,
			List<String> currentpolicies, String currentpoliciesString) {
		String iamUniqueSvcAccountName = iamServiceAccountGroup.getAwsAccountId() + "_" + iamServiceAccountGroup.getIamSvcAccName();
		String path = new StringBuilder(IAMServiceAccountConstants.IAM_SVCC_ACC_PATH).append(iamUniqueSvcAccountName).toString();
		Map<String,String> params = new HashMap<>();
		params.put("type", "groups");
		params.put("name",iamServiceAccountGroup.getGroupname());
		params.put("path",path);
		params.put("access","delete");
		Response metadataResponse = ControllerUtil.updateMetadata(params,token);
		if(metadataResponse !=null && (HttpStatus.NO_CONTENT.equals(metadataResponse.getHttpstatus()) || HttpStatus.OK.equals(metadataResponse.getHttpstatus()))){
			log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
					put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
					put(LogMessage.ACTION, IAMServiceAccountConstants.REMOVE_GROUP_FROM_IAMSVCACC_MSG).
					put(LogMessage.MESSAGE, String.format("Group[%s] is successfully removed from IAM Service Account [%s].", iamServiceAccountGroup.getGroupname(),iamServiceAccountGroup.getIamSvcAccName())).
					put(LogMessage.STATUS, metadataResponse.getHttpstatus().toString()).
					put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
					build()));
			return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Group is successfully removed from IAM Service Account\"]}");
		}else {
			return revertGroupPermissionForIAMSvcAcc(token, iamServiceAccountGroup, userDetails, oidcGroup,
					currentpolicies, currentpoliciesString, metadataResponse);
		}
	}
private ResponseEntity < String > updateMetadataForRemoveGroupFromIAMSvcAcc ( String token , IAMServiceAccountGroup iamServiceAccountGroup , UserDetails userDetails , OIDCGroup oidcGroup , List < String > currentpolicies , String currentpoliciesString ) { String iamUniqueSvcAccountName = iamServiceAccountGroup . getAwsAccountId ( ) + "_" + iamServiceAccountGroup . getIamSvcAccName ( ) ; String path = new StringBuilder ( IAMServiceAccountConstants . IAM_SVCC_ACC_PATH ) . append ( iamUniqueSvcAccountName ) . toString ( ) ; Map < String , String > params = new HashMap < > ( ) ; params . put ( "type" , "groups" ) ; params . put ( "name" , iamServiceAccountGroup . getGroupname ( ) ) ; params . put ( "path" , path ) ; params . put ( "access" , "delete" ) ; Response metadataResponse = ControllerUtil . updateMetadata ( params , token ) ; if ( metadataResponse != null && ( HttpStatus . NO_CONTENT . equals ( metadataResponse . getHttpstatus ( ) ) || HttpStatus . OK . equals ( metadataResponse . getHttpstatus ( ) ) ) ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , IAMServiceAccountConstants . REMOVE_GROUP_FROM_IAMSVCACC_MSG ) . put ( LogMessage . MESSAGE , String . format ( "Group[%s] is successfully removed from IAM Service Account [%s]." , iamServiceAccountGroup . getGroupname ( ) , iamServiceAccountGroup . getIamSvcAccName ( ) ) ) . put ( LogMessage . STATUS , metadataResponse . getHttpstatus ( ) . toString ( ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . OK ) . body ( "{\"messages\":[\"Group is successfully removed from IAM Service Account\"]}" ) ; } else { return revertGroupPermissionForIAMSvcAcc ( token , iamServiceAccountGroup , userDetails , oidcGroup , currentpolicies , currentpoliciesString , metadataResponse ) ; } }
Method to update metadata and revert group permission if metadata update failed.
Method to update metadata and revert group permission if metadata update failed .