Skip to content

Commit

Permalink
fix(credentials): add partnerId on getCredentialsRoles
Browse files Browse the repository at this point in the history
  • Loading branch information
jggrimal committed Oct 31, 2024
1 parent b754cc9 commit aa0571d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.izivia.ocpi.toolkit.modules.credentials.repositories
import com.izivia.ocpi.toolkit.modules.credentials.domain.CredentialRole

interface CredentialsRoleRepository {
suspend fun getCredentialsRoles(): List<CredentialRole>
suspend fun getCredentialsRoles(partnerId: String): List<CredentialRole>
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ open class CredentialsClientService(
credentials = Credentials(
token = serverToken,
url = clientVersionsEndpointUrl,
roles = clientCredentialsRoleRepository.getCredentialsRoles(),
roles = clientCredentialsRoleRepository.getCredentialsRoles(partnerId),
),
debugHeaders = emptyMap(),
).let {
Expand Down Expand Up @@ -148,7 +148,7 @@ open class CredentialsClientService(
credentials = Credentials(
token = credentialsServerToken,
url = clientVersionsEndpointUrl,
roles = clientCredentialsRoleRepository.getCredentialsRoles(),
roles = clientCredentialsRoleRepository.getCredentialsRoles(partnerId),
),
debugHeaders = emptyMap(),
).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.izivia.ocpi.toolkit.modules.credentials.CredentialsInterface
import com.izivia.ocpi.toolkit.modules.credentials.domain.Credentials
import com.izivia.ocpi.toolkit.modules.credentials.repositories.CredentialsRoleRepository
import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository
import com.izivia.ocpi.toolkit.modules.versions.domain.*
import com.izivia.ocpi.toolkit.modules.versions.domain.Version
import com.izivia.ocpi.toolkit.modules.versions.domain.VersionDetails
import com.izivia.ocpi.toolkit.modules.versions.domain.VersionNumber
import com.izivia.ocpi.toolkit.transport.TransportClientBuilder
import com.izivia.ocpi.toolkit.transport.domain.HttpMethod
import com.izivia.ocpi.toolkit.transport.domain.HttpRequest
Expand All @@ -24,6 +26,8 @@ open class CredentialsServerService(
): OcpiResponseBody<Credentials> = OcpiResponseBody.of {
getCredentials(
serverToken = token,
partnerRepository.getPartnerIdByCredentialsServerToken(token)
?: throw OcpiClientInvalidParametersException("Invalid ServerToken ($token)"),
)
}

Expand All @@ -36,7 +40,7 @@ open class CredentialsServerService(
// It can happen when a partner unregister, then registers with its clientToken (which is the serverToken
// for us)
val partnerId = partnerRepository.getPartnerIdByCredentialsServerToken(token)
// If we could not find a partner with this serverToken, then, it means that it's probably a tokenA
// If we could not find a partner with this serverToken, then, it means that it's probably a tokenA
?: partnerRepository.getPartnerIdByCredentialsTokenA(credentialsTokenA = token)
?: throw OcpiClientInvalidParametersException(
"Invalid token ($token) - should be either a TokenA or a ServerToken",
Expand Down Expand Up @@ -70,6 +74,7 @@ open class CredentialsServerService(
partnerId = partnerId,
credentialsServerToken = generateUUIDv4Token(),
),
partnerId = partnerId,
)
}

Expand Down Expand Up @@ -109,6 +114,7 @@ open class CredentialsServerService(
partnerId = partnerId,
credentialsServerToken = generateUUIDv4Token(),
),
partnerId = partnerId,
)
}

Expand Down Expand Up @@ -218,9 +224,9 @@ open class CredentialsServerService(
partnerRepository.saveEndpoints(partnerId = partnerId, endpoints = versionDetail.endpoints)
}

private suspend fun getCredentials(serverToken: String): Credentials = Credentials(
private suspend fun getCredentials(serverToken: String, partnerId: String): Credentials = Credentials(
token = serverToken,
url = serverVersionsUrlProvider(),
roles = credentialsRoleRepository.getCredentialsRoles(),
roles = credentialsRoleRepository.getCredentialsRoles(partnerId),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun main() {
service = CredentialsServerService(
partnerRepository = receiverPlatformRepository,
credentialsRoleRepository = object : CredentialsRoleRepository {
override suspend fun getCredentialsRoles(): List<CredentialRole> = listOf(
override suspend fun getCredentialsRoles(partnerId: String): List<CredentialRole> = listOf(
CredentialRole(
role = Role.EMSP,
businessDetails = BusinessDetails(name = "Receiver", website = null, logo = null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun main() {
clientPartnerRepository = senderPlatformRepository,
clientVersionsRepository = senderVersionsRepository,
clientCredentialsRoleRepository = object : CredentialsRoleRepository {
override suspend fun getCredentialsRoles(): List<CredentialRole> = listOf(
override suspend fun getCredentialsRoles(partnerId: String): List<CredentialRole> = listOf(
CredentialRole(
role = Role.CPO,
businessDetails = BusinessDetails(name = "Sender", website = null, logo = null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() {
service = CredentialsServerService(
partnerRepository = receiverPlatformRepo,
credentialsRoleRepository = object : CredentialsRoleRepository {
override suspend fun getCredentialsRoles(): List<CredentialRole> = listOf(
override suspend fun getCredentialsRoles(partnerId: String): List<CredentialRole> = listOf(
CredentialRole(
role = Role.EMSP,
businessDetails = BusinessDetails(name = "Receiver", website = null, logo = null),
Expand Down Expand Up @@ -135,7 +135,7 @@ class CredentialsIntegrationTests : BaseServerIntegrationTest() {
clientPartnerRepository = PartnerMongoRepository(collection = senderServerSetupResult.partnerCollection),
clientVersionsRepository = VersionsCacheRepository(baseUrl = senderServerSetupResult.transport.baseUrl),
clientCredentialsRoleRepository = object : CredentialsRoleRepository {
override suspend fun getCredentialsRoles(): List<CredentialRole> = listOf(
override suspend fun getCredentialsRoles(partnerId: String): List<CredentialRole> = listOf(
CredentialRole(
role = Role.CPO,
businessDetails = BusinessDetails(name = "Sender", website = null, logo = null),
Expand Down

0 comments on commit aa0571d

Please sign in to comment.