Skip to content

Commit

Permalink
Add a helper for loading properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Jun 1, 2024
1 parent d63c12f commit 41bb2d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import groovy.transform.stc.ClosureParams
import groovy.transform.stc.FromString
import net.neoforged.camelot.config.module.ModuleConfiguration

import java.nio.file.Files
import java.nio.file.Path

/**
* The class holding Camelot's configuration, that is represented in a Groovy DSL.
*/
Expand Down Expand Up @@ -89,4 +92,19 @@ class CamelotConfig {
}
return value
}

/**
* Load a properties file from the given {@code path}.
* @param path the path of the properties file
* @return the loaded properties
*/
static Properties loadProperties(String path) {
final props = new Properties()
try (final reader = Files.newBufferedReader(Path.of(path))) {
props.load(reader)
} catch (Exception ex) {
throw new RuntimeException("Failed to read properties file at $path", ex)
}
return props
}
}
4 changes: 3 additions & 1 deletion config/src/sample/groovy/sample.camelot.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import net.neoforged.camelot.config.module.*

camelot {
final secrets = loadProperties('secrets.properties')

token = secret(env('BOT_TOKEN'))
prefix = '!'

Expand All @@ -23,7 +25,7 @@ camelot {
}

module(FilePreview) {
auth = patAuthentication(secret(env('GIST_PAT')))
auth = patAuthentication(secret(secrets.GIST_PAT))
}

module(WebServer) {
Expand Down

0 comments on commit 41bb2d0

Please sign in to comment.