Failed Conditions
Push — v7 ( 809898...b3c0a6 )
by Florent
05:05
created

KeyFileLoaderCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 7
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Console\Command;
15
16
use Jose\Component\Core\JWKFactory;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
final class KeyFileLoaderCommand extends AbstractGeneratorCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
        $this
31
            ->setName('key:load:key')
32
            ->setDescription('Loads a key from a key file (JWK format)')
33
            ->addArgument('file', InputArgument::REQUIRED, 'Filename of the key.')
34
            ->addOption('secret', 's', InputOption::VALUE_OPTIONAL, 'Secret if the key is encrypted.', null);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $filename = $input->getArgument('file');
43
        $password = $input->getOption('secret');
44
        $args = $this->getOptions($input);
45
46
        $jwk = JWKFactory::createFromKeyFile($filename, $password, $args);
47
        $json = json_encode($jwk);
48
        $this->prepareOutput($input, $output, $json);
49
    }
50
}
51