예제 #1
0
 /**
  * {@inheritdoc}
  *
  * @return \Psr\Http\Message\ResponseInterface|PushImageInfo[]|CreateImageStream
  */
 public function push($name, $parameters = [], $fetch = self::FETCH_OBJECT)
 {
     if (isset($parameters['X-Registry-Auth']) && $parameters['X-Registry-Auth'] instanceof AuthConfig) {
         $parameters['X-Registry-Auth'] = base64_encode($this->serializer->serialize($parameters['X-Registry-Auth'], 'json'));
     }
     $queryParam = new QueryParam();
     $queryParam->setDefault('tag', null);
     $queryParam->setDefault('X-Registry-Auth', null);
     $queryParam->setHeaderParameters(['X-Registry-Auth']);
     $url = 'http://localhost/images/{name}/push';
     $url = str_replace('{name}', $name, $url);
     $url = $url . ('?' . $queryParam->buildQueryString($parameters));
     $headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters));
     $body = $queryParam->buildFormDataString($parameters);
     $request = $this->messageFactory->createRequest('POST', $url, $headers, $body);
     $response = $this->httpClient->sendRequest($request);
     if (200 === $response->getStatusCode()) {
         if (self::FETCH_STREAM === $fetch) {
             return new PushStream($response->getBody(), $this->serializer);
         }
         if (self::FETCH_OBJECT === $fetch) {
             $pushImageInfoList = [];
             $stream = new PushStream($response->getBody(), $this->serializer);
             $stream->onFrame(function (PushImageInfo $pushImageInfo) use(&$pushImageInfoList) {
                 $pushImageInfoList[] = $pushImageInfo;
             });
             $stream->wait();
             return $pushImageInfoList;
         }
     }
     return $response;
 }
예제 #2
0
 /**
  * Inspect network.
  *
  * @param string $id         Network id or name
  * @param array  $parameters List of parameters
  * @param string $fetch      Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\Network
  */
 public function find($id, $parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $url = '/networks/{id}';
     $url = str_replace('{id}', $id, $url);
     $url = $url . ('?' . $queryParam->buildQueryString($parameters));
     $headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters));
     $body = $queryParam->buildFormDataString($parameters);
     $request = $this->messageFactory->createRequest('GET', $url, $headers, $body);
     $response = $this->httpClient->sendRequest($request);
     if (self::FETCH_OBJECT == $fetch) {
         if ('200' == $response->getStatusCode()) {
             return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\Network', 'json');
         }
     }
     return $response;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  *
  * @return \Psr\Http\Message\ResponseInterface|AttachWebsocketStream
  */
 public function attachWebsocket($id, $parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setDefault('logs', null);
     $queryParam->setDefault('stream', null);
     $queryParam->setDefault('stdin', null);
     $queryParam->setDefault('stdout', null);
     $queryParam->setDefault('stderr', null);
     $url = '/containers/{id}/attach/ws';
     $url = str_replace('{id}', $id, $url);
     $url = $url . ('?' . $queryParam->buildQueryString($parameters));
     $headers = array_merge(['Host' => 'localhost', 'Origin' => 'php://docker-php', 'Upgrade' => 'websocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Version' => '13', 'Sec-WebSocket-Key' => base64_encode(uniqid())], $queryParam->buildHeaders($parameters));
     $body = $queryParam->buildFormDataString($parameters);
     $request = $this->messageFactory->createRequest('GET', $url, $headers, $body);
     $response = $this->httpClient->sendRequest($request);
     if ($response->getStatusCode() == 101) {
         if ($fetch == self::FETCH_STREAM) {
             return new AttachWebsocketStream($response->getBody());
         }
     }
     return $response;
 }
예제 #4
0
 /**
  * Get container events from docker, either in real time via streaming, or via polling (using since).
  *
  * @param array $parameters List of parameters
  * 
  *     (int)since: Timestamp used for polling
  *     (int)until: Timestamp used for polling
  *     (string)filters: A json encoded value of the filters (a map[string][]string) to process on the event list.
  * @param string $fetch Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function getEvents($parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setDefault('since', null);
     $queryParam->setDefault('until', null);
     $queryParam->setDefault('filters', null);
     $url = '/events';
     $url = $url . ('?' . $queryParam->buildQueryString($parameters));
     $headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters));
     $body = $queryParam->buildFormDataString($parameters);
     $request = $this->messageFactory->createRequest('GET', $url, $headers, $body);
     $response = $this->httpClient->sendRequest($request);
     return $response;
 }
예제 #5
0
 /**
  * Retrieving information about files and folders in a container.
  *
  * @param string $id         The container id or name
  * @param array  $parameters List of parameters
  * 
  *     (string)path: Resource in the container’s filesystem to archive.
  * @param string $fetch Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function getArchiveInformation($id, $parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setRequired('path');
     $url = '/containers/{id}/archive';
     $url = str_replace('{id}', $id, $url);
     $url = $url . ('?' . $queryParam->buildQueryString($parameters));
     $headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters));
     $body = $queryParam->buildFormDataString($parameters);
     $request = $this->messageFactory->createRequest('HEAD', $url, $headers, $body);
     $response = $this->httpClient->sendRequest($request);
     return $response;
 }