File indexing completed on 2025-01-12 05:22:24
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Service_Console 0017 * @subpackage Exception 0018 * @version $Id$ 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 */ 0022 0023 /** 0024 * @see Zend_Service_Console_Command 0025 */ 0026 // require_once 'Zend/Service/Console/Command.php'; 0027 0028 /** 0029 * @see Zend_Service_WindowsAzure_Management_Client 0030 */ 0031 // require_once 'Zend/Service/WindowsAzure/Management/Client.php'; 0032 0033 /** 0034 * Storage commands 0035 * 0036 * @category Zend 0037 * @package Zend_Service_WindowsAzure_CommandLine 0038 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0039 * @license http://framework.zend.com/license/new-bsd New BSD License 0040 * 0041 * @command-handler storage 0042 * @command-handler-description Windows Azure Storage commands 0043 * @command-handler-header Windows Azure SDK for PHP 0044 * @command-handler-header Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) 0045 * @command-handler-footer Note: Parameters that are common across all commands can be stored 0046 * @command-handler-footer in two dedicated environment variables. 0047 * @command-handler-footer - SubscriptionId: The Windows Azure Subscription Id to operate on. 0048 * @command-handler-footer - Certificate The Windows Azure .cer Management Certificate. 0049 * @command-handler-footer 0050 * @command-handler-footer All commands support the --ConfigurationFile or -F parameter. 0051 * @command-handler-footer The parameter file is a simple INI file carrying one parameter 0052 * @command-handler-footer value per line. It accepts the same parameters as one can 0053 * @command-handler-footer use from the command line command. 0054 */ 0055 class Zend_Service_WindowsAzure_CommandLine_Storage 0056 extends Zend_Service_Console_Command 0057 { 0058 /** 0059 * List storage accounts for a specified subscription. 0060 * 0061 * @command-name ListAccounts 0062 * @command-description List storage accounts for a specified subscription. 0063 * @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. 0064 * @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. 0065 * @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. 0066 * @command-example List storage accounts for subscription: 0067 * @command-example ListAccounts -sid:"<your_subscription_id>" -cert:"mycert.pem" 0068 */ 0069 public function listAccountsCommand($subscriptionId, $certificate, $certificatePassphrase) 0070 { 0071 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0072 $result = $client->listStorageAccounts(); 0073 0074 if (count($result) == 0) { 0075 echo 'No data to display.'; 0076 } 0077 foreach ($result as $object) { 0078 $this->_displayObjectInformation($object, array('ServiceName', 'Url')); 0079 } 0080 } 0081 0082 /** 0083 * Get storage account properties. 0084 * 0085 * @command-name GetProperties 0086 * @command-description Get storage account properties. 0087 * @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. 0088 * @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. 0089 * @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. 0090 * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on. 0091 * @command-example Get storage account properties for account "phptest": 0092 * @command-example GetProperties -sid:"<your_subscription_id>" -cert:"mycert.pem" 0093 * @command-example --AccountName:"phptest" 0094 */ 0095 public function getPropertiesCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName) 0096 { 0097 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0098 $result = $client->getStorageAccountProperties($accountName); 0099 0100 $this->_displayObjectInformation($result, array('ServiceName', 'Label', 'AffinityGroup', 'Location')); 0101 } 0102 0103 /** 0104 * Get storage account property. 0105 * 0106 * @command-name GetProperty 0107 * @command-description Get storage account property. 0108 * @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. 0109 * @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. 0110 * @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. 0111 * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on. 0112 * @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 storage account. 0113 * @command-example Get storage account property "Url" for account "phptest": 0114 * @command-example GetProperty -sid:"<your_subscription_id>" -cert:"mycert.pem" 0115 * @command-example --AccountName:"phptest" --Property:Url 0116 */ 0117 public function getPropertyCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $property) 0118 { 0119 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0120 $result = $client->getStorageAccountProperties($accountName); 0121 0122 printf("%s\r\n", $result->$property); 0123 } 0124 0125 /** 0126 * Get storage account keys. 0127 * 0128 * @command-name GetKeys 0129 * @command-description Get storage account keys. 0130 * @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. 0131 * @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. 0132 * @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. 0133 * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on. 0134 * @command-example Get storage account keys for account "phptest": 0135 * @command-example GetKeys -sid:"<your_subscription_id>" -cert:"mycert.pem" 0136 * @command-example --AccountName:"phptest" 0137 */ 0138 public function getKeysCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName) 0139 { 0140 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0141 $result = $client->getStorageAccountKeys($accountName); 0142 0143 $this->_displayObjectInformation((object)array('Key' => 'primary', 'Value' => $result[0]), array('Key', 'Value')); 0144 $this->_displayObjectInformation((object)array('Key' => 'secondary', 'Value' => $result[1]), array('Key', 'Value')); 0145 } 0146 0147 /** 0148 * Get storage account key. 0149 * 0150 * @command-name GetKey 0151 * @command-description Get storage account key. 0152 * @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. 0153 * @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. 0154 * @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. 0155 * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on. 0156 * @command-parameter-for $key Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Key|-k Optional. Specifies the key to regenerate (primary|secondary). If omitted, primary key is used as the default. 0157 * @command-example Get primary storage account key for account "phptest": 0158 * @command-example GetKey -sid:"<your_subscription_id>" -cert:"mycert.pem" 0159 * @command-example --AccountName:"phptest" -Key:primary 0160 */ 0161 public function getKeyCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $key = 'primary') 0162 { 0163 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0164 $result = $client->getStorageAccountKeys($accountName); 0165 0166 if (strtolower($key) == 'secondary') { 0167 printf("%s\r\n", $result[1]); 0168 } 0169 printf("%s\r\n", $result[0]); 0170 } 0171 0172 /** 0173 * Regenerate storage account keys. 0174 * 0175 * @command-name RegenerateKeys 0176 * @command-description Regenerate storage account keys. 0177 * @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. 0178 * @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. 0179 * @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. 0180 * @command-parameter-for $accountName Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile|Zend_Service_Console_Command_ParameterSource_Env --AccountName Required. The storage account name to operate on. 0181 * @command-parameter-for $key Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_ConfigFile --Key|-k Optional. Specifies the key to regenerate (primary|secondary). If omitted, primary key is used as the default. 0182 * @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? 0183 * @command-example Regenerate secondary key for account "phptest": 0184 * @command-example RegenerateKeys -sid:"<your_subscription_id>" -cert:"mycert.pem" 0185 * @command-example --AccountName:"phptest" -Key:secondary 0186 */ 0187 public function regenerateKeysCommand($subscriptionId, $certificate, $certificatePassphrase, $accountName, $key = 'primary', $waitForOperation = false) 0188 { 0189 $client = new Zend_Service_WindowsAzure_Management_Client($subscriptionId, $certificate, $certificatePassphrase); 0190 $client->regenerateStorageAccountKey($accountName, $key); 0191 if ($waitForOperation) { 0192 $client->waitForOperation(); 0193 } 0194 echo $client->getLastRequestId(); 0195 } 0196 } 0197 0198 Zend_Service_Console_Command::bootstrap($_SERVER['argv']);