Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 64
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
OpenSsl
0.00% covered (danger)
0.00%
0 / 64
0.00% covered (danger)
0.00%
0 / 2
72
0.00% covered (danger)
0.00%
0 / 1
 configure
0.00% covered (danger)
0.00%
0 / 45
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Command\Configure;
10
11use InvalidArgumentException;
12use OCA\Libresign\Command\Base;
13use Symfony\Component\Console\Input\InputInterface;
14use Symfony\Component\Console\Input\InputOption;
15use Symfony\Component\Console\Output\OutputInterface;
16
17class OpenSsl extends Base {
18    #[\Override]
19    protected function configure(): void {
20        $this
21            ->setName('libresign:configure:openssl')
22            ->setDescription('Configure OpenSSL')
23            ->addOption(
24                name: 'cn',
25                shortcut: null,
26                mode: InputOption::VALUE_REQUIRED,
27                description: 'Comon name'
28            )
29            ->addOption(
30                name: 'ou',
31                shortcut: null,
32                mode: InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
33                description: 'Organization unit (can be specified multiple times)'
34            )
35            ->addOption(
36                name: 'o',
37                shortcut: 'o',
38                mode: InputOption::VALUE_REQUIRED,
39                description: 'Organization'
40            )
41            ->addOption(
42                name: 'c',
43                shortcut: 'c',
44                mode: InputOption::VALUE_REQUIRED,
45                description: 'Country name'
46            )
47            ->addOption(
48                name: 'st',
49                shortcut: 's',
50                mode: InputOption::VALUE_REQUIRED,
51                description: 'State'
52            )
53            ->addOption(
54                name: 'l',
55                shortcut: 'l',
56                mode: InputOption::VALUE_REQUIRED,
57                description: 'Locality'
58            )
59            ->addOption(
60                name: 'config-path',
61                shortcut: null,
62                mode: InputOption::VALUE_REQUIRED,
63                description: 'Config path'
64            );
65    }
66
67    #[\Override]
68    protected function execute(InputInterface $input, OutputInterface $output): int {
69        $names = [];
70        if (!$commonName = $input->getOption('cn')) {
71            throw new InvalidArgumentException('Invalid Comon Name');
72        }
73        if ($input->getOption('ou')) {
74            $names['OU'] = ['value' => $input->getOption('ou')];
75        }
76        if ($input->getOption('o')) {
77            $names['O'] = ['value' => $input->getOption('o')];
78        }
79        if ($input->getOption('c')) {
80            $names['C'] = ['value' => $input->getOption('c')];
81        }
82        if ($input->getOption('l')) {
83            $names['L'] = ['value' => $input->getOption('l')];
84        }
85        if ($input->getOption('st')) {
86            $names['ST'] = ['value' => $input->getOption('st')];
87        }
88        $this->installService->generate(
89            (string)$commonName,
90            'openssl',
91            $names,
92        );
93        return 0;
94    }
95}