Skip to content

Commit

Permalink
[conluz-70] Configured SSL. Created keystore. Added www.omie.es certi…
Browse files Browse the repository at this point in the history
…ficate in the keystore
  • Loading branch information
viktorKhan committed Apr 17, 2024
1 parent d00b12b commit 4a3e029
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import org.springframework.web.util.UriComponentsBuilder;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.zone.ZoneRules;
import java.util.ArrayList;
Expand Down Expand Up @@ -50,7 +47,7 @@ public List<PriceByHour> getPricesByDay(OffsetDateTime day) {

final String dayFormatted = formatDay(day);

final OkHttpClient client = conluzRestClientBuilder.build();
final OkHttpClient client = conluzRestClientBuilder.build(false, Duration.ofSeconds(30));

LOGGER.info("Synchronizing OMIE prices for day {}.", dayFormatted);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ConluzRestClientBuilder {
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(10);

public OkHttpClient build() {
return build(false);
return build(false, DEFAULT_TIMEOUT);
}

/**
Expand All @@ -33,14 +33,17 @@ public OkHttpClient build() {
* @param enableLogging true if logging interceptor should be added, false otherwise
* @return the built OkHttpClient instance
*/
public OkHttpClient build(boolean enableLogging) {
public OkHttpClient build(boolean enableLogging, Duration timeout) {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
if (enableLogging) {
clientBuilder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
}
clientBuilder.connectTimeout(DEFAULT_TIMEOUT);
clientBuilder.writeTimeout(DEFAULT_TIMEOUT);
clientBuilder.readTimeout(DEFAULT_TIMEOUT);
if (timeout == null) {
timeout = DEFAULT_TIMEOUT;
}
clientBuilder.connectTimeout(timeout);
clientBuilder.writeTimeout(timeout);
clientBuilder.readTimeout(timeout);

return clientBuilder.build();
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ spring.servlet.multipart.max-request-size=11MB
# Actuator
management.endpoints.web.exposure.include=health,info

## SSL configuration
server.port=8443
server.ssl.enabled=true
# The format used for the keystore. It could be set to JKS in case it is a JKS file
server.ssl.key-store-type=PKCS12
# The path to the keystore containing the certificate
server.ssl.key-store=classpath:keystore/conluz.p12
# The password used to generate the certificate
server.ssl.key-store-password=changeit
# The alias mapped to the certificate
server.ssl.key-alias=conluz
Binary file added src/main/resources/keystore/conluz.p12
Binary file not shown.
36 changes: 36 additions & 0 deletions src/main/resources/keystore/omie.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-----BEGIN CERTIFICATE-----
MIIGSDCCBTCgAwIBAgIMNT+FkkXiTXv1T542MA0GCSqGSIb3DQEBCwUAMFMxCzAJ
BgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSkwJwYDVQQDEyBH
bG9iYWxTaWduIEdDQyBSMyBEViBUTFMgQ0EgMjAyMDAeFw0yNDA0MTcxMzQ3MTJa
Fw0yNTAxMDUwOTIwNDZaMBYxFDASBgNVBAMTC3d3dy5vbWllLmVzMIIBIjANBgkq
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArVj5hEwfrJXG9xfG3otAFli93JzghTBl
t9OmIYe5+2WpazHu6IWMpbWWqHtQhFvK5Szq3dUEKFY8NQbczIo4bAAuFMz0EPHd
3DIO2Z0MnTKW0AYzwzcvrCubU3CbzIV2Fsnymrj3t/KalO9SCJlJj0JsEcNyehu/
MpplXe/1Surej5O6ymQHWX3M/8p7mNfKXTWP6ET1dV+jTrkcLLtPi4nt4g6ZhySW
ML5zUg6UcBhm3rKXiRQJ+ZYmai6a8Kunq13ygm8E3+PByKp21OJOHVt5aXNY/5jV
PlBV6IMe94UqxS6w65jR8Ol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W2zU3z9S6x3w4I4bjWnAsfpksWKa
Od8AAAGO7E/BWAAABAMASDBGAiEAtVom3RSoJWHD0lxogzPkdPzKl5jjQ0wmKj/2
uTZcQTUCIQDg4bBW4aYFqOvyrVmdCrwxwYhPkPiEPhLU6pWmbaGBvjANBgkqhkiG
9w0BAQsFAAOCAQEAQ2EUXBa4f6HNKYWDsb5x4HPzJDnCTbaqE0N7Ba13FZBKG5Ei
Yz9BDUyeRHxZOg+KP/ZG4H/Bft4yfyF7b0RMht9i77w04pKpLDBWDDO35aOR2K+C
NJe7ngwTrtF5hqWrswcWFzR5Yao4JqZ2OxK81ChCN6DIKngSsYR1ftPw8dIcgVkr
EPXlOqZrJWsmuZYVH46NNYcAY1BWOr1P+r6/h7a4C7sxOrCpe0q8UP9WKX+RIzmj
HQZwxdwNuqWTj+PAMBBi1ioh06YgFINKtYbr5vckNxvCENGkamZhN2ealJ4goC8z
EOZMdqe2HJkGAsBoMAm9hiJtMS/E2hv9qW57pg==
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.lucoenergia.conluz.infrastructure.price.omie.sync;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.lucoenergia.conluz.domain.price.PriceByHour;
import org.lucoenergia.conluz.infrastructure.price.omie.get.GetPriceRepositoryRest;
import org.lucoenergia.conluz.infrastructure.shared.BaseIntegrationTest;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

//@Disabled("These tests should not be included in a CI pipeline because connects with www.omie.es.")
class GetPriceRepositoryRestIntegrationTest extends BaseIntegrationTest {

@Autowired
private GetPriceRepositoryRest repository;

@Test
void syncDailyPrices_successfulResponseWithNumberOne() {

// Assemble
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate date = LocalDate.parse("20230528", formatter);
OffsetDateTime dateTime = date.atStartOfDay().atOffset(ZoneOffset.UTC);

// Act
List<PriceByHour> prices = repository.getPricesByDay(dateTime);

// Assert
assertEquals(24, prices.size());
}
}

0 comments on commit 4a3e029

Please sign in to comment.