Skip to content
Snippets Groups Projects
Verified Commit 4d098c83 authored by Torsten Grote's avatar Torsten Grote
Browse files

Allow cli app to set a custom setup token

For testing purposes only!
parent 46bfa9f6
No related branches found
No related tags found
1 merge request!57Allow cli app to set a custom setup token
Pipeline #8953 passed
......@@ -31,12 +31,14 @@ import org.briarproject.mailbox.core.db.TransactionManager
import org.briarproject.mailbox.core.lifecycle.LifecycleManager
import org.briarproject.mailbox.core.setup.QrCodeEncoder
import org.briarproject.mailbox.core.setup.SetupManager
import org.briarproject.mailbox.core.system.InvalidIdException
import org.slf4j.LoggerFactory.getLogger
import java.util.logging.Level.ALL
import java.util.logging.Level.INFO
import java.util.logging.Level.WARNING
import java.util.logging.LogManager
import javax.inject.Inject
import kotlin.system.exitProcess
class Main : CliktCommand(
name = "briar-mailbox",
......@@ -50,6 +52,7 @@ class Main : CliktCommand(
"-v",
help = "Print verbose log messages"
).counted()
private val setupToken: String? by option("--setup-token", hidden = true)
@Inject
internal lateinit var coreEagerSingletons: CoreEagerSingletons
......@@ -100,6 +103,13 @@ class Main : CliktCommand(
lifecycleManager.startServices()
lifecycleManager.waitForStartup()
if (setupToken != null) try {
setupManager.setToken(setupToken, null)
} catch (e: InvalidIdException) {
System.err.println("Invalid setup token")
exitProcess(1)
}
// TODO this is obviously not the final code, just a stub to get us started
val setupTokenExists = db.read { txn ->
setupManager.getSetupToken(txn) != null
......
......@@ -51,11 +51,8 @@ class SetupManager @Inject constructor(
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE_OWNER)
}
/**
* Visible for testing, consider private.
*/
@Throws(DbException::class)
internal fun setToken(setupToken: String?, ownerToken: String?) {
fun setToken(setupToken: String?, ownerToken: String?) {
val settings = Settings()
if (setupToken != null) randomIdManager.assertIsRandomId(setupToken)
settings[SETTINGS_SETUP_TOKEN] = setupToken
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment