Failed Conditions
Push — v7 ( 12d27f...276ae4 )
by Florent
03:49
created

KeyFileLoaderCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
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;
15
16
use Jose\Component\KeyManagement\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
/**
23
 * Class KeyFileLoaderCommand.
24
 */
25
final class KeyFileLoaderCommand extends AbstractGeneratorCommand
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function configure()
31
    {
32
        parent::configure();
33
        $this
34
            ->setName('key:load:key')
35
            ->setDescription('Loads a key from a key file (JWK format)')
36
            ->addArgument('file', InputArgument::REQUIRED, 'Filename of the key.')
37
            ->addOption('secret', 's', InputOption::VALUE_OPTIONAL, 'Secret if the key is encrypted.', null);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $filename = $input->getArgument('file');
46
        $password = $input->getOption('secret');
47
        $args = $this->getOptions($input);
48
49
        $jwk = JWKFactory::createFromKeyFile($filename, $password, $args);
50
        $this->prepareJsonOutput($input, $output, $jwk);
51
    }
52
}
53