NTP-16416 | Lite rotate keys logic fix (#13866)
This commit is contained in:
@@ -288,44 +288,65 @@ constructor(
|
||||
)
|
||||
}
|
||||
UpiLiteBoundStatus.BOUND.name -> {
|
||||
if (upiLiteBoundStatus.syncRequired == "true") {
|
||||
val isLiteSyncSuccess =
|
||||
upiLiteClHelper.performLiteSync(
|
||||
lrn = liteAccount.lrn,
|
||||
accountId = linkedAccountEntity.accountId,
|
||||
screenName = screenName
|
||||
)
|
||||
if (upiLiteBoundStatus.syncRequired == "false") {
|
||||
naviPayAnalytics.onDevGenericEvent(
|
||||
event = "Sync_CL_For_Upi_Lite_Bound_False",
|
||||
params = mapOf("func" to ::syncClForUpiLite.name)
|
||||
)
|
||||
checkIfClIsBoundUpdateBalance(accountId = linkedAccountEntity.accountId)
|
||||
return
|
||||
}
|
||||
|
||||
if (isLiteSyncSuccess) {
|
||||
naviPayAnalytics.onDevGenericEvent(
|
||||
event = "Sync_CL_For_Upi_Lite_Success",
|
||||
params =
|
||||
mapOf(
|
||||
"func" to ::syncClForUpiLite.name,
|
||||
"reason" to "Lite Sync registerUPILiteState success"
|
||||
)
|
||||
)
|
||||
checkAndRotateDeviceCertificate(
|
||||
val isLiteSyncSuccess =
|
||||
upiLiteClHelper.performLiteSync(
|
||||
lrn = liteAccount.lrn,
|
||||
accountId = linkedAccountEntity.accountId,
|
||||
screenName = screenName
|
||||
)
|
||||
|
||||
if (isLiteSyncSuccess) {
|
||||
naviPayAnalytics.onDevGenericEvent(
|
||||
event = "Sync_CL_For_Upi_Lite_Success",
|
||||
params =
|
||||
mapOf(
|
||||
"func" to ::syncClForUpiLite.name,
|
||||
"reason" to "Lite Sync registerUPILiteState success"
|
||||
)
|
||||
)
|
||||
checkIfClIsBoundUpdateBalance(accountId = linkedAccountEntity.accountId)
|
||||
} else {
|
||||
// Check if key rotation is needed
|
||||
val isKeysRotationNeeded =
|
||||
checkIfKeysRotationIsNeeded(
|
||||
lrn = liteAccount.lrn,
|
||||
linkedAccountEntity = linkedAccountEntity
|
||||
)
|
||||
checkIfClIsBoundUpdateBalance(accountId = linkedAccountEntity.accountId)
|
||||
} else {
|
||||
|
||||
if (isKeysRotationNeeded) {
|
||||
naviPayAnalytics.onDevGenericEvent(
|
||||
event = "Sync_CL_For_Upi_Lite_Failed",
|
||||
event = "Sync_CL_For_Upi_Lite_Rotation_Needed",
|
||||
params =
|
||||
mapOf(
|
||||
"func" to ::syncClForUpiLite.name,
|
||||
"reason" to "Lite Sync registerUPILiteState failed"
|
||||
)
|
||||
)
|
||||
executeLiteRegistration(
|
||||
linkedAccountEntity = linkedAccountEntity,
|
||||
lrn = liteAccount.lrn
|
||||
)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
||||
naviPayAnalytics.onDevGenericEvent(
|
||||
event = "Sync_CL_For_Upi_Lite_Bound_False",
|
||||
params = mapOf("func" to ::syncClForUpiLite.name)
|
||||
event = "Sync_CL_For_Upi_Lite_Failed",
|
||||
params =
|
||||
mapOf(
|
||||
"func" to ::syncClForUpiLite.name,
|
||||
"reason" to
|
||||
"Lite Sync registerUPILiteState and keys rotation failed"
|
||||
)
|
||||
)
|
||||
checkIfClIsBoundUpdateBalance(accountId = linkedAccountEntity.accountId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -538,41 +559,34 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun checkAndRotateDeviceCertificate(
|
||||
private fun checkIfKeysRotationIsNeeded(
|
||||
lrn: String,
|
||||
linkedAccountEntity: LinkedAccountEntity
|
||||
) {
|
||||
): Boolean {
|
||||
val liteInfoEntity = linkedAccountEntity.upiLiteInfo.find { it.lrn == lrn }
|
||||
naviPayAnalytics.onDevGenericEvent(
|
||||
event = "Device_Certificate_Rotation",
|
||||
params =
|
||||
mapOf(
|
||||
"func" to ::checkAndRotateDeviceCertificate.name,
|
||||
"func" to ::checkIfKeysRotationIsNeeded.name,
|
||||
"currentDateTime" to DateTime.now().toString(),
|
||||
"liteInfoEntity" to liteInfoEntity.toString()
|
||||
)
|
||||
)
|
||||
|
||||
liteInfoEntity?.let {
|
||||
val lastUpdatedAt =
|
||||
NaviPayCommonUtils.getDateTimeObjectFromDateTimeString(dateTime = it.lastUpdatedOn)
|
||||
if (liteInfoEntity == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
// check if 80% of rotation period is elapsed
|
||||
val elapsedDays = Days.daysBetween(lastUpdatedAt, DateTime.now()).days
|
||||
val isRotationNeeded = elapsedDays / it.rotation.toDouble() >= 0.8
|
||||
|
||||
naviPayAnalytics.onDevGenericEvent(
|
||||
event = "Device_Certificate_Rotation_Needed",
|
||||
params =
|
||||
mapOf(
|
||||
"func" to ::checkAndRotateDeviceCertificate.name,
|
||||
"isRotationNeeded" to isRotationNeeded.toString()
|
||||
)
|
||||
val lastUpdatedAt =
|
||||
NaviPayCommonUtils.getDateTimeObjectFromDateTimeString(
|
||||
dateTime = liteInfoEntity.lastUpdatedOn
|
||||
)
|
||||
|
||||
if (isRotationNeeded) {
|
||||
executeLiteRegistration(linkedAccountEntity = linkedAccountEntity, lrn = lrn)
|
||||
}
|
||||
}
|
||||
// check if 80% of rotation period is elapsed
|
||||
val elapsedDays = Days.daysBetween(lastUpdatedAt, DateTime.now()).days
|
||||
val isRotationNeeded = elapsedDays / liteInfoEntity.rotation.toDouble() >= 0.8
|
||||
return isRotationNeeded
|
||||
}
|
||||
|
||||
private suspend fun executeLiteRegistration(
|
||||
|
||||
Reference in New Issue
Block a user