Skip to content

Commit

Permalink
feat: MET-1956 add bearerToken option for backendService
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-DucPhung committed Feb 6, 2024
1 parent 6815af4 commit d7fb36f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ To ensure the stability and reliability of this project, unit and mutation tests
- FLYWAY_VALIDATE: whether to automatically call validate when performing a migration
- KOIOS_BASE_URL_ENABLED: Set `true` to enable to use your Koios instance base URL, otherwise set `false`
- KOIOS_BASE_URL: Koios instance base URL.
- KOIOS_AUTH_TOKEN: JWT Bearer Auth token generated via https://koios.rest Profile page
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ services:
- FETCH_AND_SAVE_POOL_INFO_DATA_DELAY=${FETCH_AND_SAVE_POOL_INFO_DATA_DELAY}
- KOIOS_BASE_URL_ENABLED=${KOIOS_BASE_URL_ENABLED}
- KOIOS_BASE_URL=${KOIOS_BASE_URL}
- KOIOS_AUTH_TOKEN=${KOIOS_AUTH_TOKEN}
ports:
- ${SERVER_PORT}:${SERVER_PORT}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<version.java>17</version.java>
<version.lombok>1.18.26</version.lombok>
<org.projectlombok.version>1.18.24</org.projectlombok.version>
<koios-java-client.version>1.17.2</koios-java-client.version>
<koios-java-client.version>1.18.1</koios-java-client.version>
<version.ledgersync-common>0.1.0-SNAPSHOT</version.ledgersync-common>
<version.explorer-common>0.1.1-SNAPSHOT</version.explorer-common>
<version.explorer-consumer-common>0.1.12</version.explorer-consumer-common>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.cardanofoundation.explorer.rewards.config;

import jakarta.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
Expand All @@ -26,31 +28,37 @@ public class KoiosClient {
@Value("${application.koios-base-url}")
private String baseUrl;

@Value("${application.koios-auth-token}")
private String authToken;

private BackendService backendService;

public AccountService accountService() {
return this.getBackendService().getAccountService();
return this.backendService.getAccountService();
}

public NetworkService networkService() {
return this.getBackendService().getNetworkService();
return this.backendService.getNetworkService();
}

public PoolService poolService() {
return this.getBackendService().getPoolService();
return this.backendService.getPoolService();
}

public EpochService epochService() {
return this.getBackendService().getEpochService();
return this.backendService.getEpochService();
}

private BackendService getBackendService() {
@PostConstruct
void setBackendService() {
if (Boolean.TRUE.equals(baseUrlEnabled)) {
return BackendFactory.getCustomRPCService(baseUrl);
backendService = BackendFactory.getCustomRPCService(baseUrl, authToken);
} else {
return switch (value) {
case NetworkConstants.MAINNET -> BackendFactory.getKoiosMainnetService();
case NetworkConstants.PREPROD -> BackendFactory.getKoiosPreprodService();
case NetworkConstants.PREVIEW -> BackendFactory.getKoiosPreviewService();
case NetworkConstants.GUILDNET -> BackendFactory.getKoiosGuildService();
backendService = switch (value) {
case NetworkConstants.MAINNET -> BackendFactory.getKoiosMainnetService(authToken);
case NetworkConstants.PREPROD -> BackendFactory.getKoiosPreprodService(authToken);
case NetworkConstants.PREVIEW -> BackendFactory.getKoiosPreviewService(authToken);
case NetworkConstants.GUILDNET -> BackendFactory.getKoiosGuildService(authToken);
default -> throw new IllegalStateException("Unexpected value: " + value);
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ application:
network: ${NETWORK:mainnet}
koios-base-url-enabled: ${KOIOS_BASE_URL_ENABLED:false}
koios-base-url: ${KOIOS_BASE_URL:https://api.koios.rest/api/v0/}
koios-auth-token: ${KOIOS_AUTH_TOKEN}

reward:
list-size-each-thread: ${REWARD_LIST_SIZE_EACH_THREAD:5}
epoch-stake:
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ spring:
application:
network: ${NETWORK:mainnet}
koios-base-url-enabled: ${KOIOS_BASE_URL_ENABLED:false}
koios-base-url: ${KOIOS_BASE_URL:https://api.koios.rest/api/v0/}
koios-base-url: ${KOIOS_BASE_URL:https://koios-api.pro.dandelion-mainnet.eu-west-1.metadata.dev.cf-deployments.org/rpc/}
koios-auth-token: ${KOIOS_AUTH_TOKEN:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZGRyIjoic3Rha2UxdTg5eXZsNXB1OWhqenVkenF6amh3cHF2Y3Z3YTJ3dHNzNHljZG1seDM4Y2Foa2NwNWhzdmYiLCJleHAiOjE3Mzg2ODY5NjcsInRpZXIiOjEsInByb2pJRCI6ImNhcmRhbm9fZXhwbG9yZXJfcmV3YXJkIn0.vP9mbj4fDN3yz3c-kYloey9ssXbgqDcwVM3BSOJfk-g}

reward:
list-size-each-thread: ${LIST_SIZE_EACH_THREAD:5}
epoch-stake:
Expand Down
18 changes: 13 additions & 5 deletions src/main/resources/config/application-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spring:
hikari:
pool-name: explorer-api-pool
minimum-idle: 1 #minimum number of idle connections maintained by HikariCP in a connection pool
maximum-pool-size: 10 #maximum pool size
maximum-pool-size: 32 #maximum pool size
idle-timeout: 300000 #maximum idle time for connection
max-lifetime: 900000 #maximum lifetime in milliseconds of a connection in the pool after it is closed.
connection-timeout: 50000 #maximum number of milliseconds that a client will wait for a connection
Expand Down Expand Up @@ -63,15 +63,23 @@ spring:
default-schema: ${spring.jpa.properties.hibernate.default_schema}
schemas: ${spring.jpa.properties.hibernate.default_schema}
validate-on-migrate: ${FLYWAY_VALIDATE:false}

out-of-order: true
application:
network: ${NETWORK:mainnet}
koios-base-url-enabled: ${KOIOS_BASE_URL_ENABLED:false}
koios-base-url: ${KOIOS_BASE_URL:https://api.koios.rest/api/v0/}
koios-auth-token: ${KOIOS_AUTH_TOKEN}

reward:
list-size-each-thread: ${LIST_SIZE_EACH_THREAD:5}
list-size-each-thread: ${REWARD_LIST_SIZE_EACH_THREAD:5}
epoch-stake:
list-size-each-thread: ${LIST_SIZE_EACH_THREAD:5}
list-size-each-thread: ${EPOCH_STAKE_LIST_SIZE_EACH_THREAD:5}
pool-info:
list-size-each-thread: ${POOL_INFO_LIST_SIZE_EACH_THREAD:500}
job:
enable: ${POOL_INFO_DATA_JOB_ENABLED:true}
fixed-delay: ${FETCH_AND_SAVE_POOL_INFO_DATA_DELAY:3600000}
fixed-delay: ${FETCH_AND_SAVE_POOL_INFO_DATA_DELAY:3600000}

logging:
level:
rest.koios: ERROR

0 comments on commit d7fb36f

Please sign in to comment.