Example #1
0
 /**
  * get the public hostname or IP of the instance
  * @throws Exception - if no public hostname or IP can be found
  * @return string - hostname or IP
  */
 public function getHost()
 {
     $host = $this->description['PublicDnsName'];
     if (!$host) {
         $data = new Model($this->description);
         $publicIps = $data->getPath('NetworkInterfaces/*/PrivateIpAddresses/*/Association/PublicIp');
         if (count($publicIps) > 0) {
             $host = $publicIps[0];
         }
     }
     if (!$host) {
         throw new \Exception(sprintf('No public hostname or IP can be found for this instance: %s', $this->id));
     }
     return $host;
 }
Example #2
0
 public function testFalseyKeysStillDescend()
 {
     $model = new Model(array('0' => array('a' => 'jar'), 1 => 'other'));
     $this->assertEquals('jar', $model->getPath('0/a'));
     $this->assertEquals('other', $model->getPath('1'));
 }
 /**
  * Extracts the value from the result using Collection::getPath. Also adds some additional logic for keys that need
  * to access n-1 indexes (e.g., ImportExport, Kinesis). The n-1 logic only works for the known cases. We will switch
  * to a jmespath implementation in the future to cover all cases
  *
  * @param Model  $result
  * @param string $key
  *
  * @return mixed|null
  */
 protected function getValueFromResult(Model $result, $key)
 {
     // Special handling for keys that need to access n-1 indexes
     if (strpos($key, '#') !== false) {
         $keyParts = explode('#', $key, 2);
         $items = $result->getPath(trim($keyParts[0], '/'));
         if ($items && is_array($items)) {
             $index = count($items) - 1;
             $key = strtr($key, array('#' => $index));
         }
     }
     // Get the value
     return $result->getPath($key);
 }
 /**
  * Check to see if the path of the output key is satisfied by the value
  *
  * @param Model  $model      Result model
  * @param string $key        Key to check
  * @param string $checkValue Compare the key to the value
  * @param bool   $all        Set to true to ensure all value match or false to only match one
  *
  * @return bool
  */
 protected function checkPath(Model $model, $key = null, $checkValue = array(), $all = true)
 {
     // If no key is set, then just assume true because the request succeeded
     if (!$key) {
         return true;
     }
     if (!($result = $model->getPath($key))) {
         return false;
     }
     $total = $matches = 0;
     foreach ((array) $result as $value) {
         $total++;
         foreach ((array) $checkValue as $check) {
             if ($value == $check) {
                 $matches++;
                 break;
             }
         }
     }
     // When matching all values, ensure that the match count matches the total count
     if ($all && $total != $matches) {
         return false;
     }
     return $matches > 0;
 }
Example #5
0
 /**
  * Creates a credentials object from the credential data return by an STS operation
  *
  * @param Model $result The result of an STS operation
  *
  * @return Credentials
  * @throws InvalidArgumentException if the result does not contain credential data
  */
 public function createCredentials(Model $result)
 {
     if (!$result->hasKey('Credentials')) {
         throw new InvalidArgumentException('The modeled result provided contained no credentials.');
     }
     return new Credentials($result->getPath('Credentials/AccessKeyId'), $result->getPath('Credentials/SecretAccessKey'), $result->getPath('Credentials/SessionToken'), $result->getPath('Credentials/Expiration'));
 }
 /**
  * {@inheritdoc}
  */
 protected function determineNextToken(Model $result)
 {
     $this->nextToken = null;
     // If the value of "more key" is true or there is no "more key" to check, then try to get the next token
     $moreKey = $this->get('more_key');
     if ($moreKey === null || $result->getPath($moreKey)) {
         // Get the token key to check
         if ($tokenKey = $this->get('token_key')) {
             // Get the next token's value. Works with multi-value tokens
             $getToken = function ($key) use($result) {
                 return $result->getPath((string) $key);
             };
             $this->nextToken = is_array($tokenKey) ? array_map($getToken, $tokenKey) : $getToken($tokenKey);
         }
     }
 }
Example #7
0
 /**
  * @param \Guzzle\Service\Resource\Model $resources
  * @return mixed
  */
 private function getHostFromDescribedInstances($resources)
 {
     $instances = $resources->getPath('Reservations/*/Instances');
     if (empty($instances)) {
         return;
     }
     $instanceToUse = null;
     foreach ($instances as $index => $instance) {
         if (!empty($instance['Tags'])) {
             foreach ($instance['Tags'] as $tag) {
                 if (!empty($this->testSuite) && $tag['Key'] === 'TestSuite' && $tag['Value'] === $this->testSuite) {
                     $instanceToUse = $instance;
                 }
             }
         }
     }
     if (empty($instanceToUse)) {
         $instanceToUse = array_shift($instances);
     }
     $host = $instanceToUse['PublicDnsName'];
     return $host;
 }