diff --git a/src/docs/agent-bsm-lab-postgres/cert/dfxagent-local.p12 b/src/docs/agent-bsm-lab-postgres/cert/dfxagent-local.p12 new file mode 100644 index 0000000..faa4d9e Binary files /dev/null and b/src/docs/agent-bsm-lab-postgres/cert/dfxagent-local.p12 differ diff --git a/src/docs/agent-bsm-lab-postgres/cert/truststore-local.jks b/src/docs/agent-bsm-lab-postgres/cert/truststore-local.jks new file mode 100644 index 0000000..5fb9ea4 Binary files /dev/null and b/src/docs/agent-bsm-lab-postgres/cert/truststore-local.jks differ diff --git a/src/docs/agent-bsm-lab-postgres/conf/dfxagent-bsm-lab-postgres.json b/src/docs/agent-bsm-lab-postgres/conf/dfxagent-bsm-lab-postgres.json index 03bf412..dcd7495 100644 --- a/src/docs/agent-bsm-lab-postgres/conf/dfxagent-bsm-lab-postgres.json +++ b/src/docs/agent-bsm-lab-postgres/conf/dfxagent-bsm-lab-postgres.json @@ -2,11 +2,19 @@ "description": "bsm-lab 서버에서 실행함. postgres 연결.", "myHostId": "agent-bsm-lab-postgres", "myListenPort": 17801, + "sslEnabled": true, + "keyStorePath": "D:/projects/bsm-lab/dfx/dfxagent/src/docs/agent-bsm-lab-postgres/cert/dfxagent-kdn.p12", + "keyStorePassword": "qortpals1!", + "keyStoreType": "PKCS12", + "trustStorePath": "D:/projects/bsm-lab/dfx/dfxagent/src/docs/agent-bsm-lab-postgres/cert/truststore-kdn.jks", + "trustStorePassword": "qortpals1!", + "trustStoreType": "JKS", "knownAgentList": [ { "hostId": "agent-tuf-a15-defree-oracle", "hostName": "bsm-lab.dev", "listenPort": 63801, + "sslEnabled": true, "dropBoxIdList": [ ], "routingHostIdList": [ @@ -45,17 +53,15 @@ "logPattern": "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n", "rootLogLevel": "DEBUG", "packages": [ - { - "com.bsmlab.dfx.agent": "DEBUG", - "jdbc.timing": "DEBUG", - "jdbc.sqltiming": "OFF", - "jdbc.sqlonly": "OFF", - "jdbc.audit": "OFF", - "jdbc.resultset": "OFF", - "jdbc.resultsettable": "OFF", - "jdbc.connection": "OFF", - "org.springframework": "INFO" - } + {"com.bsmlab.dfx.agent": "DEBUG"}, + {"jdbc.timing": "DEBUG"}, + {"jdbc.sqltiming": "OFF"}, + {"jdbc.sqlonly": "OFF"}, + {"jdbc.audit": "OFF"}, + {"jdbc.resultset": "OFF"}, + {"jdbc.resultsettable": "OFF"}, + {"jdbc.connection": "OFF"}, + {"org.springframework": "INFO"} ] }, "dropBoxConfig": { diff --git a/src/main/java/com/bsmlab/dfx/agent/DfxAgentApplication.java b/src/main/java/com/bsmlab/dfx/agent/DfxAgentApplication.java index 757f137..f8f27b6 100644 --- a/src/main/java/com/bsmlab/dfx/agent/DfxAgentApplication.java +++ b/src/main/java/com/bsmlab/dfx/agent/DfxAgentApplication.java @@ -1,13 +1,71 @@ package com.bsmlab.dfx.agent; +import com.bsmlab.dfx.agent.config.AgentConfigDto; +import com.fasterxml.jackson.databind.DatabindException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; +import java.util.Scanner; + @SpringBootApplication public class DfxAgentApplication { public static void main(String[] args) { - SpringApplication.run(DfxAgentApplication.class, args); + //--setting.file=$AGENT_HOME/conf/settings.json --setting.check + // --parse.message.file + boolean hasSettingFile = false; + boolean hasSettingCheck = false; + boolean hasParseMessageFile = false; + String settingFilePath = null; + if(args != null) { + for(String arg : args) { + if(arg != null && arg.contains("setting.file")) { + if(arg.split("=").length == 2) { + settingFilePath = arg.split("=")[1].trim(); + if(Files.exists(Path.of(settingFilePath))) { + hasSettingFile = true; + } + } + } + if(arg != null && arg.contains("setting.check")) { + hasSettingCheck = true; + } + if(arg != null && arg.contains("parse.message.file")) { + hasParseMessageFile = true; + } + } + } + if(hasSettingFile && !hasSettingCheck && !hasParseMessageFile) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + AgentConfigDto agentConfigDto = objectMapper.readValue(new File(settingFilePath), AgentConfigDto.class); + if(agentConfigDto.isSslEnabled()) { + System.setProperty("server.port", String.valueOf(agentConfigDto.getMyListenPort())); + System.setProperty("server.ssl.enabled", String.valueOf(agentConfigDto.isSslEnabled())); + System.setProperty("server.ssl.key-store", agentConfigDto.getKeyStorePath()); + System.setProperty("server.ssl.key-store-password", agentConfigDto.getKeyStorePassword()); + System.setProperty("server.ssl.key-store-type", "PKCS12"); + System.setProperty("server.ssl.trust-store", agentConfigDto.getTrustStorePath()); + System.setProperty("server.ssl.trust-store-password", agentConfigDto.getTrustStorePassword()); + System.setProperty("server.ssl.trust-store-type", "JKS"); + } + } catch (DatabindException e) { + System.out.println("cannot parse a setting file. " + settingFilePath); + e.printStackTrace(System.out); + } catch (IOException e) { + System.out.println("cannot read a setting file. " + settingFilePath); + e.printStackTrace(System.out); + } + SpringApplication.run(DfxAgentApplication.class, args); + } } } diff --git a/src/main/java/com/bsmlab/dfx/agent/config/AgentConfigDto.java b/src/main/java/com/bsmlab/dfx/agent/config/AgentConfigDto.java index 2a68406..91bcd60 100644 --- a/src/main/java/com/bsmlab/dfx/agent/config/AgentConfigDto.java +++ b/src/main/java/com/bsmlab/dfx/agent/config/AgentConfigDto.java @@ -11,6 +11,11 @@ public class AgentConfigDto { private String myHostId; private String myHostName; private int myListenPort; + private boolean sslEnabled; + private String keyStorePath; + private String keyStorePassword; + private String trustStorePath; + private String trustStorePassword; private List knownAgentList; private StatusChecker statusChecker; private List dataSourceConfig; @@ -26,6 +31,7 @@ public class AgentConfigDto { private String hostId; private String hostName; private int listenPort; + private boolean sslEnabled; private List dropBoxIdList; private List routingHostIdList; }