mirror of
https://codeberg.org/PGPainless/cert-d-pgpainless.git
synced 2024-11-13 03:22:05 +01:00
Add Export command
This commit is contained in:
parent
1efb2598a2
commit
fca9a8ef91
3 changed files with 43 additions and 1 deletions
|
@ -8,6 +8,7 @@ import org.pgpainless.certificate_store.CertificateReader;
|
|||
import org.pgpainless.certificate_store.SharedPGPCertificateDirectoryAdapter;
|
||||
import pgp.cert_d.BaseDirectoryProvider;
|
||||
import pgp.cert_d.SharedPGPCertificateDirectoryImpl;
|
||||
import pgp.cert_d.cli.commands.Export;
|
||||
import pgp.cert_d.cli.commands.Get;
|
||||
import pgp.cert_d.cli.commands.Insert;
|
||||
import pgp.cert_d.cli.commands.Import;
|
||||
|
@ -25,6 +26,7 @@ import java.sql.SQLException;
|
|||
name = "certificate-store",
|
||||
description = "Store and manage public OpenPGP certificates",
|
||||
subcommands = {
|
||||
Export.class,
|
||||
Insert.class,
|
||||
Import.class,
|
||||
Get.class,
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.cert_d.cli.commands;
|
||||
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
@CommandLine.Command(name = "export",
|
||||
description = "Export all certificates in the store to Standard Output")
|
||||
public class Export implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Get.class);
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Iterator<Certificate> certificates = PGPCertDCli.getCertificateDirectory()
|
||||
.getCertificates();
|
||||
while (certificates.hasNext()) {
|
||||
try {
|
||||
Certificate certificate = certificates.next();
|
||||
InputStream inputStream = certificate.getInputStream();
|
||||
Streams.pipeAll(inputStream, System.out);
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("IO Error", e);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
|
||||
@CommandLine.Command(name = "import",
|
||||
description = "Import certificates into the store from stdin")
|
||||
description = "Import certificates into the store from Standard Input")
|
||||
public class Import implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Import.class);
|
||||
|
|
Loading…
Reference in a new issue