Skip to content

Commit

Permalink
feat: update models to comply with ocpi 2.2.1 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
dv-rosales authored Aug 13, 2024
1 parent c2d8a90 commit 79afba6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package snc.openchargingnetwork.node.config

import org.springframework.boot.context.properties.ConfigurationProperties
import snc.openchargingnetwork.node.tools.generateUUIDv4Token
import javax.annotation.PostConstruct

@ConfigurationProperties("ocn.node")
class NodeProperties {

var apikey: String = generateUUIDv4Token()

var base64apiKey: String = "";

var dev: Boolean = false

var privateKey: String? = null
Expand Down Expand Up @@ -55,4 +58,9 @@ class NodeProperties {
var plannedPartySearchEnabled: Boolean = true

var serviceInterfaceEnabled: Boolean = true

@PostConstruct
fun init() {
base64apiKey = java.util.Base64.getEncoder().encodeToString(apikey.toByteArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AdminController(private val platformRepo: PlatformRepository,
private val properties: NodeProperties) {

fun isAuthorized(authorization: String): Boolean {
return authorization == "Token ${properties.apikey}"
return authorization == "Token ${properties.apikey}" || authorization == "Bearer ${properties.base64apiKey}"
}

@GetMapping("/connection-status/{countryCode}/{partyID}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data class StartSession(@JsonProperty("response_url") var responseURL: String,
@JsonProperty("token") val token: Token,
@JsonProperty("location_id") val locationID: String,
@JsonProperty("evse_uid") val evseUID: String? = null,
@JsonProperty("connector_id") val connectorID: String? = null,
@JsonProperty("authorization_reference") val authorizationReference: String? = null)

data class StopSession(@JsonProperty("response_url") var responseURL: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import snc.openchargingnetwork.node.models.*
import snc.openchargingnetwork.node.models.exceptions.OcpiServerGenericException
import snc.openchargingnetwork.node.models.exceptions.OcpiServerUnusableApiException
import snc.openchargingnetwork.node.models.ocpi.*
import snc.openchargingnetwork.node.tools.generateUUIDv4Token
import snc.openchargingnetwork.node.tools.urlJoin


Expand Down Expand Up @@ -96,7 +97,11 @@ class HttpService {
*/
fun getVersions(url: String, authorization: String): List<Version> {
try {
val response = khttp.get(url = url, headers = mapOf("Authorization" to "Token $authorization"))
val response = khttp.get(url = url, headers = mapOf(
"Authorization" to "Token $authorization",
"X-Correlation-ID" to generateUUIDv4Token(),
"X-Request-ID" to generateUUIDv4Token()
))
val body: OcpiResponse<List<Version>> = mapper.readValue(response.text)

return if (response.statusCode == 200 && body.statusCode == 1000) {
Expand All @@ -117,7 +122,11 @@ class HttpService {
*/
fun getVersionDetail(url: String, authorization: String): VersionDetail {
try {
val response = khttp.get(url = url, headers = mapOf("Authorization" to "Token $authorization"))
val response = khttp.get(url = url, headers = mapOf(
"Authorization" to "Token $authorization",
"X-Correlation-ID" to generateUUIDv4Token(),
"X-Request-ID" to generateUUIDv4Token()
))
val body: OcpiResponse<VersionDetail> = mapper.readValue(response.text)

return if (response.statusCode == 200 && body.statusCode == 1000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class CredentialsControllerTest(@Autowired val mockMvc: MockMvc) {
.header("Authorization", "Token ${platform.auth.tokenC}")
.contentType(MediaType.APPLICATION_JSON)
.content(jacksonObjectMapper().writeValueAsString(Credentials(
token = tokenB!!,
token = tokenB,
url = versionsUrl,
roles = listOf(role1, role2)))))
.andExpect(status().isOk)
Expand Down

This file was deleted.

0 comments on commit 79afba6

Please sign in to comment.