diff -r 000000000000 -r 4eba9c11703f web/Zend/Service/Amazon/Ec2/Keypair.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/Zend/Service/Amazon/Ec2/Keypair.php Mon Dec 13 18:29:26 2010 +0100 @@ -0,0 +1,137 @@ +sendRequest($params); + $xpath = $response->getXPath(); + + $return = array(); + $return['keyName'] = $xpath->evaluate('string(//ec2:keyName/text())'); + $return['keyFingerprint'] = $xpath->evaluate('string(//ec2:keyFingerprint/text())'); + $return['keyMaterial'] = $xpath->evaluate('string(//ec2:keyMaterial/text())'); + + return $return; + } + + /** + * Returns information about key pairs available to you. If you specify + * key pairs, information about those key pairs is returned. Otherwise, + * information for all registered key pairs is returned. + * + * @param string|rarray $keyName Key pair IDs to describe. + * @return array + */ + public function describe($keyName = null) + { + $params = array(); + + $params['Action'] = 'DescribeKeyPairs'; + if(is_array($keyName) && !empty($keyName)) { + foreach($keyName as $k=>$name) { + $params['KeyName.' . ($k+1)] = $name; + } + } elseif($keyName) { + $params['KeyName.1'] = $keyName; + } + + $response = $this->sendRequest($params); + $xpath = $response->getXPath(); + + $nodes = $xpath->query('//ec2:keySet/ec2:item'); + + $return = array(); + foreach ($nodes as $k => $node) { + $item = array(); + $item['keyName'] = $xpath->evaluate('string(ec2:keyName/text())', $node); + $item['keyFingerprint'] = $xpath->evaluate('string(ec2:keyFingerprint/text())', $node); + + $return[] = $item; + unset($item); + } + + return $return; + } + + /** + * Deletes a key pair + * + * @param string $keyName Name of the key pair to delete. + * @throws Zend_Service_Amazon_Ec2_Exception + * @return boolean Return true or false from the deletion. + */ + public function delete($keyName) + { + $params = array(); + + $params['Action'] = 'DeleteKeyPair'; + + if(!$keyName) { + require_once 'Zend/Service/Amazon/Ec2/Exception.php'; + throw new Zend_Service_Amazon_Ec2_Exception('Invalid Key Name'); + } + + $params['KeyName'] = $keyName; + + $response = $this->sendRequest($params); + + $xpath = $response->getXPath(); + $success = $xpath->evaluate('string(//ec2:return/text())'); + + return ($success === "true"); + } +}