Beispiel #1
0
 /**
  * @param array $options
  *
  * @return Service
  */
 private function getDefaultIdentityService(array $options) : Service
 {
     if (!isset($options['authUrl'])) {
         throw new \InvalidArgumentException("'authUrl' is a required option");
     }
     return Service::factory(new Client(['base_uri' => Utils::normalizeUrl($options['authUrl']), 'handler' => HandlerStack::create()]));
 }
Beispiel #2
0
 private function getSchema() : Schema
 {
     if (null === $this->jsonSchema) {
         $response = $this->execute($this->api->getImageSchema());
         $this->jsonSchema = new Schema(Utils::jsonDecode($response, false));
     }
     return $this->jsonSchema;
 }
Beispiel #3
0
 /**
  * {@inheritDoc}
  */
 public function populateFromResponse(ResponseInterface $response) : self
 {
     $entries = Utils::jsonDecode($response)['access']['serviceCatalog'];
     foreach ($entries as $entry) {
         $this->entries[] = $this->model(Entry::class, $entry);
     }
     return $this;
 }
 /**
  * Populates the current resource from a response object.
  *
  * @param ResponseInterface $response
  *
  * @return AbstractResource
  */
 public function populateFromResponse(ResponseInterface $response) : self
 {
     if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
         $json = Utils::jsonDecode($response);
         if (!empty($json)) {
             $this->populateFromArray(Utils::flattenJson($json, $this->resourceKey));
         }
     }
     return $this;
 }
Beispiel #5
0
 private function fetchResources()
 {
     if ($this->shouldNotSendAnotherRequest()) {
         return false;
     }
     $response = call_user_func($this->requestFn, $this->currentMarker);
     $json = Utils::flattenJson(Utils::jsonDecode($response), $this->resourcesKey);
     if ($response->getStatusCode() === 204 || empty($json)) {
         return false;
     }
     return $json;
 }
Beispiel #6
0
 public function parseMetadata(ResponseInterface $response) : array
 {
     $json = Utils::jsonDecode($response);
     return isset($json['metadata']) ? $json['metadata'] : [];
 }
Beispiel #7
0
 /**
  * Retrieves the public URI for this resource.
  *
  * @return \GuzzleHttp\Psr7\Uri
  */
 public function getPublicUri() : Uri
 {
     return Utils::addPaths($this->getHttpBaseUrl(), $this->containerName, $this->name);
 }
 public function extractMultipleInstances(ResponseInterface $response, string $key = null) : array
 {
     $key = $key ?: $this->getResourcesKey();
     $resourcesData = Utils::jsonDecode($response)[$key];
     $resources = [];
     foreach ($resourcesData as $resourceData) {
         $resources[] = $this->newInstance()->populateFromArray($resourceData);
     }
     return $resources;
 }
Beispiel #9
0
 public function parseMetadata(ResponseInterface $response) : array
 {
     return Utils::jsonDecode($response)['metadata'];
 }
Beispiel #10
0
 private function httpClient(string $baseUrl, HandlerStack $stack) : ClientInterface
 {
     $clientOptions = ['base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack];
     if (isset($this->globalOptions['requestOptions'])) {
         $clientOptions = array_merge($this->globalOptions['requestOptions'], $clientOptions);
     }
     return new Client($clientOptions);
 }
Beispiel #11
0
 public static function getAuthOptsV2()
 {
     $httpClient = new Client(['base_uri' => TransportUtils::normalizeUrl(getenv('OS_AUTH_URL')), 'handler' => HandlerStack::create()]);
     return ['authUrl' => getenv('OS_AUTH_URL'), 'region' => getenv('OS_REGION_NAME'), 'username' => getenv('OS_USERNAME'), 'password' => getenv('OS_PASSWORD'), 'tenantName' => getenv('OS_TENANT_NAME'), 'identityService' => Service::factory($httpClient)];
 }
Beispiel #12
0
 /**
  * {@inheritDoc}
  */
 public function populateFromResponse(ResponseInterface $response) : self
 {
     $this->populateFromArray(Utils::jsonDecode($response)['access']['token']);
     return $this;
 }
 /**
  * Load a token for the Compute Service
  *
  * @param String $opt serialized token
  *
  * @return void
  */
 public function loadComputeBackup($opt)
 {
     $options = $this->optionsGlobal['Common'];
     $options['catalogName'] = 'nova';
     $options['catalogType'] = 'compute';
     $options['region'] = 'RegionOne';
     $this->backup['Compute'] = $opt;
     $token = $this->unserializeToken($this->backup['Compute']['token']);
     $baseUrl = $this->backup['Compute']['baseUrl'];
     $stack = HandlerStack::create();
     $stack->push(Middleware::authHandler($options['authHandler'], $token));
     $this->addDebugMiddleware($options, $stack);
     $options['httpClient'] = new Client(['base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack]);
     $this->saveBackup('Compute', array('token' => $token, 'baseUrl' => $baseUrl));
     $this->optionsGlobal['Compute'] = $options;
 }
Beispiel #14
0
 public function test_it_adds_paths()
 {
     $uri = Utils::addPaths(uri_for('http://openstack.org/foo'), 'bar', 'baz', '1', '2');
     $this->assertInstanceOf(Uri::class, $uri);
     $this->assertEquals(uri_for('http://openstack.org/foo/bar/baz/1/2'), $uri);
 }