diff --git a/bin/acme b/bin/acme index bfa2cab..d4211d5 100755 --- a/bin/acme +++ b/bin/acme @@ -2,6 +2,7 @@ error("Please run this script via CLI!"); @@ -122,7 +122,9 @@ try { } } +$injector = new Injector; $injector->share($climate); +$injector->share(new AcmeFactory); $command = $injector->make($class); diff --git a/src/AcmeFactory.php b/src/AcmeFactory.php new file mode 100644 index 0000000..c037ada --- /dev/null +++ b/src/AcmeFactory.php @@ -0,0 +1,16 @@ +climate = $climate; + $this->acmeFactory = $acmeFactory; } public function execute(Manager $args) { @@ -77,7 +79,7 @@ class Issue implements Command { $this->climate->br(); - $acme = new AcmeService(new AcmeClient($server, $keyPair)); + $acme = $this->acmeFactory->build($server, $keyPair); $promises = []; foreach ($domains as $i => $domain) { diff --git a/src/Commands/Revoke.php b/src/Commands/Revoke.php index 10bdc42..1c4e2f3 100644 --- a/src/Commands/Revoke.php +++ b/src/Commands/Revoke.php @@ -4,8 +4,7 @@ namespace Kelunik\AcmeClient\Commands; use Amp\CoroutineResult; use Amp\File\FilesystemException; -use Kelunik\Acme\AcmeClient; -use Kelunik\Acme\AcmeService; +use Kelunik\AcmeClient\AcmeFactory; use Kelunik\AcmeClient\Stores\CertificateStore; use Kelunik\AcmeClient\Stores\KeyStore; use Kelunik\Certificate\Certificate; @@ -14,9 +13,11 @@ use League\CLImate\CLImate; class Revoke implements Command { private $climate; + private $acmeFactory; - public function __construct(CLImate $climate) { + public function __construct(CLImate $climate, AcmeFactory $acmeFactory) { $this->climate = $climate; + $this->acmeFactory = $acmeFactory; } public function execute(Manager $args) { @@ -30,7 +31,7 @@ class Revoke implements Command { $keyFile = \Kelunik\AcmeClient\serverToKeyname($server); $keyPair = (yield $keyStore->get("accounts/{$keyFile}.pem")); - $acme = new AcmeService(new AcmeClient($server, $keyPair), $keyPair); + $acme = $this->acmeFactory->build($server, $keyPair); $this->climate->br(); $this->climate->whisper(" Revoking certificate ..."); @@ -57,7 +58,7 @@ class Revoke implements Command { $this->climate->br(); $this->climate->info(" Certificate has been revoked."); - yield (new CertificateStore(\Kelunik\AcmeClient\normalizePath($args->get("storage")). "/certs/" . $keyFile))->delete($args->get("name")); + yield (new CertificateStore(\Kelunik\AcmeClient\normalizePath($args->get("storage")) . "/certs/" . $keyFile))->delete($args->get("name")); yield new CoroutineResult(0); } diff --git a/src/Commands/Setup.php b/src/Commands/Setup.php index 11017d3..99c1d8e 100644 --- a/src/Commands/Setup.php +++ b/src/Commands/Setup.php @@ -6,11 +6,10 @@ use Amp\CoroutineResult; use Amp\Dns\Record; use Amp\Dns\ResolutionException; use InvalidArgumentException; -use Kelunik\Acme\AcmeClient; use Kelunik\Acme\AcmeException; -use Kelunik\Acme\AcmeService; use Kelunik\Acme\OpenSSLKeyGenerator; use Kelunik\Acme\Registration; +use Kelunik\AcmeClient\AcmeFactory; use Kelunik\AcmeClient\Stores\KeyStore; use Kelunik\AcmeClient\Stores\KeyStoreException; use League\CLImate\Argument\Manager; @@ -18,9 +17,11 @@ use League\CLImate\CLImate; class Setup implements Command { private $climate; + private $acmeFactory; - public function __construct(CLImate $climate) { + public function __construct(CLImate $climate, AcmeFactory $acmeFactory) { $this->climate = $climate; + $this->acmeFactory = $acmeFactory; } public function execute(Manager $args) { @@ -53,7 +54,7 @@ class Setup implements Command { $this->climate->whisper(" Generated new private key with {$bits} bits."); } - $acme = new AcmeService(new AcmeClient($server, $keyPair), $keyPair); + $acme = $this->acmeFactory->build($server, $keyPair); $this->climate->whisper(" Registering with " . substr($server, 8) . " ...");