Completed
Push — 1.x ( 48ee65...5c55fc )
by Joel
03:10
created

ImageResource::commit()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 18

Duplication

Lines 23
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 23
loc 23
rs 9.0857
cc 3
eloc 18
nc 3
nop 3
1
<?php
2
3
namespace Docker\API\Resource;
4
5
use Joli\Jane\Swagger\Client\QueryParam;
6
use Joli\Jane\Swagger\Client\Resource;
7
8
class ImageResource extends Resource
9
{
10
    /**
11
     * List Images.
12
     * 
13
     * @param array  $parameters List of parameters
14
     * @param string $fetch      Fetch mode (object or response)
15
     *
16
     * @return \Psr\Http\Message\ResponseInterface
17
     */
18
    public function findAll($parameters = [], $fetch = self::FETCH_OBJECT)
19
    {
20
        $queryParam = new QueryParam();
21
        $queryParam->setDefault('all', false);
22
        $queryParam->setDefault('filters', null);
23
        $queryParam->setDefault('filter', null);
24
        $queryParam->setDefault('digests', null);
25
        $url      = sprintf('/v1.21/images/json?%s', $queryParam->buildQueryString($parameters));
26
        $request  = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null);
27
        $request  = $request->withHeader('Host', 'localhost');
28
        $response = $this->httpClient->sendRequest($request);
29
        if (self::FETCH_RESPONSE == $fetch) {
30
            return $response;
31
        }
32
        if ('200' == $response->getStatusCode()) {
33
            return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ImageItem[]', 'json');
34
        }
35
36
        return $response;
37
    }
38
39
    /**
40
     * Build an image from Dockerfile via stdin.
41
     * 
42
     * @param mixed  $inputStream The input stream must be a tar archive compressed with one of the following algorithms: identity (no compression), gzip, bzip2, xz.
43
     * @param array  $parameters  List of parameters
44
     * @param string $fetch       Fetch mode (object or response)
45
     *
46
     * @return \Psr\Http\Message\ResponseInterface
47
     */
48
    public function build($inputStream, $parameters = [], $fetch = self::FETCH_OBJECT)
49
    {
50
        $queryParam = new QueryParam();
51
        $queryParam->setDefault('dockerfile', null);
52
        $queryParam->setDefault('t', null);
53
        $queryParam->setDefault('remote', null);
54
        $queryParam->setDefault('q', false);
55
        $queryParam->setDefault('nocache', false);
56
        $queryParam->setDefault('pull', null);
57
        $queryParam->setDefault('rm', true);
58
        $queryParam->setDefault('forcerm', false);
59
        $queryParam->setDefault('Content-type', 'application/tar');
60
        $queryParam->setDefault('X-Registry-Config', null);
61
        $url      = sprintf('/v1.21/build?%s', $queryParam->buildQueryString($parameters));
62
        $request  = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), $inputStream);
63
        $request  = $request->withHeader('Host', 'localhost');
64
        $response = $this->httpClient->sendRequest($request);
65
        if (self::FETCH_RESPONSE == $fetch) {
66
            return $response;
67
        }
68
69
        return $response;
70
    }
71
72
    /**
73
     * Create an image either by pulling it from the registry or by importing it.
74
     * 
75
     * @param array  $parameters List of parameters
76
     * @param string $fetch      Fetch mode (object or response)
77
     *
78
     * @return \Psr\Http\Message\ResponseInterface
79
     */
80 View Code Duplication
    public function create($parameters = [], $fetch = self::FETCH_OBJECT)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        $queryParam = new QueryParam();
83
        $queryParam->setDefault('fromImage', null);
84
        $queryParam->setDefault('fromSrc', null);
85
        $queryParam->setDefault('repo', null);
86
        $queryParam->setDefault('tag', null);
87
        $queryParam->setDefault('X-Registry-Config', null);
88
        $url      = sprintf('/v1.21/images/create?%s', $queryParam->buildQueryString($parameters));
89
        $request  = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null);
90
        $request  = $request->withHeader('Host', 'localhost');
91
        $response = $this->httpClient->sendRequest($request);
92
        if (self::FETCH_RESPONSE == $fetch) {
93
            return $response;
94
        }
95
96
        return $response;
97
    }
98
99
    /**
100
     * Return low-level information on the image name.
101
     * 
102
     * @param array  $parameters List of parameters
103
     * @param string $fetch      Fetch mode (object or response)
104
     *
105
     * @return \Psr\Http\Message\ResponseInterface
106
     */
107
    public function find($parameters = [], $fetch = self::FETCH_OBJECT)
108
    {
109
        $queryParam = new QueryParam();
110
        $url        = sprintf('/v1.21/images/{name}/json?%s', $queryParam->buildQueryString($parameters));
111
        $request    = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null);
112
        $request    = $request->withHeader('Host', 'localhost');
113
        $response   = $this->httpClient->sendRequest($request);
114
        if (self::FETCH_RESPONSE == $fetch) {
115
            return $response;
116
        }
117
        if ('200' == $response->getStatusCode()) {
118
            return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\Image', 'json');
119
        }
120
121
        return $response;
122
    }
123
124
    /**
125
     * Return the history of the image name.
126
     * 
127
     * @param array  $parameters List of parameters
128
     * @param string $fetch      Fetch mode (object or response)
129
     *
130
     * @return \Psr\Http\Message\ResponseInterface
131
     */
132
    public function history($parameters = [], $fetch = self::FETCH_OBJECT)
133
    {
134
        $queryParam = new QueryParam();
135
        $url        = sprintf('/v1.21/images/{name}/history?%s', $queryParam->buildQueryString($parameters));
136
        $request    = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null);
137
        $request    = $request->withHeader('Host', 'localhost');
138
        $response   = $this->httpClient->sendRequest($request);
139
        if (self::FETCH_RESPONSE == $fetch) {
140
            return $response;
141
        }
142
        if ('200' == $response->getStatusCode()) {
143
            return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ImageHistoryItem[]', 'json');
144
        }
145
146
        return $response;
147
    }
148
149
    /**
150
     * Push the image name on the registry.
151
     * 
152
     * @param array  $parameters List of parameters
153
     * @param string $fetch      Fetch mode (object or response)
154
     *
155
     * @return \Psr\Http\Message\ResponseInterface
156
     */
157 View Code Duplication
    public function push($parameters = [], $fetch = self::FETCH_OBJECT)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $queryParam = new QueryParam();
160
        $queryParam->setDefault('tag', null);
161
        $queryParam->setDefault('X-Registry-Auth', null);
162
        $url      = sprintf('/v1.21/images/{name}/push?%s', $queryParam->buildQueryString($parameters));
163
        $request  = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null);
164
        $request  = $request->withHeader('Host', 'localhost');
165
        $response = $this->httpClient->sendRequest($request);
166
        if (self::FETCH_RESPONSE == $fetch) {
167
            return $response;
168
        }
169
170
        return $response;
171
    }
172
173
    /**
174
     * Tag the image name into a repository.
175
     * 
176
     * @param array  $parameters List of parameters
177
     * @param string $fetch      Fetch mode (object or response)
178
     *
179
     * @return \Psr\Http\Message\ResponseInterface
180
     */
181 View Code Duplication
    public function tag($parameters = [], $fetch = self::FETCH_OBJECT)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
182
    {
183
        $queryParam = new QueryParam();
184
        $queryParam->setDefault('repo', null);
185
        $queryParam->setDefault('force', null);
186
        $queryParam->setDefault('tag', null);
187
        $url      = sprintf('/v1.21/images/{name}/tag?%s', $queryParam->buildQueryString($parameters));
188
        $request  = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), null);
189
        $request  = $request->withHeader('Host', 'localhost');
190
        $response = $this->httpClient->sendRequest($request);
191
        if (self::FETCH_RESPONSE == $fetch) {
192
            return $response;
193
        }
194
195
        return $response;
196
    }
197
198
    /**
199
     * Remove the image name from the filesystem.
200
     * 
201
     * @param array  $parameters List of parameters
202
     * @param string $fetch      Fetch mode (object or response)
203
     *
204
     * @return \Psr\Http\Message\ResponseInterface
205
     */
206 View Code Duplication
    public function remove($parameters = [], $fetch = self::FETCH_OBJECT)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
207
    {
208
        $queryParam = new QueryParam();
209
        $queryParam->setDefault('force', null);
210
        $queryParam->setDefault('noprune', null);
211
        $url      = sprintf('/v1.21/images/{name}?%s', $queryParam->buildQueryString($parameters));
212
        $request  = $this->messageFactory->createRequest('DELETE', $url, $queryParam->buildHeaders($parameters), null);
213
        $request  = $request->withHeader('Host', 'localhost');
214
        $response = $this->httpClient->sendRequest($request);
215
        if (self::FETCH_RESPONSE == $fetch) {
216
            return $response;
217
        }
218
219
        return $response;
220
    }
221
222
    /**
223
     * Search for an image on Docker Hub.
224
     * 
225
     * @param array  $parameters List of parameters
226
     * @param string $fetch      Fetch mode (object or response)
227
     *
228
     * @return \Psr\Http\Message\ResponseInterface
229
     */
230
    public function search($parameters = [], $fetch = self::FETCH_OBJECT)
231
    {
232
        $queryParam = new QueryParam();
233
        $queryParam->setDefault('term', null);
234
        $url      = sprintf('/v1.21/images/search?%s', $queryParam->buildQueryString($parameters));
235
        $request  = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null);
236
        $request  = $request->withHeader('Host', 'localhost');
237
        $response = $this->httpClient->sendRequest($request);
238
        if (self::FETCH_RESPONSE == $fetch) {
239
            return $response;
240
        }
241
        if ('200' == $response->getStatusCode()) {
242
            return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ImageSearchResult[]', 'json');
243
        }
244
245
        return $response;
246
    }
247
248
    /**
249
     * Create a new image from a container’s changes.
250
     * 
251
     * @param mixed  $containerConfig The container configuration
252
     * @param array  $parameters      List of parameters
253
     * @param string $fetch           Fetch mode (object or response)
254
     *
255
     * @return \Psr\Http\Message\ResponseInterface
256
     */
257 View Code Duplication
    public function commit($containerConfig, $parameters = [], $fetch = self::FETCH_OBJECT)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
258
    {
259
        $queryParam = new QueryParam();
260
        $queryParam->setDefault('container', null);
261
        $queryParam->setDefault('repo', null);
262
        $queryParam->setDefault('tag', null);
263
        $queryParam->setDefault('comment', null);
264
        $queryParam->setDefault('author', null);
265
        $queryParam->setDefault('pause', null);
266
        $queryParam->setDefault('changes', null);
267
        $url      = sprintf('/v1.21/commit?%s', $queryParam->buildQueryString($parameters));
268
        $request  = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), $containerConfig);
269
        $request  = $request->withHeader('Host', 'localhost');
270
        $response = $this->httpClient->sendRequest($request);
271
        if (self::FETCH_RESPONSE == $fetch) {
272
            return $response;
273
        }
274
        if ('201' == $response->getStatusCode()) {
275
            return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\CommitResult', 'json');
276
        }
277
278
        return $response;
279
    }
280
281
    /**
282
     * Get a tarball containing all images and metadata for the repository specified by name.
283
     * 
284
     * @param array  $parameters List of parameters
285
     * @param string $fetch      Fetch mode (object or response)
286
     *
287
     * @return \Psr\Http\Message\ResponseInterface
288
     */
289
    public function save($parameters = [], $fetch = self::FETCH_OBJECT)
290
    {
291
        $queryParam = new QueryParam();
292
        $url        = sprintf('/v1.21/images/{name}/get?%s', $queryParam->buildQueryString($parameters));
293
        $request    = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null);
294
        $request    = $request->withHeader('Host', 'localhost');
295
        $response   = $this->httpClient->sendRequest($request);
296
        if (self::FETCH_RESPONSE == $fetch) {
297
            return $response;
298
        }
299
300
        return $response;
301
    }
302
303
    /**
304
     * Get a tarball containing all images and metadata for one or more repositories.
305
     * 
306
     * @param array  $parameters List of parameters
307
     * @param string $fetch      Fetch mode (object or response)
308
     *
309
     * @return \Psr\Http\Message\ResponseInterface
310
     */
311 View Code Duplication
    public function saveAll($parameters = [], $fetch = self::FETCH_OBJECT)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
312
    {
313
        $queryParam = new QueryParam();
314
        $queryParam->setDefault('names', null);
315
        $url      = sprintf('/v1.21/images/get?%s', $queryParam->buildQueryString($parameters));
316
        $request  = $this->messageFactory->createRequest('GET', $url, $queryParam->buildHeaders($parameters), null);
317
        $request  = $request->withHeader('Host', 'localhost');
318
        $response = $this->httpClient->sendRequest($request);
319
        if (self::FETCH_RESPONSE == $fetch) {
320
            return $response;
321
        }
322
323
        return $response;
324
    }
325
326
    /**
327
     * Load a set of images and tags into a Docker repository. See the image tarball format for more details.
328
     * 
329
     * @param mixed  $imagesTarball Tar archive containing images
330
     * @param array  $parameters    List of parameters
331
     * @param string $fetch         Fetch mode (object or response)
332
     *
333
     * @return \Psr\Http\Message\ResponseInterface
334
     */
335
    public function load($imagesTarball, $parameters = [], $fetch = self::FETCH_OBJECT)
336
    {
337
        $queryParam = new QueryParam();
338
        $url        = sprintf('/v1.21/images/load?%s', $queryParam->buildQueryString($parameters));
339
        $request    = $this->messageFactory->createRequest('POST', $url, $queryParam->buildHeaders($parameters), $imagesTarball);
340
        $request    = $request->withHeader('Host', 'localhost');
341
        $response   = $this->httpClient->sendRequest($request);
342
        if (self::FETCH_RESPONSE == $fetch) {
343
            return $response;
344
        }
345
346
        return $response;
347
    }
348
}
349