Skip to content

Commit

Permalink
Merge pull request #124 from choffmann/server-refactoring
Browse files Browse the repository at this point in the history
Server refactoring
  • Loading branch information
choffmann authored Jun 24, 2022
2 parents 9b3412c + 91edfa2 commit 9138871
Show file tree
Hide file tree
Showing 74 changed files with 4,712 additions and 2,742 deletions.
2 changes: 1 addition & 1 deletion CopyScriptJsMain.ps1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Copy-Item -Force -Path ".\budget-binder-multiplatform-app\build\distributions\*" -Destination ".\budget-binder-server\files\"
Copy-Item -Force -Path ".\budget-binder-multiplatform-app\build\distributions\*" -Destination ".\budget-binder-server\public\"
2 changes: 2 additions & 0 deletions CopyScriptJsMain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cp -r ./budget-binder-multiplatform-app/build/distributions/* ./budget-binder-server/public/
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ WORKDIR /home/gradle/src
RUN gradle :budget-binder-multiplatform-app:jsBrowserDistribution :budget-binder-server:shadowJar --no-daemon

FROM openjdk:17
RUN mkdir -p /app/data && mkdir -p /app/files
RUN mkdir -p /app/data && mkdir -p /app/public
WORKDIR /app

VOLUME /app/data
COPY --from=build /home/gradle/src/budget-binder-server/files /app/files/
COPY --from=build /home/gradle/src/budget-binder-multiplatform-app/build/distributions/ /app/files/
COPY --from=build /home/gradle/src/budget-binder-server/files /app/public/
COPY --from=build /home/gradle/src/budget-binder-multiplatform-app/build/distributions/ /app/public/
COPY --from=build /home/gradle/src/budget-binder-server/build/libs/*.jar /app/ktor-docker-server.jar

ENV \
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile_dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ WORKDIR /home/gradle/src
RUN gradle :budget-binder-multiplatform-app:jsBrowserDistribution :budget-binder-server:shadowJar --no-daemon

FROM openjdk:17
RUN mkdir -p /app/data && mkdir -p /app/files
RUN mkdir -p /app/data && mkdir -p /app/public
WORKDIR /app

VOLUME /app/data
COPY --from=build /home/gradle/src/budget-binder-server/files /app/files/
COPY --from=build /home/gradle/src/budget-binder-multiplatform-app/build/distributions/ /app/files/
COPY --from=build /home/gradle/src/budget-binder-server/files /app/public/
COPY --from=build /home/gradle/src/budget-binder-multiplatform-app/build/distributions/ /app/public/
COPY --from=build /home/gradle/src/budget-binder-server/build/libs/*.jar /app/ktor-docker-server.jar

ENV \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class APIResponse<T>(
val error: ErrorModel? = null,
val data: T? = null,
val success: Boolean = false
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package de.hsfl.budgetBinder.common
import kotlinx.serialization.Serializable

@Serializable
data class AuthToken(val token: String)
data class AuthToken(val token: String)
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ data class Category(
val image: Image,
val budget: Float
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import de.hsfl.budgetBinder.android.BudgetBinderApplication
import java.io.File

actual fun getCookieFileStorage(): File {
return File(BudgetBinderApplication.instance.filesDir, "cookies.txt")
return File(BudgetBinderApplication.instance.filesDir, "cookies.bin")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.util.*


class AuthPlugin private constructor(
val loginPath: String,
val logoutPath: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ actual fun getCookieFileStorage(): File {
path += "/.bb-client"
File(path).toPath().createDirectories()

path += "/cookies.txt"
path += "/cookies.bin"
val file = File(path)
file.createNewFile()
return file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,5 @@ class FileCookieStorage : CookiesStorage {
writeCookiesToFile(container)
}

override fun close() {
}
override fun close() {}
}
6 changes: 3 additions & 3 deletions budget-binder-server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val ktorVersion: String by project
val exposedVersion: String by project

plugins {
application
kotlin("jvm")
Expand All @@ -25,7 +28,6 @@ dependencies {
implementation(project(":budget-binder-common"))
implementation(kotlin("stdlib"))

val ktorVersion = "2.0.2"
implementation("io.ktor:ktor-network-tls-certificates-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-core-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-auth-jvm:$ktorVersion")
Expand All @@ -45,10 +47,8 @@ dependencies {

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2")


implementation("ch.qos.logback:logback-classic:1.2.11")

val exposedVersion = "0.38.2"
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
Expand Down
2 changes: 1 addition & 1 deletion budget-binder-server/data/config_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ server:
keyStorePassword: null
keyStorePath: null
noForwardedHeaderSupport: false
dataBase:
database:
dbType: SQLITE
sqlitePath: null
serverAddress: null
Expand Down
2 changes: 2 additions & 0 deletions budget-binder-server/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ktorVersion=2.0.2
exposedVersion=0.38.2
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package de.hsfl.budgetBinder.server.config

import java.io.File

data class Config(val server: Server, val dataBase: DataBase, val jwt: JWT) {
data class Config(val server: Server, val database: Database, val jwt: JWT) {
data class Server(
val dev: Boolean,
val ssl: Boolean,
Expand All @@ -20,7 +21,7 @@ data class Config(val server: Server, val dataBase: DataBase, val jwt: JWT) {
POSTGRES,
}

data class DataBase(
data class Database(
val dbType: DBType,
val sqlitePath: String,
val serverAddress: String,
Expand All @@ -39,4 +40,98 @@ data class Config(val server: Server, val dataBase: DataBase, val jwt: JWT) {
val issuer: String,
val audience: String
)

companion object {
fun create(configFile: File? = null): Config {
return configFile?.let {
createFromIntermediate(ConfigIntermediate.createFromFile(it))
} ?: createFromIntermediate(ConfigIntermediate.createFromEnv())
}

fun createFromIntermediate(intermediate: ConfigIntermediate): Config {
val dbType = intermediate.database.dbType

val sqlitePath: String
val dbServerAddress: String
val dbServerPort: String
val dbName: String
val dbUser: String
val dbPassword: String
if (dbType == DBType.SQLITE) {
sqlitePath = intermediate.database.sqlitePath ?: (System.getProperty("user.dir") + "/data/data.db")
dbServerAddress = ""
dbServerPort = ""
dbName = ""
dbUser = ""
dbPassword = ""
} else {
sqlitePath = ""
dbServerAddress = intermediate.database.serverAddress ?: error("No dbServerAddress specified")
dbServerPort = intermediate.database.serverPort ?: error("No dbServerPort specified")
dbName = intermediate.database.name ?: error("No dbDatabaseName specified")
dbUser = intermediate.database.user ?: error("No dbUser specified")
dbPassword = intermediate.database.password ?: error("No dbPassword specified")
}

val dev = intermediate.server?.dev ?: false
val ssl = intermediate.server?.ssl ?: false

val host = intermediate.server?.host ?: "0.0.0.0"
val port = intermediate.server?.port ?: 8080
val sslHost = intermediate.server?.sslHost ?: "0.0.0.0"
val sslPort = intermediate.server?.sslPort ?: 8443

val keyStorePassword: String
val keyStorePath: String
if (ssl) {
keyStorePassword = intermediate.server?.keyStorePassword
?: if (dev) "budget-binder-server" else error("No KeystorePassword provided")
keyStorePath = intermediate.server?.keyStorePath
?: if (dev) "data/dev_keystore.jks" else error("No KeystorePath provided")
} else {
keyStorePassword = ""
keyStorePath = ""
}

val forwardedHeaderSupport = !(intermediate.server?.noForwardedHeaderSupport ?: false)

val jwtAccessSecret = intermediate.jwt.accessSecret
val jwtRefreshSecret = intermediate.jwt.refreshSecret
val jwtAccessMinutes = intermediate.jwt.accessMinutes ?: 15
val jwtRefreshDays = intermediate.jwt.refreshDays ?: 7
val jwtRealm = intermediate.jwt.realm ?: "budget-binder-server"
val jwtIssuer = intermediate.jwt.issuer ?: "http://0.0.0.0:8080/"
val jwtAudience = intermediate.jwt.audience ?: "http://0.0.0.0:8080/"

return Config(
database = Database(
dbType,
sqlitePath,
dbServerAddress,
dbServerPort,
dbName,
dbUser,
dbPassword
), server = Server(
dev,
ssl,
host,
port,
sslHost,
sslPort,
keyStorePassword,
keyStorePath,
forwardedHeaderSupport
), jwt = JWT(
jwtAccessSecret,
jwtRefreshSecret,
jwtAccessMinutes,
jwtRefreshDays,
jwtRealm,
jwtIssuer,
jwtAudience
)
)
}
}
}
Loading

0 comments on commit 9138871

Please sign in to comment.