Skip to content

Commit f76f131

Browse files
committed
Add database credentials to properties file
Credentials for the database connection have been transferred from the build.gradle.kts file to a new local.properties file to enhance security and readabilty. These credentials can now also be sourced from environment variables.
1 parent aab4445 commit f76f131

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

build.gradle.kts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.util.*
2+
13
plugins {
24
kotlin("jvm") version "1.8.0"
35
id("org.jetbrains.kotlinx.dataframe") version "0.13.1"
@@ -18,22 +20,26 @@ dependencies {
1820
testImplementation(kotlin("test"))
1921
}
2022

23+
24+
val props = Properties()
25+
file("local.properties").inputStream().use { props.load(it) }
26+
2127
dataframes {
2228
schema {
2329
data = "jdbc:mariadb://localhost:3307/imdb"
2430
name = "org.jetbrains.kotlinx.dataframe.examples.jdbc.Actors"
2531
jdbcOptions {
26-
user = "root"
27-
password = "pass"
32+
user = props.getProperty("db.user")
33+
password = props.getProperty("db.password")
2834
tableName = "actors"
2935
}
3036
}
3137
schema {
3238
data = "jdbc:mariadb://localhost:3307/imdb"
3339
name = "org.jetbrains.kotlinx.dataframe.examples.jdbc.TarantinoFilms"
3440
jdbcOptions {
35-
user = "root"
36-
password = "pass"
41+
user = System.getenv("DB_USER") ?: props.getProperty("db.user")
42+
password = System.getenv("DB_PASSWORD") ?: props.getProperty("db.password")
3743
sqlQuery = """
3844
SELECT name, year, rank,
3945
GROUP_CONCAT (genre) as "genres"

local.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.user=root
2+
db.password=pass

0 commit comments

Comments
 (0)