2022-03-01 15:53:24 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package pgp.cert_d.cli.commands;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2022-07-04 20:12:42 +02:00
|
|
|
import pgp.cert_d.cli.MergeCallbacks;
|
2022-03-01 15:53:24 +01:00
|
|
|
import pgp.cert_d.cli.PGPCertDCli;
|
|
|
|
import pgp.certificate_store.Certificate;
|
|
|
|
import pgp.certificate_store.exception.BadDataException;
|
|
|
|
import picocli.CommandLine;
|
|
|
|
|
2022-07-04 12:52:49 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2022-07-04 13:04:11 +02:00
|
|
|
@CommandLine.Command(name = "insert",
|
|
|
|
description = "Insert or update a certificate")
|
|
|
|
public class Insert implements Runnable {
|
2022-03-01 15:53:24 +01:00
|
|
|
|
2022-07-04 13:04:11 +02:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(Insert.class);
|
2022-03-01 15:53:24 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
2022-07-04 20:12:42 +02:00
|
|
|
Certificate certificate = PGPCertDCli.getCertificateDirectory()
|
|
|
|
.insertCertificate(System.in, MergeCallbacks.mergeCertificates());
|
2022-03-01 15:53:24 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
LOGGER.error("IO-Error.", e);
|
|
|
|
System.exit(-1);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
LOGGER.error("Thread interrupted.", e);
|
|
|
|
System.exit(-1);
|
|
|
|
} catch (BadDataException e) {
|
|
|
|
LOGGER.error("Certificate contains bad data.", e);
|
|
|
|
System.exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|