-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5770196
Showing
11 changed files
with
391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
webservices.xml | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2011 Gordon Franke, https://github.com/gimler <info@nevalon.de> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Pazure | ||
============ | ||
|
||
Pazure is a command line tool to interact with the Azue API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "pazure/pazure", | ||
"description": "Pazure is a command line tool to interact with the Azue API.", | ||
"keywords": ["framework", "azure", "api"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Gordon Franke", | ||
"email": "info@nevalon.de" | ||
}, | ||
{ | ||
"name": "Pazure Community", | ||
"homepage": "https://github.com/gimler/pazure/contributors" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.2", | ||
"pazure/guzzle-azure": "dev-master", | ||
"cilex/cilex": "dev-master" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Cilex": "src/", | ||
"Pazure": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$app = new \Cilex\Application('Pazure'); | ||
|
||
$app->command(new \Pazure\Command\Certificates\ListCommand()); | ||
$app->command(new \Pazure\Command\Certificates\AddCommand()); | ||
$app->command(new \Pazure\Command\Certificates\GetCommand()); | ||
$app->command(new \Pazure\Command\Certificates\DeleteCommand()); | ||
|
||
$app->command(new \Pazure\Command\Locations\ListCommand()); | ||
|
||
$app->register(new \Cilex\Provider\GuzzleServiceProvider(), array('guzzle.configs' => __DIR__.'/webservices.xml')); | ||
|
||
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Cilex framework. | ||
* | ||
* (c) Mike van Riel <mike.vanriel@naenius.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cilex\Provider; | ||
|
||
use Cilex\Application; | ||
use Cilex\ServiceProviderInterface; | ||
|
||
use Guzzle\Service\Builder\ServiceBuilder; | ||
|
||
/** | ||
* Guzzle Provider. | ||
* | ||
* @author Gordon Franke <info@nevalon.de> | ||
*/ | ||
class GuzzleServiceProvider implements ServiceProviderInterface | ||
{ | ||
public function register(Application $app) | ||
{ | ||
$app['guzzle'] = $app->share(function () use ($app) | ||
{ | ||
$serviceBuilder = ServiceBuilder::factory($app['guzzle.configs']); | ||
|
||
return $serviceBuilder; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Pazure. | ||
* | ||
* (c) Gordon Franke <info@nevalon.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pazure\Command\Certificates; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use Cilex\Command\Command; | ||
|
||
use Guzzle\Http\Exception\ClientErrorResponseException; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Deletes a certificate from the list of management certificates. | ||
* | ||
* @author Gordon Franke <info@nevalon.de> | ||
*/ | ||
class DeleteCommand extends Command | ||
{ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('managment:certificates:delete') | ||
->setDescription('Delete Management Certificate') | ||
->setDefinition(array( | ||
new InputArgument( | ||
'thumbprint', InputArgument::REQUIRED | ||
) | ||
)); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$command = $this->getService('guzzle') | ||
->get('azure') | ||
->getCommand('certificates.delete', array('thumbprint' => $input->getArgument('thumbprint'))); | ||
|
||
try { | ||
$result = $command->execute(); | ||
} catch (ClientErrorResponseException $e) { | ||
if (404 === $e->getResponse()->getStatusCode()) { | ||
throw new Exception('Invalid certificate thumbprint'); | ||
} | ||
|
||
throw $e; | ||
} | ||
|
||
$output->writeln('<info>Successfully delete certificate</info>'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Pazure. | ||
* | ||
* (c) Gordon Franke <info@nevalon.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pazure\Command\Certificates; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use Cilex\Command\Command; | ||
|
||
use Guzzle\Http\Exception\ClientErrorResponseException; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Gets information about the management certificate with the specified thumbprint. | ||
* | ||
* @author Gordon Franke <info@nevalon.de> | ||
*/ | ||
class GetCommand extends Command | ||
{ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('managment:certificates:get') | ||
->setDescription('Get Management Certificate') | ||
->setDefinition(array( | ||
new InputArgument( | ||
'thumbprint', InputArgument::REQUIRED | ||
) | ||
)); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$command = $this->getService('guzzle') | ||
->get('azure') | ||
->getCommand('certificates.get', array('thumbprint' => $input->getArgument('thumbprint'))); | ||
|
||
try { | ||
$certificate = $command->execute(); | ||
} catch (ClientErrorResponseException $e) { | ||
if (404 === $e->getResponse()->getStatusCode()) { | ||
throw new Exception($e->getResponse()); | ||
} | ||
|
||
throw $e; | ||
} | ||
|
||
//TODO: move to method share with list command | ||
$certDer = base64_decode((string) $certificate->SubscriptionCertificateData); | ||
$certPem = $this->der2pem($certDer); | ||
$certData = openssl_x509_parse($certPem); | ||
|
||
//TODO: seperate each entry free line, and bold headline? | ||
//TODO: add valid info in green color | ||
$output->writeln(sprintf('<comment>Id: %s</comment>', $certificate->SubscriptionCertificateThumbprint)); | ||
$output->writeln(sprintf('Created: %s', $certificate->Created)); | ||
|
||
$properties = array( | ||
'C' => 'Country Name', | ||
'ST' => 'State or Province Name', | ||
'L' => 'Locality Name', | ||
'O' => 'Organization Name', | ||
'OU' => 'Organizational Unit Name', | ||
'CN' => 'Common Name', | ||
'emailAddress' => 'E-Mail-Address' | ||
); | ||
foreach ($properties as $key => $text) { | ||
if (isset($certData['subject'][$key])) { | ||
$output->writeln(sprintf('%s: %s', $text, $certData['subject'][$key])); | ||
} | ||
} | ||
} | ||
|
||
//TODO: move to global helper service | ||
function der2pem($der_data) { | ||
$pem = chunk_split(base64_encode($der_data), 64, "\n"); | ||
$pem = "-----BEGIN CERTIFICATE-----\n".$pem."-----END CERTIFICATE-----\n"; | ||
|
||
return $pem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Pazure. | ||
* | ||
* (c) Gordon Franke <info@nevalon.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pazure\Command\Certificates; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use Cilex\Command\Command; | ||
|
||
/** | ||
* Lists and returns basic information about all of the management certificates associated with the specified subscription. | ||
* | ||
* @author Gordon Franke <info@nevalon.de> | ||
*/ | ||
class ListCommand extends Command | ||
{ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('managment:certificates:list') | ||
->setDescription('List Management Certificates'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$command = $this->getService('guzzle') | ||
->get('azure') | ||
->getCommand('certificates.list'); | ||
$certificates = $command->execute(); | ||
|
||
foreach ($certificates as $certificate) { | ||
//TODO: move to method share with list command | ||
$certDer = base64_decode((string) $certificate->SubscriptionCertificateData); | ||
$certPem = $this->der2pem($certDer); | ||
$certData = openssl_x509_parse($certPem); | ||
|
||
//TODO: seperate each entry free line, and bold headline? | ||
//TODO: add valid info in green color | ||
$output->writeln(sprintf('<comment>Id: %s</comment>', $certificate->SubscriptionCertificateThumbprint)); | ||
$output->writeln(sprintf('Created: %s', $certificate->Created)); | ||
|
||
$properties = array( | ||
'C' => 'Country Name', | ||
'ST' => 'State or Province Name', | ||
'L' => 'Locality Name', | ||
'O' => 'Organization Name', | ||
'OU' => 'Organizational Unit Name', | ||
'CN' => 'Common Name', | ||
'emailAddress' => 'E-Mail-Address' | ||
); | ||
foreach ($properties as $key => $text) { | ||
if (isset($certData['subject'][$key])) { | ||
$output->writeln(sprintf('%s: %s', $text, $certData['subject'][$key])); | ||
} | ||
} | ||
|
||
$output->writeln(''); | ||
} | ||
} | ||
|
||
//TODO: move to global helper service | ||
function der2pem($der_data) { | ||
$pem = chunk_split(base64_encode($der_data), 64, "\n"); | ||
$pem = "-----BEGIN CERTIFICATE-----\n".$pem."-----END CERTIFICATE-----\n"; | ||
|
||
return $pem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Pazure. | ||
* | ||
* (c) Gordon Franke <info@nevalon.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pazure\Command\Locations; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use Cilex\Command\Command; | ||
|
||
/** | ||
* The List Locations operation lists all of the data center locations that are valid for your subscription. | ||
* | ||
* @author Gordon Franke <info@nevalon.de> | ||
*/ | ||
class ListCommand extends Command | ||
{ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('locations:list') | ||
->setDescription('List data center locations'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$command = $this->getService('guzzle') | ||
->get('azure') | ||
->getCommand('locations.list'); | ||
$locations = $command->execute(); | ||
|
||
foreach ($locations as $location) { | ||
$output->writeln(sprintf('<comment>Name: %s</comment>', $location->Name)); | ||
$output->writeln(sprintf('Display name: %s', $location->DisplayName)); | ||
|
||
$services = current($location->AvailableServices); | ||
$output->writeln(sprintf('Services: %s', implode(', ', $services))); | ||
|
||
$output->writeln(''); | ||
} | ||
} | ||
} |
Oops, something went wrong.