Scalr\Service\Aws\Ec2\V20150415\Ec2Api::describeKeyPairs PHP Method

describeKeyPairs() public method

Describes one or more of your key pairs.
public describeKeyPairs ( ListDataType $keyNameList = null, array $filter = null ) : Scalr\Service\Aws\Ec2\DataType\KeyPairList
$keyNameList Scalr\Service\Aws\DataType\ListDataType optional The list of the names
$filter array optional Array of the key => value properties.
return Scalr\Service\Aws\Ec2\DataType\KeyPairList Returns KeyPairList on success
    public function describeKeyPairs(ListDataType $keyNameList = null, array $filter = null)
    {
        //Filter parameter is excluded here and can be added in the future version of method.
        $result = null;
        $options = [];
        if ($keyNameList !== null) {
            $options = array_merge($options, $keyNameList->getQueryArrayBare('KeyName'));
        }
        if (!empty($filter)) {
            //Here we use list from another data set just to avoid duplicates.
            $arr = [];
            foreach ($filter as $k => $v) {
                array_push($arr, ['name' => new KeyPairFilterNameType((string) $k), 'value' => (string) $v]);
            }
            $flt = new KeyPairFilterList($arr);
            $options = array_merge($options, $flt->getQueryArrayBare('Filter'));
        }
        $response = $this->client->call(ucfirst(__FUNCTION__), $options);
        if ($response->getError() === false) {
            $sxml = simplexml_load_string($response->getRawContent());
            $response = null;
            $result = new KeyPairList();
            $result->setEc2($this->ec2);
            $result->setRequestId($sxml->requestId);
            if (isset($sxml->keySet->item)) {
                foreach ($sxml->keySet->item as $v) {
                    $item = new KeyPairData();
                    $item->setEc2($this->ec2);
                    $item->keyName = (string) $v->keyName;
                    $item->keyFingerprint = (string) $v->keyFingerprint;
                    $result->append($item);
                    unset($item);
                }
            }
        }
        return $result;
    }
Ec2Api