This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(incept): expose an inception endpoint to create a controller
- Loading branch information
1 parent
34f00e7
commit cfa84ed
Showing
5 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
"ncount": 1, | ||
"isith": "1", | ||
"nsith": "1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/id/walt/service/keri/KeriInceptionService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package id.walt.service.keri | ||
|
||
import id.walt.service.dto.KeriInceptionResponse | ||
import id.walt.service.keri.interfaces.KeriInceptionInterface | ||
import java.io.BufferedReader | ||
import java.io.IOException | ||
import java.io.InputStreamReader | ||
|
||
class KeriInceptionService: KeriInceptionInterface { | ||
|
||
private val CONFIG_DIR = "config" | ||
private val INCEPTION_FILE = "inception-config.json" | ||
override fun inceptController(name: String, alias: String, passcode: String): KeriInceptionResponse { | ||
var prefix = "" | ||
val publicKeys = mutableListOf<String>() | ||
|
||
val inceptCommand: List<String> = listOf( | ||
"kli", "incept", | ||
"--name" ,name, | ||
"--alias", alias, | ||
"--passcode", passcode, | ||
"--file", "$CONFIG_DIR/keri/$INCEPTION_FILE" | ||
) | ||
|
||
// kli status --name waltid --alias waltid-alias | awk '/Identifier:/ {print $2}' | ||
val statusCommand: List<String> = listOf( | ||
"kli", "status", | ||
"--name" ,name, | ||
"--alias", alias, | ||
"--passcode", passcode | ||
) | ||
|
||
try { | ||
val processBuilder = ProcessBuilder(inceptCommand) | ||
val process = processBuilder.start() | ||
process.waitFor() | ||
|
||
val statusProcessBuilder = ProcessBuilder(statusCommand) | ||
val statusProcess = statusProcessBuilder.start() | ||
|
||
val prefixInputReader = BufferedReader(InputStreamReader(statusProcess.inputStream)) | ||
|
||
var line: String? | ||
var capturingPublicKeys = false | ||
while (prefixInputReader.readLine().also { line = it } != null) { | ||
if (line?.contains("Identifier:") == true) { | ||
prefix = line!!.split(" ")[1] | ||
} | ||
|
||
if (line?.startsWith("Public Keys:") == true) { | ||
capturingPublicKeys = true | ||
continue | ||
} | ||
|
||
if (capturingPublicKeys && line?.isNotBlank() == true) { | ||
publicKeys.add(line!!.trim().split(" ")[1]) | ||
} else if (capturingPublicKeys && line?.isBlank() == true) { | ||
break | ||
} | ||
} | ||
|
||
statusProcess.waitFor() | ||
|
||
} catch(e: IOException) { | ||
e.printStackTrace() | ||
} catch (e: InterruptedException) { | ||
e.printStackTrace() | ||
} | ||
|
||
return KeriInceptionResponse(prefix, "did:keri:$prefix", publicKeys) | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/id/walt/service/keri/interfaces/KeriInceptionInterface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package id.walt.service.keri.interfaces | ||
|
||
import id.walt.service.dto.KeriInceptionResponse | ||
|
||
interface KeriInceptionInterface { | ||
fun inceptController(name: String, alias: String, passcode: String): KeriInceptionResponse; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters