Skip to content

Commit 4a13bcc

Browse files
committedAug 2, 2019
Add yaml config
1 parent 342a69d commit 4a13bcc

File tree

7 files changed

+55
-11
lines changed

7 files changed

+55
-11
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
**/build/
55
!gradle-wrapper.jar
66
gluecan-backend/gluecan
7+
**/*.sqlite

‎gluecan-backend/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ dependencies {
4343
implementation("org.jetbrains.exposed:exposed:0.15.1")
4444
implementation("com.fasterxml.jackson.core:jackson-databind:2.9.9")
4545
implementation("commons-lang:commons-lang:2.6")
46+
implementation("com.amihaiemil.web:eo-yaml:2.0.1")
4647
runtime(project(":gluecan-frontend"))
4748
}

‎gluecan-backend/gluecan-config.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
port: 8080
2+
3+
# No password required to add/delete if public
4+
public: false
5+
6+
# Password for administration UI if not public
7+
adminPass: change_me
8+
9+
# Database name/path
10+
database: gluecan.sqlite
11+
12+
# Optional keystore for HTTPS
13+
keystore:
14+
path: ~
15+
password: ~

‎gluecan-backend/src/main/kotlin/config.js.kt

-9
This file was deleted.
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package us.kesslern
2+
3+
import com.amihaiemil.eoyaml.Yaml
4+
import com.amihaiemil.eoyaml.YamlMapping
5+
import java.io.File
6+
7+
object Config {
8+
val adminPass: String
9+
val public: Boolean
10+
val database: String
11+
val keystorePath: String?
12+
val keystorePassword: String?
13+
val port: Int
14+
15+
16+
init {
17+
val yamlMapping = Yaml
18+
.createYamlInput(File("gluecan-config.yml"))
19+
.readYamlMapping()
20+
21+
22+
this.adminPass = yamlMapping.string("adminPass")
23+
this.database = "jdbc:sqlite:${yamlMapping.string("database")}"
24+
this.port = yamlMapping.string("port")!!.toInt()
25+
this.public = yamlMapping.string("public")!!.toBoolean()
26+
27+
val keystore = yamlMapping.yamlMapping("keystore")
28+
this.keystorePath = keystore.optionalString("path")
29+
this.keystorePassword = keystore.optionalString("password")
30+
}
31+
}
32+
33+
fun YamlMapping.optionalString(key: String): String? {
34+
val value = this.string(key)
35+
return if (value == "~") null else value
36+
}

‎gluecan-backend/src/main/kotlin/main.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ fun main() {
1616

1717
app.gluecan()
1818

19-
app.start(8080)
19+
app.start(Config.port)
2020
}
2121

‎gluecan-backend/src/main/kotlin/webapp.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Templater {
1414
.readText()
1515
.replace("{{pasteId}}", paste.id.toString())
1616
.replace("{{class}}", paste.language ?: "")
17-
.replace("{{date}}", paste.date.toString())
17+
.replace("{{date}}", paste.date)
1818
.replace("{{pasteHtml}}", paste.toHtml())
1919

2020
}

0 commit comments

Comments
 (0)