forked from plesk/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecResource.php
More file actions
148 lines (138 loc) · 6.01 KB
/
Copy pathExecResource.php
File metadata and controls
148 lines (138 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
namespace Docker\API\Resource;
use Docker\Custom\QueryParam;
use Docker\Custom\Resource;
class ExecResource extends Resource
{
/**
* Sets up an exec instance in a running container id.
*
* @param string $id Container name or id
* @param \Docker\API\Model\ExecConfig $execConfig Exec configuration
* @param array $parameters {
*
* @var string $Content-Type Content Type Header
* }
*
* @param string $fetch Fetch mode (object or response)
*
* @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\ExecCreateResult
*/
public function create($id, \Docker\API\Model\ExecConfig $execConfig, $parameters = [], $fetch = self::FETCH_OBJECT)
{
$queryParam = new QueryParam();
$queryParam->setDefault('Content-Type', 'application/json');
$queryParam->setHeaderParameters(['Content-Type']);
$url = '/containers/{id}/exec';
$url = str_replace('{id}', urlencode($id), $url);
$url = $url . ('?' . $queryParam->buildQueryString($parameters));
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters));
$body = $this->serializer->normalize($execConfig, 'json');
$request = $this->messageFactory->createRequest('POST', $url, $headers, $body);
$promise = $this->httpClient->sendAsyncRequest($request);
if (self::FETCH_PROMISE === $fetch) {
return $promise;
}
$response = $promise->wait();
if (self::FETCH_OBJECT == $fetch) {
if ('201' == $response->getStatusCode()) {
return $this->serializer->deserialize((string) $response->getBody(), 'Docker\\API\\Model\\ExecCreateResult', 'json');
}
}
return $response;
}
/**
* Starts a previously set up exec instance id. If detach is true, this API returns after starting the exec command. Otherwise, this API sets up an interactive session with the exec command.
*
* @param string $id Exec instance id
* @param \Docker\API\Model\ExecStartConfig $execStartConfig Exec configuration
* @param array $parameters {
*
* @var string $Content-Type Content Type Header
* }
*
* @param string $fetch Fetch mode (object or response)
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function start($id, \Docker\API\Model\ExecStartConfig $execStartConfig, $parameters = [], $fetch = self::FETCH_OBJECT)
{
$queryParam = new QueryParam();
$queryParam->setDefault('Content-Type', 'application/json');
$queryParam->setHeaderParameters(['Content-Type']);
$url = '/exec/{id}/start';
$url = str_replace('{id}', urlencode($id), $url);
$url = $url . ('?' . $queryParam->buildQueryString($parameters));
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters));
$body = $this->serializer->normalize($execStartConfig, 'json');
$request = $this->messageFactory->createRequest('POST', $url, $headers, $body);
$promise = $this->httpClient->sendAsyncRequest($request);
if (self::FETCH_PROMISE === $fetch) {
return $promise;
}
$response = $promise->wait();
return $response;
}
/**
* Resize the tty session used by the exec command id.
*
* @param string $id Exec instance id
* @param array $parameters {
*
* @var int $h Height of the tty session
* @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('h', null);
$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);
$promise = $this->httpClient->sendAsyncRequest($request);
if (self::FETCH_PROMISE === $fetch) {
return $promise;
}
$response = $promise->wait();
return $response;
}
/**
* Return low-level information about the exec command id.
*
* @param string $id Exec instance id
* @param array $parameters List of parameters
* @param string $fetch Fetch mode (object or response)
*
* @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\ExecCommand
*/
public function find($id, $parameters = [], $fetch = self::FETCH_OBJECT)
{
$queryParam = new QueryParam();
$url = '/exec/{id}/json';
$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('GET', $url, $headers, $body);
$promise = $this->httpClient->sendAsyncRequest($request);
if (self::FETCH_PROMISE === $fetch) {
return $promise;
}
$response = $promise->wait();
if (self::FETCH_OBJECT == $fetch) {
if ('200' == $response->getStatusCode()) {
return $this->serializer->deserialize((string) $response->getBody(), 'Docker\\API\\Model\\ExecCommand', 'json');
}
}
return $response;
}
}