// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
chargingStation.stationInfo?.chargingStationId
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- }#${connectorId?.toString()} for idTag '${idTag}'`
+ }#${connectorId?.toString()} for idTag '${truncateId(idTag)}'`
)
} else {
logger.debug(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
chargingStation.stationInfo?.chargingStationId
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- }#${connectorId?.toString()} for idTag '${idTag}'`
+ }#${connectorId?.toString()} for idTag '${truncateId(idTag)}'`
)
}
return undefined
`${chargingStation.logPrefix()} ${moduleName}.handleRequestRemoteStartTransaction: Remote start transaction ACCEPTED on ${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
chargingStation.stationInfo?.chargingStationId
- }#${transactionConnectorId.toString()}, idTag '${idTag}'`
+ }#${transactionConnectorId.toString()}, idTag '${truncateId(idTag)}'`
)
return OCPP16Constants.OCPP_RESPONSE_ACCEPTED
}
`${chargingStation.logPrefix()} ${moduleName}.notifyRemoteStartTransactionRejected: Remote start transaction REJECTED on ${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
chargingStation.stationInfo?.chargingStationId
- }#${connectorId.toString()}, idTag '${idTag}', availability '${
+ }#${connectorId.toString()}, idTag '${truncateId(idTag)}', availability '${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
connectorStatus?.availability
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) {
authorizeConnectorStatus.idTagAuthorized = true
logger.debug(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseAuthorize: idTag '${
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseAuthorize: idTag '${truncateId(
requestPayload.idTag
- }' accepted on connector id ${authorizeConnectorId.toString()}`
+ )}' accepted on connector id ${authorizeConnectorId.toString()}`
)
} else {
authorizeConnectorStatus.idTagAuthorized = false
}
} else {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseAuthorize: idTag '${
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseAuthorize: idTag '${truncateId(
requestPayload.idTag
- }' has no authorize request pending`
+ )}' has no authorize request pending`
)
}
OCPP16ServiceUtils.updateAuthorizationCache(
connectorStatus.idTagLocalAuthorized === false
) {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with a not local authorized idTag ${
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- connectorStatus.localAuthorizeIdTag
- } on connector id ${connectorId.toString()}`
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with a not local authorized idTag '${truncateId(
+ connectorStatus.localAuthorizeIdTag ?? ''
+ )}' on connector id ${connectorId.toString()}`
)
await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
return
connectorStatus.idTagAuthorized === false
) {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with a not authorized idTag ${
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- connectorStatus.authorizeIdTag
- } on connector id ${connectorId.toString()}`
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with a not authorized idTag '${truncateId(
+ connectorStatus.authorizeIdTag ?? ''
+ )}' on connector id ${connectorId.toString()}`
)
await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
return
connectorStatus.authorizeIdTag !== requestPayload.idTag
) {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with an idTag ${
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with an idTag '${truncateId(
requestPayload.idTag
- } different from the authorize request one ${
- connectorStatus.authorizeIdTag
- } on connector id ${connectorId.toString()}`
+ )}' different from the authorize request one '${truncateId(
+ connectorStatus.authorizeIdTag ?? ''
+ )}' on connector id ${connectorId.toString()}`
)
await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
return
connectorStatus.localAuthorizeIdTag !== requestPayload.idTag
) {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with an idTag ${
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction with an idTag '${truncateId(
requestPayload.idTag
- } different from the local authorized one ${
- connectorStatus.localAuthorizeIdTag
- } on connector id ${connectorId.toString()}`
+ )}' different from the local authorized one '${truncateId(
+ connectorStatus.localAuthorizeIdTag ?? ''
+ )}' on connector id ${connectorId.toString()}`
)
await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
return
}
if (connectorStatus?.transactionStarted === true) {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction on an already used connector id ${connectorId.toString()} by idTag ${
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- connectorStatus.transactionIdTag
- }`
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction on an already used connector id ${connectorId.toString()} by idTag '${truncateId(
+ connectorStatus.transactionIdTag ?? ''
+ )}'`
)
return
}
for (const [id, status] of evseStatus.connectors) {
if (id !== connectorId && status.transactionStarted === true) {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction on an already used evse id ${evseId.toString()} by connector id ${id.toString()} with idTag ${
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- status.transactionIdTag
- }`
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Trying to start a transaction on an already used evse id ${evseId.toString()} by connector id ${id.toString()} with idTag '${truncateId(
+ status.transactionIdTag ?? ''
+ )}'`
)
await this.resetConnectorOnStartTransactionError(chargingStation, connectorId)
return
if (reservation != null) {
if (reservation.idTag !== requestPayload.idTag) {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Reserved transaction ${payload.transactionId.toString()} started with a different idTag ${truncateId(
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseStartTransaction: Reserved transaction ${payload.transactionId.toString()} started with a different idTag '${truncateId(
requestPayload.idTag
- )} than the reservation one ${truncateId(reservation.idTag)}`
+ )}' than the reservation one '${truncateId(reservation.idTag)}'`
)
}
if (hasReservationExpired(reservation)) {
chargingStationReservation.idTag === idTag)
) {
logger.debug(
- `${chargingStation.logPrefix()} ${moduleName}.hasReservation: Connector id ${connectorId.toString()} has a valid reservation for idTag ${idTag}: %j`,
+ `${chargingStation.logPrefix()} ${moduleName}.hasReservation: Connector id ${connectorId.toString()} has a valid reservation for idTag '${truncateId(idTag)}': %j`,
connectorReservation ?? chargingStationReservation
)
return true
if (authResult.status !== AuthorizationStatus.ACCEPTED) {
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.authorizeToken: ${tokenLabel} ${truncateId(tokenValue)} is not authorized`
+ `${chargingStation.logPrefix()} ${moduleName}.authorizeToken: ${tokenLabel} '${truncateId(tokenValue)}' is not authorized`
)
}
): Promise<OCPP20RequestStartTransactionResponse> {
const { chargingProfile, evseId, groupIdToken, idToken, remoteStartId } = commandPayload
logger.info(
- `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Remote start transaction request received on EVSE ${evseId?.toString() ?? 'undefined'} with idToken ${truncateId(idToken.idToken)} and remoteStartId ${remoteStartId.toString()}`
+ `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Remote start transaction request received on EVSE ${evseId?.toString() ?? 'undefined'} with idToken '${truncateId(idToken.idToken)}' and remoteStartId ${remoteStartId.toString()}`
)
let resolvedEvseId = evseId
)
} catch (error) {
logger.error(
- `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Authorization error for ${truncateId(idToken.idToken)}:`,
+ `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Authorization error for '${truncateId(idToken.idToken)}':`,
error
)
return {
return {
status: RequestStartStopStatusEnumType.Rejected,
statusInfo: {
- additionalInfo: `IdToken ${truncateId(idToken.idToken)} is not authorized`,
+ additionalInfo: `IdToken '${truncateId(idToken.idToken)}' is not authorized`,
reasonCode: ReasonCodeEnumType.InvalidIdToken,
},
transactionId: generateUUID(),
)
} catch (error) {
logger.error(
- `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Group authorization error for ${truncateId(groupIdToken.idToken)}:`,
+ `${chargingStation.logPrefix()} ${moduleName}.handleRequestStartTransaction: Group authorization error for '${truncateId(groupIdToken.idToken)}':`,
error
)
return {
return {
status: RequestStartStopStatusEnumType.Rejected,
statusInfo: {
- additionalInfo: `GroupIdToken ${truncateId(groupIdToken.idToken)} is not authorized`,
+ additionalInfo: `GroupIdToken '${truncateId(groupIdToken.idToken)}' is not authorized`,
reasonCode: ReasonCodeEnumType.InvalidIdToken,
},
transactionId: generateUUID(),
}
logger.debug(
- `${chargingStation.logPrefix()} ${moduleName}.isAuthorizedToStopTransaction: IdToken ${truncateId(presentedIdToken.idToken)} not authorized to stop transaction on connector ${connectorId.toString()}`
+ `${chargingStation.logPrefix()} ${moduleName}.isAuthorizedToStopTransaction: IdToken '${truncateId(presentedIdToken.idToken)}' not authorized to stop transaction on connector ${connectorId.toString()}`
)
return false
}
import type { ChargingStation } from '../../charging-station/index.js'
-import { logger } from '../../utils/index.js'
+import { logger, truncateId } from '../../utils/index.js'
import {
AuthContext,
AuthenticationMethod,
): Promise<boolean> => {
try {
logger.debug(
- `${chargingStation.logPrefix()} Authorizing idTag '${idTag}' on connector ${connectorId.toString()}`
+ `${chargingStation.logPrefix()} Authorizing idTag '${truncateId(idTag)}' on connector ${connectorId.toString()}`
)
const authService = OCPPAuthServiceFactory.getInstance(chargingStation)
})
logger.debug(
- `${chargingStation.logPrefix()} Authorization result for idTag '${idTag}': ${authResult.status} using ${authResult.method} method`
+ `${chargingStation.logPrefix()} Authorization result for idTag '${truncateId(idTag)}': ${authResult.status} using ${authResult.method} method`
)
if (authResult.status === AuthorizationStatus.ACCEPTED) {
try {
logger.debug(
- `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier ${truncateId(identifier.value)} via OCPP 1.6`
+ `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier '${truncateId(identifier.value)}' via OCPP 1.6`
)
// Mark connector as authorizing if provided
try {
logger.debug(
- `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier ${truncateId(identifier.value)} via OCPP 2.0 Authorize`
+ `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier '${truncateId(identifier.value)}' via OCPP 2.0 Authorize`
)
const isRemoteAuth = this.isRemoteAvailable()
// Check rate limiting first
if (!this.checkRateLimit(identifier)) {
this.stats.rateLimitBlocked++
- logger.warn(`${moduleName}: Rate limit exceeded for identifier: ${truncateId(identifier)}`)
+ logger.warn(`${moduleName}: Rate limit exceeded for identifier: '${truncateId(identifier)}'`)
return undefined
}
}
this.lruOrder.set(identifier, now)
logger.debug(
- `${moduleName}: Expired entry transitioned to EXPIRED for identifier: ${truncateId(identifier)}`
+ `${moduleName}: Expired entry transitioned to EXPIRED for identifier: '${truncateId(identifier)}'`
)
return authCacheEntry.result
}
authCacheEntry.expiresAt = now + this.defaultTtl * 1000
}
- logger.debug(`${moduleName}: Cache hit for identifier: ${truncateId(identifier)}`)
+ logger.debug(`${moduleName}: Cache hit for identifier: '${truncateId(identifier)}'`)
return authCacheEntry.result
}
this.lruOrder.delete(identifier)
if (deleted) {
- logger.debug(`${moduleName}: Removed entry for identifier: ${truncateId(identifier)}`)
+ logger.debug(`${moduleName}: Removed entry for identifier: '${truncateId(identifier)}'`)
}
}
if (!this.checkRateLimit(identifier)) {
this.stats.rateLimitBlocked++
logger.warn(
- `${moduleName}: Rate limit exceeded, not caching identifier: ${truncateId(identifier)}`
+ `${moduleName}: Rate limit exceeded, not caching identifier: '${truncateId(identifier)}'`
)
return
}
this.stats.sets++
logger.debug(
- `${moduleName}: Cached result for identifier: ${truncateId(identifier)}, ttl=${String(clampedTtl)}s, entries=${String(this.cache.size)}/${String(this.maxEntries)}`
+ `${moduleName}: Cached result for identifier: '${truncateId(identifier)}', ttl=${String(clampedTtl)}s, entries=${String(this.cache.size)}/${String(this.maxEntries)}`
)
}
this.cache.delete(candidateIdentifier)
this.lruOrder.delete(candidateIdentifier)
this.stats.evictions++
- logger.debug(`${moduleName}: Evicted LRU entry: ${truncateId(candidateIdentifier)}`)
+ logger.debug(`${moduleName}: Evicted LRU entry: '${truncateId(candidateIdentifier)}'`)
}
}
}
this.metrics.totalRequests++
logger.debug(
- `${this.chargingStation.logPrefix()} ${moduleName}.authenticate: Starting authentication for identifier: ${truncateId(request.identifier.value)}`
+ `${this.chargingStation.logPrefix()} ${moduleName}.authenticate: Starting authentication for identifier: '${truncateId(request.identifier.value)}'`
)
// Try each strategy in priority order
}
this.authCache.remove(identifier.value)
logger.info(
- `${this.chargingStation.logPrefix()} ${moduleName}.invalidateCache: Cache invalidated for identifier: ${truncateId(identifier.value)}`
+ `${this.chargingStation.logPrefix()} ${moduleName}.invalidateCache: Cache invalidated for identifier: '${truncateId(identifier.value)}'`
)
}
const ttlSeconds = Math.floor((expiry.getTime() - Date.now()) / 1000)
if (ttlSeconds <= 0) {
logger.debug(
- `${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Skipping expired entry for ${truncateId(identifier)}`
+ `${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Skipping expired entry for '${truncateId(identifier)}'`
)
return
}
this.authCache.set(identifier, result, effectiveTtl)
logger.debug(
- `${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Updated cache for ${truncateId(identifier)} status=${status}${effectiveTtl != null ? `, ttl=${effectiveTtl.toString()}s` : ''}`
+ `${this.chargingStation.logPrefix()} ${moduleName}.updateCacheEntry: Updated cache for '${truncateId(identifier)}' status=${status}${effectiveTtl != null ? `, ttl=${effectiveTtl.toString()}s` : ''}`
)
}
try {
logger.debug(
- `${moduleName}: Authenticating ${truncateId(request.identifier.value)} for ${request.context}`
+ `${moduleName}: Authenticating '${truncateId(request.identifier.value)}' for ${request.context}`
)
// 1. Try local authorization list first (highest priority)
}
logger.debug(
- `${moduleName}: No local authorization found for ${truncateId(request.identifier.value)}`
+ `${moduleName}: No local authorization found for '${truncateId(request.identifier.value)}'`
)
return undefined
} catch (error) {
try {
this.authCache.set(identifier, result, ttl)
- logger.debug(`${moduleName}: Cached result for ${truncateId(identifier)}`)
+ logger.debug(`${moduleName}: Cached result for '${truncateId(identifier)}'`)
} catch (error) {
const errorMessage = getErrorMessage(error)
logger.error(`${moduleName}: Failed to cache result: ${errorMessage}`)
try {
this.authCache.remove(identifier)
- logger.debug(`${moduleName}: Invalidated cache for ${truncateId(identifier)}`)
+ logger.debug(`${moduleName}: Invalidated cache for '${truncateId(identifier)}'`)
} catch (error) {
const errorMessage = getErrorMessage(error)
logger.error(`${moduleName}: Failed to invalidate cache: ${errorMessage}`)
return undefined
}
- logger.debug(`${moduleName}: Cache hit for ${truncateId(request.identifier.value)}`)
+ logger.debug(`${moduleName}: Cache hit for '${truncateId(request.identifier.value)}'`)
return cachedResult
} catch (error) {
const errorMessage = getErrorMessage(error)
// Check if entry is expired
if (entry.expiryDate && entry.expiryDate < new Date()) {
- logger.debug(`${moduleName}: Entry ${truncateId(request.identifier.value)} expired`)
+ logger.debug(`${moduleName}: Entry '${truncateId(request.identifier.value)}' expired`)
return {
expiryDate: entry.expiryDate,
isOffline: false,
config: AuthConfiguration
): AuthorizationResult | undefined {
logger.debug(
- `${moduleName}: Applying offline fallback for ${truncateId(request.identifier.value)}`
+ `${moduleName}: Applying offline fallback for '${truncateId(request.identifier.value)}'`
)
// For transaction stops, always allow (safety requirement)
try {
logger.debug(
- `${moduleName}: Authenticating ${truncateId(request.identifier.value)} via CSMS for ${request.context}`
+ `${moduleName}: Authenticating '${truncateId(request.identifier.value)}' via CSMS for ${request.context}`
)
// Get adapter
const isInLocalList = await this.localAuthListManager.getEntry(request.identifier.value)
if (isInLocalList) {
logger.debug(
- `${moduleName}: Skipping cache for local list identifier: ${truncateId(request.identifier.value)}`
+ `${moduleName}: Skipping cache for local list identifier: '${truncateId(request.identifier.value)}'`
)
} else {
this.cacheResult(
}
logger.debug(
- `${moduleName}: No remote authorization result for ${truncateId(request.identifier.value)}`
+ `${moduleName}: No remote authorization result for '${truncateId(request.identifier.value)}'`
)
return undefined
} catch (error) {
const cacheTtl = ttl ?? result.cacheTtl ?? 300 // Default 5 minutes
this.authCache.set(identifier, result, cacheTtl)
logger.debug(
- `${moduleName}: Cached result for ${truncateId(identifier)} (TTL: ${String(cacheTtl)}s)`
+ `${moduleName}: Cached result for '${truncateId(identifier)}' (TTL: ${String(cacheTtl)}s)`
)
} catch (error) {
const errorMessage = getErrorMessage(error)
* @returns Formatted error string with truncated identifier
*/
function formatAuthError (error: Error, identifier: Identifier): string {
- return `Authentication failed for identifier ${truncateId(identifier.value)} (${identifier.type}): ${error.message}`
+ return `Authentication failed for identifier '${truncateId(identifier.value)}' (${identifier.type}): ${error.message}`
}
/**