Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Commit

Permalink
Added console commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mduplouy committed Jan 29, 2016
1 parent 239b267 commit 57a0ee6
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 3 deletions.
16 changes: 16 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env php
<?php

require_once __DIR__.'/../vendor/autoload.php';

set_time_limit(0);

use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Application;
use Octopuce\Acme\Command\Certificate;

$input = new ArgvInput();

$app = new Application;
$app->add(new Certificate);
$app->run();
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"phpseclib/phpseclib": "^2.0",
"guzzlehttp/guzzle": "3.8.1",
"psr/log": "~1.0",
"symfony/finder": "2.8.2"
"symfony/finder": "2.8.2",
"symfony/console": "2.7.9"
},
"require-dev": {
"phpunit/phpunit": "4.8.*"
Expand Down
63 changes: 61 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/Octopuce/Acme/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Octopuce\Acme\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Octopuce\Acme\Client;

abstract class AbstractCommand extends Command
{
/**
* {@inheritDoc}
*/
protected function configure()
{
$this->addOption(
'config',
'c',
InputOption::VALUE_OPTIONAL,
'Config file to be read',
__DIR__.'/../../../config.php'
);
}

/**
* Get client instance
*
* @param array $config
*
* @return Client
*/
protected function getClient(array $config)
{
return new Client($config);
}
}
71 changes: 71 additions & 0 deletions src/Octopuce/Acme/Command/Certificate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Octopuce\Acme\Command;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Certificate extends AbstractCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();

$this
->setName('certificate')
->setDescription('Certificate operations')
->addArgument(
'action',
InputArgument::REQUIRED,
'Desired action get|sign|revoke|renew'
)
->addArgument(
'fqdn',
InputArgument::REQUIRED,
'Fully qualified domain name'
)
->addArgument(
'altnames',
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
'Alternative names for certificate (separate multiple with a space)'
);
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = require $input->getOption('config');
$client = $this->getClient($config);

$fqdn = $input->getArgument('fqdn');

switch ($input->getArgument('action'))
{
case 'get':
$text = $client->getCertificate($fqdn);
break;

case 'sign':
$text = $client->signCertificate($fqdn, $input->getArgument('altnames'));
break;

case 'revoke':
$text = $client->revokeCertificate($fqdn);
break;

case 'renew':
break;

default:
throw new \ÌnvalidArgmentException('action must be get, sign, revoke or renew');
}

$output->writeln($text);
}
}

0 comments on commit 57a0ee6

Please sign in to comment.