From 74570dc3300de673dda218fb5f27af846867a20c Mon Sep 17 00:00:00 2001 From: francescods Date: Wed, 5 Mar 2025 09:43:57 +0100 Subject: [PATCH 1/5] configurazione build task buildFatJar Ktor aggiunta file per il logging dell'applicazione (file logFile.log creato nella stessa folder di esecuzione dell'applicazione) --- build.gradle.kts | 4 ++++ src/main/resources/logback.xml | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/main/resources/logback.xml diff --git a/build.gradle.kts b/build.gradle.kts index f2b1945..cef2a10 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,6 +9,10 @@ plugins { kotlin("plugin.serialization") version "1.9.23" // Aggiungi il plugin di Serialization } +application { + mainClass.set("eu.maiora.ApplicationKt") +} + group = "org.maiora" version = "1.0-SNAPSHOT" diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..9714b07 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + ./logFile.log + true + + %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file From 8242c78b35686d607ea94d8f6434ae9dd9cde83a Mon Sep 17 00:00:00 2001 From: francescods Date: Wed, 5 Mar 2025 11:57:27 +0100 Subject: [PATCH 2/5] file config esterno MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sul file di configurazione esterno vengono mappate le proprietà legate alla connessione al database --- .gitignore | 1 + src/main/kotlin/eu/maiora/Application.kt | 16 +++++++++++++--- src/main/resources/application.conf | 14 -------------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 42a03c5..3c63787 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ bin/ ### Mac OS ### .DS_Store .idea/.name +*.log diff --git a/src/main/kotlin/eu/maiora/Application.kt b/src/main/kotlin/eu/maiora/Application.kt index d82eece..80cf04c 100644 --- a/src/main/kotlin/eu/maiora/Application.kt +++ b/src/main/kotlin/eu/maiora/Application.kt @@ -9,6 +9,8 @@ import io.ktor.server.engine.* import io.ktor.server.netty.* import io.ktor.server.plugins.callloging.* import io.ktor.server.plugins.cors.routing.* +import java.io.FileInputStream +import java.util.* fun main() { embeddedServer(Netty, port = 8098, host = "0.0.0.0", module = Application::module) @@ -17,9 +19,10 @@ fun main() { fun Application.module() { val config = ApplicationConfig("application.conf") - val dbUrl = config.property("ktor.database.url").getString() - val username = config.property("ktor.database.username").getString() - val password = config.property("ktor.database.password").getString() + val configFile = loadConfig() + val dbUrl = configFile.getProperty("ktor.database.url") + val username = configFile.getProperty("ktor.database.username") + val password = configFile.getProperty("ktor.database.password") val secret = config.property("ktor.jwt.secret").getString() configureDatabases(dbUrl, username, password) configureSecurity(secret) @@ -39,3 +42,10 @@ fun Application.module() { allowMethod(HttpMethod.Delete) } } + +fun loadConfig(): Properties { + val properties = Properties() + val inputStream = FileInputStream("/home/ristocloudadm/config.properties") + properties.load(inputStream) + return properties +} diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 2037c99..8d1e65d 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -1,18 +1,4 @@ ktor { - database { -; url = "jdbc:postgresql://192.168.20.49:5432/caritas" -; username = "caritas" -; password = "caritas" -; driver = "org.postgresql.Driver" - driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver" - url = "jdbc:sqlserver://192.168.20.45;databaseName=EP_FAER;integratedSecurity=false;encrypt=true;trustServerCertificate=true;" - username = "SA" - password = "I5fz9l1a" - ;driver = "oracle.jdbc.OracleDriver" - ;url = "jdbc:oracle:thin:@//192.168.20.101:1521/SIR" - ;username = "EP_DONORIONE" - ;password = "ep_donorione" - } jwt { # secret per JWT generato partendo dalla stringa '?Backend_API*06022025!' codificato in Base64 secret = "P0JhY2tlbmRfQVBJKjA2MDIyMDI1IQ==" From b49577804e4eee1025cfac35b6636fe1e04f0a4d Mon Sep 17 00:00:00 2001 From: francescods Date: Tue, 18 Mar 2025 15:48:08 +0100 Subject: [PATCH 3/5] porta server su file esterno --- src/main/kotlin/eu/maiora/Application.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/eu/maiora/Application.kt b/src/main/kotlin/eu/maiora/Application.kt index 80cf04c..ad67624 100644 --- a/src/main/kotlin/eu/maiora/Application.kt +++ b/src/main/kotlin/eu/maiora/Application.kt @@ -13,13 +13,15 @@ import java.io.FileInputStream import java.util.* fun main() { - embeddedServer(Netty, port = 8098, host = "0.0.0.0", module = Application::module) - .start(wait = true) + val properties = loadConfig() + val port = properties.getProperty("server.port").toInt() + embeddedServer(Netty, port = port, host = "0.0.0.0") { + module(properties) + }.start(wait = true) } -fun Application.module() { +fun Application.module(configFile: Properties) { val config = ApplicationConfig("application.conf") - val configFile = loadConfig() val dbUrl = configFile.getProperty("ktor.database.url") val username = configFile.getProperty("ktor.database.username") val password = configFile.getProperty("ktor.database.password") From 23733caca9efbbf7c4686441f47a22e9b8bf2d95 Mon Sep 17 00:00:00 2001 From: francescods Date: Wed, 19 Mar 2025 09:17:31 +0100 Subject: [PATCH 4/5] modifica nome folder properties usato nome generico backend_api --- src/main/kotlin/eu/maiora/Application.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/eu/maiora/Application.kt b/src/main/kotlin/eu/maiora/Application.kt index ad67624..70fd658 100644 --- a/src/main/kotlin/eu/maiora/Application.kt +++ b/src/main/kotlin/eu/maiora/Application.kt @@ -47,7 +47,7 @@ fun Application.module(configFile: Properties) { fun loadConfig(): Properties { val properties = Properties() - val inputStream = FileInputStream("/home/ristocloudadm/config.properties") + val inputStream = FileInputStream("/home/backend_api/config.properties") properties.load(inputStream) return properties } From 8a934dca5bd3773d9b1bf0ffec7bfa726c87de57 Mon Sep 17 00:00:00 2001 From: francescods Date: Thu, 20 Mar 2025 13:00:16 +0100 Subject: [PATCH 5/5] modifica path autenticazione pulizia codice --- src/main/kotlin/eu/maiora/Application.kt | 2 +- src/main/kotlin/eu/maiora/plugins/Routing.kt | 8 +------- src/main/kotlin/eu/maiora/routes/Auth.kt | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/eu/maiora/Application.kt b/src/main/kotlin/eu/maiora/Application.kt index 70fd658..4e693fc 100644 --- a/src/main/kotlin/eu/maiora/Application.kt +++ b/src/main/kotlin/eu/maiora/Application.kt @@ -28,7 +28,7 @@ fun Application.module(configFile: Properties) { val secret = config.property("ktor.jwt.secret").getString() configureDatabases(dbUrl, username, password) configureSecurity(secret) - configureRouting(dbUrl, username, password) + configureRouting() configureSerialization() install(CallLogging) diff --git a/src/main/kotlin/eu/maiora/plugins/Routing.kt b/src/main/kotlin/eu/maiora/plugins/Routing.kt index abfd7e4..7194be6 100644 --- a/src/main/kotlin/eu/maiora/plugins/Routing.kt +++ b/src/main/kotlin/eu/maiora/plugins/Routing.kt @@ -1,18 +1,12 @@ package eu.maiora.plugins -//import eu.maiora.model.LogScriptRepositoryImpl -//import eu.maiora.routes.analizzaURLRoute -//import eu.maiora.routes.eseguiScriptSQLRoute -//import eu.maiora.routes.logScriptRouting import eu.maiora.model.AccountsRepositoryImpl -import eu.maiora.model.ParametriRepositoryImpl import eu.maiora.routes.auth import io.ktor.server.application.* import io.ktor.server.response.* import io.ktor.server.routing.* -//fun Application.configureRouting(dbUrl : String, username : String, password : String, repository : LogScriptRepositoryImpl ) { -fun Application.configureRouting(dbUrl : String, username : String, password : String) { +fun Application.configureRouting() { routing { get("/") { call.respondText("Hello World!") diff --git a/src/main/kotlin/eu/maiora/routes/Auth.kt b/src/main/kotlin/eu/maiora/routes/Auth.kt index c6a2cbb..0443947 100644 --- a/src/main/kotlin/eu/maiora/routes/Auth.kt +++ b/src/main/kotlin/eu/maiora/routes/Auth.kt @@ -16,7 +16,7 @@ import java.util.* fun Route.auth(accountsRepository: AccountsRepositoryImpl) { - route("/auth") { + route("/api/auth") { post() { // Riceve il body della richiesta e lo deserializza in ReceivedResponse val receivedResponse = try {