Skip to content

Commit

Permalink
Custodians REST API should also offer the management functionality fo…
Browse files Browse the repository at this point in the history
…r DIDs, close #71
  • Loading branch information
waltkb committed Nov 28, 2021
1 parent b19dba5 commit 5885e7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/main/kotlin/id/walt/cli/DidCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ package id.walt.cli

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.requireObject
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.optional
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.types.choice
import com.github.ajalt.clikt.parameters.types.path
import id.walt.common.prettyPrint
import id.walt.crypto.KeyAlgorithm
import id.walt.model.DidMethod
import id.walt.model.DidUrl
import id.walt.services.crypto.CryptoService
import id.walt.services.did.DidService

import java.io.File
import java.nio.file.Path
import kotlin.io.path.absolutePathString
import kotlin.io.path.writeText

class DidCommand : CliktCommand(
help = """Decentralized Identifiers (DIDs).
Expand All @@ -24,10 +29,7 @@ class DidCommand : CliktCommand(
Supported DID methods are "key", "web" and "ebsi"""
) {

override fun run() {

}
override fun run() {}
}

class CreateDidCommand : CliktCommand(
Expand All @@ -40,15 +42,13 @@ class CreateDidCommand : CliktCommand(
"""
) {
val config: CliConfig by requireObject()
val method: String by option("-m", "--did-method", help = "Specify DID method [key]").choice(
"key",
"web",
"ebsi"
).default("key")
val method: String by option("-m", "--did-method", help = "Specify DID method [key]")
.choice("key", "web", "ebsi").default("key")

val keyAlias: String? by option("-k", "--key", help = "Specific key (ID or alias)")
val domain: String by option("-d", "--domain", help = "Domain for did:web").default("walt.id")
val path: String? by option("-p", "--path", help = "Path for did:web")
val outFile: String? by option("-o", "--out", help = "Output file")
val dest: Path? by argument("destination-file").path().optional()

override fun run() {

Expand All @@ -67,14 +67,17 @@ class CreateDidCommand : CliktCommand(
val encodedDid = loadDidHelper(did)
echo("DID document (below, JSON):\n\n$encodedDid")

outFile?.let {
val didFile = File(outFile)
echo("\nSaving DID to file: ${didFile.absolutePath}")
didFile.writeText(encodedDid)
dest?.let {
echo("\nSaving DID to file: ${dest!!.absolutePathString()}")
dest!!.writeText(encodedDid)
}

when (method) {
"web" -> echo("Install this did:web at: https://$domain/${path?.replace(":", "/")?.plus("/") ?: ""}.well-known/did.json")
"web" -> echo(
"Install this did:web at: https://$domain/${
path?.replace(":", "/")?.plus("/") ?: ""
}.well-known/did.json"
)
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/id/walt/rest/custodian/CustodianAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import id.walt.Values
import id.walt.rest.ErrorResponse
import id.walt.rest.OpenAPIUtils
import id.walt.rest.RootController
import id.walt.rest.core.DidController
import io.javalin.Javalin
import io.javalin.apibuilder.ApiBuilder.*
import io.javalin.core.util.RouteOverviewPlugin
Expand Down Expand Up @@ -116,6 +117,15 @@ object CustodianAPI {
delete("{id}", documented(CustodianController.deleteKeysDocs(), CustodianController::deleteKey))
}

path("did") {
get("", documented(DidController.listDocs(), DidController::list))
get("{id}", documented(DidController.loadDocs(), DidController::load))
delete("{id}", documented(DidController.deleteDocs(), DidController::delete))
post("create", documented(DidController.createDocs(), DidController::create))
post("resolve", documented(DidController.resolveDocs(), DidController::resolve))
post("import", documented(DidController.importDocs(), DidController::import))
}

path("credentials") {
get("/", documented(CustodianController.listCredentialsDocs(), CustodianController::listCredentials))
get("{id}", documented(CustodianController.getCredentialDocs(), CustodianController::getCredential))
Expand Down

0 comments on commit 5885e7f

Please sign in to comment.