|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | +namespace OC\Core\Command\OCM; |
| 10 | + |
| 11 | +use OC\Core\Command\Base; |
| 12 | +use OC\OCM\OCMSignatoryManager; |
| 13 | +use Symfony\Component\Console\Helper\Table; |
| 14 | +use Symfony\Component\Console\Input\InputInterface; |
| 15 | +use Symfony\Component\Console\Output\OutputInterface; |
| 16 | + |
| 17 | +class ListKeys extends Base { |
| 18 | + public function __construct( |
| 19 | + private readonly OCMSignatoryManager $signatoryManager, |
| 20 | + ) { |
| 21 | + parent::__construct(); |
| 22 | + } |
| 23 | + |
| 24 | + #[\Override] |
| 25 | + protected function configure(): void { |
| 26 | + $this |
| 27 | + ->setName('ocm:keys:list') |
| 28 | + ->setDescription('list Ed25519 keys used by OCM RFC 9421 HTTP Message Signatures'); |
| 29 | + parent::configure(); |
| 30 | + } |
| 31 | + |
| 32 | + #[\Override] |
| 33 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
| 34 | + $keys = $this->signatoryManager->listEd25519Keys(); |
| 35 | + $format = $input->getOption('output'); |
| 36 | + if ($format === self::OUTPUT_FORMAT_JSON || $format === self::OUTPUT_FORMAT_JSON_PRETTY) { |
| 37 | + $output->writeln(json_encode($keys, $format === self::OUTPUT_FORMAT_JSON_PRETTY ? JSON_PRETTY_PRINT : 0)); |
| 38 | + return 0; |
| 39 | + } |
| 40 | + |
| 41 | + if ($keys === []) { |
| 42 | + $output->writeln('<comment>No Ed25519 keys yet — one will be generated on first OCM request.</comment>'); |
| 43 | + return 0; |
| 44 | + } |
| 45 | + |
| 46 | + $table = new Table($output); |
| 47 | + $table->setHeaders(['Pool', 'Slot', 'Key ID']); |
| 48 | + foreach ($keys as $key) { |
| 49 | + $table->addRow([$key['poolId'], $key['slot'] ?? '-', $key['kid']]); |
| 50 | + } |
| 51 | + $table->render(); |
| 52 | + return 0; |
| 53 | + } |
| 54 | +} |
0 commit comments