Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  *
  * @return \Psr\Http\Message\ResponseInterface|AttachWebsocketStream
  */
 public function attachWebsocket($id, $parameters = [], $fetch = self::FETCH_STREAM)
 {
     $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;
 }
Exemplo n.º 3
0
 /**
  * Resize the tty session used by the exec command id.
  *
  * @param string $id         Exec instance id
  * @param array  $parameters {
  *
  *     @var int $w Width of the tty session
  * }
  *
  * @param string $fetch Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function resize($id, $parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setDefault('w', null);
     $url = '/exec/{id}/resize';
     $url = str_replace('{id}', urlencode($id), $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);
     return $response;
 }
Exemplo n.º 4
0
 /**
  * List volumes.
  *
  * @param array $parameters {
  *
  *     @var string $filters JSON encoded value of the filters (a map[string][]string) to process on the volumes list
  * }
  *
  * @param string $fetch Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\VolumeList
  */
 public function findAll($parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setDefault('filters', null);
     $url = '/volumes';
     $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((string) $response->getBody(), 'Docker\\API\\Model\\VolumeList', 'json');
         }
     }
     return $response;
 }
Exemplo n.º 5
0
 /**
  * Upload a tar archive to be extracted to a path in the filesystem of container id.
  *
  * @param string $id          The container id or name
  * @param string $inputStream The input stream must be a tar archive compressed with one of the following algorithms: identity (no compression), gzip, bzip2, xz.
  * @param array  $parameters  {
  *
  *     @var string $path Path to a directory in the container to extract the archive’s contents into.
  *     @var string $noOverwriteDirNonDir If “1”, “true”, or “True” then it will be an error if unpacking the given content would cause an existing directory to be replaced with a non-directory and vice versa.
  * }
  *
  * @param string $fetch Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function putArchive($id, $inputStream, $parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setRequired('path');
     $queryParam->setDefault('noOverwriteDirNonDir', null);
     $url = '/containers/{id}/archive';
     $url = str_replace('{id}', urlencode($id), $url);
     $url = $url . ('?' . $queryParam->buildQueryString($parameters));
     $headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters));
     $body = $inputStream;
     $request = $this->messageFactory->createRequest('PUT', $url, $headers, $body);
     $response = $this->httpClient->sendRequest($request);
     return $response;
 }
Exemplo n.º 6
0
 /**
  * Get a tarball containing all images and metadata for one or more repositories.
  *
  * @param array $parameters {
  *
  *     @var array $names Image names to filter
  * }
  *
  * @param string $fetch Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function saveAll($parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setDefault('names', null);
     $url = '/images/get';
     $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;
 }
Exemplo n.º 7
0
 /**
  * Disconnect a container to a network.
  *
  * @param string                                $id         Network id or name
  * @param \Docker\API\Model\ContainerDisconnect $container  Container
  * @param array                                 $parameters {
  *
  *     @var string $Content-Type Content Type of input
  * }
  *
  * @param string $fetch Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function disconnect($id, \Docker\API\Model\ContainerDisconnect $container, $parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setDefault('Content-Type', 'application/json');
     $queryParam->setHeaderParameters(['Content-Type']);
     $url = '/networks/{id}/disconnect';
     $url = str_replace('{id}', urlencode($id), $url);
     $url = $url . ('?' . $queryParam->buildQueryString($parameters));
     $headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters));
     $body = $this->serializer->serialize($container, 'json');
     $request = $this->messageFactory->createRequest('POST', $url, $headers, $body);
     $response = $this->httpClient->sendRequest($request);
     return $response;
 }
Exemplo n.º 8
0
 /**
  * @param array $parameters {
  *
  *     @var string $testString
  *     @var int $testInteger
  *     @var float $testFloat
  *     @var array $testArray
  *     @var string $testRequired
  *     @var string $testDefault
  * }
  *
  * @param string $fetch Fetch mode (object or response)
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function testFormParameters($parameters = [], $fetch = self::FETCH_OBJECT)
 {
     $queryParam = new QueryParam();
     $queryParam->setDefault('testString', null);
     $queryParam->setFormParameters(['testString']);
     $queryParam->setDefault('testInteger', null);
     $queryParam->setFormParameters(['testInteger']);
     $queryParam->setDefault('testFloat', null);
     $queryParam->setFormParameters(['testFloat']);
     $queryParam->setDefault('testArray', null);
     $queryParam->setFormParameters(['testArray']);
     $queryParam->setRequired('testRequired');
     $queryParam->setFormParameters(['testRequired']);
     $queryParam->setDefault('testDefault', 'test');
     $queryParam->setFormParameters(['testDefault']);
     $url = '/test-form';
     $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);
     return $response;
 }