tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/IAMServiceAccountsService.java
private boolean rotateIAMServiceAccountByAccessKeyId(String token, String awsAccountId, String iamServiceAccountName, String accessKeyId, int accessKeyIndex, UserDetails userDetails) {
		String uniqueIAMSvcaccName = awsAccountId + "_" + iamServiceAccountName;
		IAMServiceAccountRotateRequest iamServiceAccountRotateRequest = new IAMServiceAccountRotateRequest(accessKeyId, iamServiceAccountName, awsAccountId);

		IAMServiceAccountSecret iamServiceAccountSecret = iamServiceAccountUtils.rotateIAMSecret(iamServiceAccountRotateRequest);

		if (null != iamServiceAccountSecret) {
			log.info(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
					put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
					put(LogMessage.ACTION, "rotate IAM Service Account By AccessKeyId").
					put(LogMessage.MESSAGE, String.format ("IAM Service account [%s] rotated successfully for " +
									"AccessKeyId [%s]", iamServiceAccountRotateRequest.getUserName(),
							iamServiceAccountRotateRequest.getAccessKeyId())).
					put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
					build()));
			// Save secret in iamavcacc mount
			String path = IAMServiceAccountConstants.IAM_SVCC_ACC_PATH + uniqueIAMSvcaccName + "/" + IAMServiceAccountConstants.IAM_SECRET_FOLDER_PREFIX + (accessKeyIndex);
			if (iamServiceAccountUtils.writeIAMSvcAccSecret(token, path, iamServiceAccountName, iamServiceAccountSecret)) {
				log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
						put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
						put(LogMessage.ACTION, "rotate IAM Service Account By AccessKeyId").
						put(LogMessage.MESSAGE, "Secret saved to IAM service account mount").
						put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
						build()));
				Response metadataUdpateResponse = iamServiceAccountUtils.updateIAMSvcAccNewAccessKeyIdInMetadata(token, awsAccountId, iamServiceAccountName, accessKeyId, iamServiceAccountSecret);
				if (null != metadataUdpateResponse
						&& HttpStatus.NO_CONTENT.equals(metadataUdpateResponse.getHttpstatus())) {
					updateIAMSvcAccSecretWithLatestExpiryDate(token, awsAccountId, iamServiceAccountName, accessKeyId,
							iamServiceAccountSecret.getExpiryDateEpoch());
					log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
							put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
							put(LogMessage.ACTION, "rotate IAM Service Account By AccessKeyId").
							put(LogMessage.MESSAGE, "Updated IAM service account metadata with new AccessKeyId and expiry").
							put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
							build()));
					return true;
				}
			}
		}
		return false;
	}
/**
	 * Rotate secret for an accessKeyID in an IAM Service Account.
	 * @param token
	 * @param awsAccountId
	 * @param iamServiceAccountName
	 * @param accessKeyId
	 * @return
	 */
Rotate secret for an accessKeyID in an IAM Service Account.
Rotate secret for an accessKeyID in an IAM Service Account .
private boolean rotateIAMServiceAccountByAccessKeyId(String token, String awsAccountId, String iamServiceAccountName, String accessKeyId, int accessKeyIndex, UserDetails userDetails) {
		String uniqueIAMSvcaccName = awsAccountId + "_" + iamServiceAccountName;
		IAMServiceAccountRotateRequest iamServiceAccountRotateRequest = new IAMServiceAccountRotateRequest(accessKeyId, iamServiceAccountName, awsAccountId);
		IAMServiceAccountSecret iamServiceAccountSecret = iamServiceAccountUtils.rotateIAMSecret(iamServiceAccountRotateRequest);
		if (null != iamServiceAccountSecret) {
			log.info(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
					put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
					put(LogMessage.ACTION, "rotate IAM Service Account By AccessKeyId").
					put(LogMessage.MESSAGE, String.format ("IAM Service account [%s] rotated successfully for " +
									"AccessKeyId [%s]", iamServiceAccountRotateRequest.getUserName(),
							iamServiceAccountRotateRequest.getAccessKeyId())).
					put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
					build()));
			String path = IAMServiceAccountConstants.IAM_SVCC_ACC_PATH + uniqueIAMSvcaccName + "/" + IAMServiceAccountConstants.IAM_SECRET_FOLDER_PREFIX + (accessKeyIndex);
			if (iamServiceAccountUtils.writeIAMSvcAccSecret(token, path, iamServiceAccountName, iamServiceAccountSecret)) {
				log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
						put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
						put(LogMessage.ACTION, "rotate IAM Service Account By AccessKeyId").
						put(LogMessage.MESSAGE, "Secret saved to IAM service account mount").
						put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
						build()));
				Response metadataUdpateResponse = iamServiceAccountUtils.updateIAMSvcAccNewAccessKeyIdInMetadata(token, awsAccountId, iamServiceAccountName, accessKeyId, iamServiceAccountSecret);
				if (null != metadataUdpateResponse
						&& HttpStatus.NO_CONTENT.equals(metadataUdpateResponse.getHttpstatus())) {
					updateIAMSvcAccSecretWithLatestExpiryDate(token, awsAccountId, iamServiceAccountName, accessKeyId,
							iamServiceAccountSecret.getExpiryDateEpoch());
					log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
							put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
							put(LogMessage.ACTION, "rotate IAM Service Account By AccessKeyId").
							put(LogMessage.MESSAGE, "Updated IAM service account metadata with new AccessKeyId and expiry").
							put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
							build()));
					return true;
				}
			}
		}
		return false;
	}
private boolean rotateIAMServiceAccountByAccessKeyId ( String token , String awsAccountId , String iamServiceAccountName , String accessKeyId , int accessKeyIndex , UserDetails userDetails ) { String uniqueIAMSvcaccName = awsAccountId + "_" + iamServiceAccountName ; IAMServiceAccountRotateRequest iamServiceAccountRotateRequest = new IAMServiceAccountRotateRequest ( accessKeyId , iamServiceAccountName , awsAccountId ) ; IAMServiceAccountSecret iamServiceAccountSecret = iamServiceAccountUtils . rotateIAMSecret ( iamServiceAccountRotateRequest ) ; if ( null != iamServiceAccountSecret ) { log . info ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "rotate IAM Service Account By AccessKeyId" ) . put ( LogMessage . MESSAGE , String . format ( "IAM Service account [%s] rotated successfully for " + "AccessKeyId [%s]" , iamServiceAccountRotateRequest . getUserName ( ) , iamServiceAccountRotateRequest . getAccessKeyId ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; String path = IAMServiceAccountConstants . IAM_SVCC_ACC_PATH + uniqueIAMSvcaccName + "/" + IAMServiceAccountConstants . IAM_SECRET_FOLDER_PREFIX + ( accessKeyIndex ) ; if ( iamServiceAccountUtils . writeIAMSvcAccSecret ( token , path , iamServiceAccountName , iamServiceAccountSecret ) ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "rotate IAM Service Account By AccessKeyId" ) . put ( LogMessage . MESSAGE , "Secret saved to IAM service account mount" ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; Response metadataUdpateResponse = iamServiceAccountUtils . updateIAMSvcAccNewAccessKeyIdInMetadata ( token , awsAccountId , iamServiceAccountName , accessKeyId , iamServiceAccountSecret ) ; if ( null != metadataUdpateResponse && HttpStatus . NO_CONTENT . equals ( metadataUdpateResponse . getHttpstatus ( ) ) ) { updateIAMSvcAccSecretWithLatestExpiryDate ( token , awsAccountId , iamServiceAccountName , accessKeyId , iamServiceAccountSecret . getExpiryDateEpoch ( ) ) ; log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "rotate IAM Service Account By AccessKeyId" ) . put ( LogMessage . MESSAGE , "Updated IAM service account metadata with new AccessKeyId and expiry" ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return true ; } } } return false ; }
Rotate secret for an accessKeyID in an IAM Service Account.
Rotate secret for an accessKeyID in an IAM Service Account .
// Save secret in iamavcacc mount