|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Service_Console |
|
17 * @subpackage Exception |
|
18 * @version $Id$ |
|
19 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 */ |
|
22 |
|
23 |
|
24 /** |
|
25 * Certificate commands |
|
26 * |
|
27 * @category Zend |
|
28 * @package Zend_Service_WindowsAzure_CommandLine |
|
29 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
|
30 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
31 * |
|
32 * @command-handler certificate |
|
33 * @command-handler-description Windows Azure Certificate commands |
|
34 * @command-handler-header Windows Azure SDK for PHP |
|
35 * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) |
|
36 * @command-handler-footer Note: Parameters that are common across all commands can be stored |
|
37 * @command-handler-footer in two dedicated environment variables. |
|
38 * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on. |
|
39 * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate. |
|
40 * @command-handler-footer |
|
41 * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. |
|
42 * @command-handler-footer The parameter file is a simple INI file carrying one parameter |
|
43 * @command-handler-footer value per line. It accepts the same parameters as one can |
|
44 * @command-handler-footer use from the command line command. |
|
45 */ |
|
46 class Zend_Service_WindowsAzure_CommandLine_Certificate |
|
47 extends Zend_Service_Console_Command |
|
48 { |
|
49 /** |
|
50 * List certificates for a specified hosted service in a specified subscription. |
|
51 * |
|
52 * @command-name List |
|
53 * @command-description List certificates for a specified hosted service in a specified subscription. |
|
54 * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on. |
|
55 * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate. |
|
56 * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed. |
|
57 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --ServiceName|-sn Required. The name of the hosted service. |
|
58 * @command-example List certificates for service name "phptest": |
|
59 * @command-example List -sid:"<your_subscription_id>" -cert:"mycert.pem" -sn:"phptest" |
|
60 */ |
|
61 public function listCertificatesCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName) |
|
62 { |
|
63 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
64 $result = $client->listCertificates($serviceName); |
|
65 |
|
66 if (count($result) == 0) { |
|
67 echo 'No data to display.'; |
|
68 } |
|
69 foreach ($result as $object) { |
|
70 $this->_displayObjectInformation($object, array('Thumbprint', 'CertificateUrl', 'ThumbprintAlgorithm')); |
|
71 } |
|
72 } |
|
73 |
|
74 /** |
|
75 * Add a certificate for a specified hosted service in a specified subscription. |
|
76 * |
|
77 * @command-name Add |
|
78 * @command-description Add a certificate for a specified hosted service in a specified subscription. |
|
79 * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on. |
|
80 * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate. |
|
81 * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed. |
|
82 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --ServiceName|-sn Required. The name of the hosted service. |
|
83 * @command-parameter-for $certificateLocation Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --CertificateLocation Required. Path to the .pfx certificate to be added. |
|
84 * @command-parameter-for $certificatePassword Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --CertificatePassword Required. The password for the certificate that will be added. |
|
85 * @command-parameter-for $waitForOperation Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete? |
|
86 * @command-example Add certificates for service name "phptest": |
|
87 * @command-example Add -sid:"<your_subscription_id>" -cert:"mycert.pem" -sn:"phptest" --CertificateLocation:"cert.pfx" --CertificatePassword:"certpassword" |
|
88 */ |
|
89 public function addCertificateCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $certificateLocation, $certificatePassword, $waitForOperation = false) |
|
90 { |
|
91 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
92 $client->addCertificate($serviceName, $certificateLocation, $certificatePassword, 'pfx'); |
|
93 if ($waitForOperation) { |
|
94 $client->waitForOperation(); |
|
95 } |
|
96 echo $client->getLastRequestId(); |
|
97 } |
|
98 |
|
99 /** |
|
100 * Gets a certificate from a specified hosted service in a specified subscription. |
|
101 * |
|
102 * @command-name Get |
|
103 * @command-description Gets a certificate from a specified hosted service in a specified subscription. |
|
104 * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on. |
|
105 * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate. |
|
106 * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed. |
|
107 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --ServiceName|-sn Required. The name of the hosted service. |
|
108 * @command-parameter-for $thumbprint Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --CertificateThumbprint Required. The certificate thumbprint for which to retrieve the certificate. |
|
109 * @command-parameter-for $algorithm Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --CertificateAlgorithm Required. The certificate's algorithm. |
|
110 * @command-example Get certificate for service name "phptest": |
|
111 * @command-example Get -sid:"<your_subscription_id>" -cert:"mycert.pem" -sn:"phptest" --CertificateThumbprint:"<thumbprint>" --CertificateAlgorithm:"sha1" |
|
112 */ |
|
113 public function getCertificateCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $thumbprint, $algorithm = "sha1") |
|
114 { |
|
115 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
116 $result = $client->getCertificate($serviceName, $algorithm, $thumbprint); |
|
117 |
|
118 $this->_displayObjectInformation($result, array('Thumbprint', 'CertificateUrl', 'ThumbprintAlgorithm')); |
|
119 } |
|
120 |
|
121 /** |
|
122 * Gets a certificate property from a specified hosted service in a specified subscription. |
|
123 * |
|
124 * @command-name GetProperty |
|
125 * @command-description Gets a certificate property from a specified hosted service in a specified subscription. |
|
126 * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on. |
|
127 * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate. |
|
128 * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed. |
|
129 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --ServiceName|-sn Required. The name of the hosted service. |
|
130 * @command-parameter-for $thumbprint Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --CertificateThumbprint Required. The certificate thumbprint for which to retrieve the certificate. |
|
131 * @command-parameter-for $algorithm Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --CertificateAlgorithm Required. The certificate's algorithm. |
|
132 * @command-parameter-for $property Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Property|-prop Required. The property to retrieve for the certificate. |
|
133 * @command-example Get certificate for service name "phptest": |
|
134 * @command-example Get -sid:"<your_subscription_id>" -cert:"mycert.pem" -sn:"phptest" --CertificateThumbprint:"<thumbprint>" --CertificateAlgorithm:"sha1" |
|
135 */ |
|
136 public function getCertificatePropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $thumbprint, $algorithm = "sha1", $property) |
|
137 { |
|
138 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
139 $result = $client->getCertificate($serviceName, $algorithm, $thumbprint); |
|
140 |
|
141 printf("%s\r\n", $result->$property); |
|
142 } |
|
143 |
|
144 /** |
|
145 * Deletes a certificate from a specified hosted service in a specified subscription. |
|
146 * |
|
147 * @command-name Delete |
|
148 * @command-description Deletes a certificate from a specified hosted service in a specified subscription. |
|
149 * @command-parameter-for $subscriptionId Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --SubscriptionId|-sid Required. This is the Windows Azure Subscription Id to operate on. |
|
150 * @command-parameter-for $certificate Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --Certificate|-cert Required. This is the .pem certificate that user has uploaded to Windows Azure subscription as Management Certificate. |
|
151 * @command-parameter-for $certificatePassphrase Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Prompt --Passphrase|-p Required. The certificate passphrase. If not specified, a prompt will be displayed. |
|
152 * @command-parameter-for $serviceName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --ServiceName|-sn Required. The name of the hosted service. |
|
153 * @command-parameter-for $thumbprint Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --CertificateThumbprint Required. The certificate thumbprint for which to retrieve the certificate. |
|
154 * @command-parameter-for $algorithm Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --CertificateAlgorithm Required. The certificate's algorithm. |
|
155 * @command-parameter-for $waitForOperation Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --WaitFor|-w Optional. Wait for the operation to complete? |
|
156 * @command-example Get certificate for service name "phptest": |
|
157 * @command-example Get -sid:"<your_subscription_id>" -cert:"mycert.pem" -sn:"phptest" --CertificateThumbprint:"<thumbprint>" --CertificateAlgorithm:"sha1" |
|
158 */ |
|
159 public function deleteCertificateCommand($subscriptionId, $certificate, $certificatePassphrase, $serviceName, $thumbprint, $algorithm = "sha1", $waitForOperation = false) |
|
160 { |
|
161 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); |
|
162 $client->deleteCertificate($serviceName, $algorithm, $thumbprint); |
|
163 if ($waitForOperation) { |
|
164 $client->waitForOperation(); |
|
165 } |
|
166 echo $client->getLastRequestId(); |
|
167 } |
|
168 } |
|
169 |
|
170 Zend_Service_Console_Command::bootstrap($_SERVER['argv']); |