pgpainless/pgpainless-wot-cli/src/main/kotlin/org/pgpainless/wot/cli/subcommands/AuthenticateCmd.kt

59 lines
1.5 KiB
Kotlin
Raw Normal View History

2023-06-29 17:49:12 +02:00
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.wot.cli.subcommands
2023-07-07 15:42:04 +02:00
import org.pgpainless.wot.api.AuthenticateAPI
2023-06-29 17:49:12 +02:00
import org.pgpainless.wot.cli.WotCLI
2023-07-09 13:03:57 +02:00
import org.pgpainless.wot.network.Fingerprint
import org.pgpainless.wot.query.Path
2023-06-29 17:49:12 +02:00
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Parameters
import picocli.CommandLine.ParentCommand
import java.text.SimpleDateFormat
2023-06-29 17:49:12 +02:00
import java.util.concurrent.Callable
/**
* Authenticate a binding between a certification and one of its user-ids.
*/
2023-06-29 17:49:12 +02:00
@Command(name = "authenticate")
class AuthenticateCmd: Callable<Int> {
/**
* Parent command to acquire global options from.
*/
2023-06-29 17:49:12 +02:00
@ParentCommand
lateinit var parent: WotCLI
/**
* Fingerprint of the certificate.
*/
2023-06-29 17:49:12 +02:00
@Parameters(index = "0")
lateinit var fingerprint: String
/**
* User-ID to authenticate.
*/
2023-06-29 17:49:12 +02:00
@Parameters(index = "1")
lateinit var userId: String
/**
* Handle the User-ID as an email address.
*/
2023-06-29 17:49:12 +02:00
@CommandLine.Option(names = ["--email"], description = ["Consider all user-IDs that contain the given email address."])
var email = false
/**
* Execute the command.
* @return exit code
*/
override fun call(): Int {
val result = parent.api.authenticate(AuthenticateAPI.Arguments(
Fingerprint(fingerprint), userId, email))
2023-07-13 16:53:35 +02:00
println(parent.formatter.format(result))
return if (result.acceptable) 0 else 1
2023-06-29 17:49:12 +02:00
}
}