1 | var util = require('./util');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var Image = function(modem, name) {
|
9 | this.modem = modem;
|
10 | this.name = name;
|
11 | };
|
12 |
|
13 | Image.prototype[require('util').inspect.custom] = function() { return this; };
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | Image.prototype.inspect = function(callback) {
|
21 | var self = this;
|
22 |
|
23 | var opts = {
|
24 | path: '/images/' + this.name + '/json',
|
25 | method: 'GET',
|
26 | statusCodes: {
|
27 | 200: true,
|
28 | 404: 'no such image',
|
29 | 500: 'server error'
|
30 | }
|
31 | };
|
32 |
|
33 | if(callback === undefined) {
|
34 | return new this.modem.Promise(function(resolve, reject) {
|
35 | self.modem.dial(opts, function(err, data) {
|
36 | if (err) {
|
37 | return reject(err);
|
38 | }
|
39 | resolve(data);
|
40 | });
|
41 | });
|
42 | } else {
|
43 | this.modem.dial(opts, function(err, data) {
|
44 | if (err) return callback(err, data);
|
45 | callback(err, data);
|
46 | });
|
47 | }
|
48 | };
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | Image.prototype.distribution = function(opts, callback) {
|
57 | var args = util.processArgs(opts, callback);
|
58 | var self = this;
|
59 |
|
60 | var fopts = {
|
61 | path: '/distribution/' + this.name + '/json',
|
62 | method: 'GET',
|
63 | statusCodes: {
|
64 | 200: true,
|
65 | 401: 'no such image',
|
66 | 500: 'server error'
|
67 | },
|
68 | authconfig: (args.opts) ? args.opts.authconfig : undefined
|
69 | };
|
70 |
|
71 | if(args.callback === undefined) {
|
72 | return new this.modem.Promise(function(resolve, reject) {
|
73 | self.modem.dial(fopts, function(err, data) {
|
74 | if (err) {
|
75 | return reject(err);
|
76 | }
|
77 | resolve(data);
|
78 | });
|
79 | });
|
80 | } else {
|
81 | this.modem.dial(fopts, function(err, data) {
|
82 | if (err) return args.callback(err, data);
|
83 | args.callback(err, data);
|
84 | });
|
85 | }
|
86 | };
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | Image.prototype.history = function(callback) {
|
93 | var self = this;
|
94 | var opts = {
|
95 | path: '/images/' + this.name + '/history',
|
96 | method: 'GET',
|
97 | statusCodes: {
|
98 | 200: true,
|
99 | 404: 'no such image',
|
100 | 500: 'server error'
|
101 | }
|
102 | };
|
103 |
|
104 | if(callback === undefined) {
|
105 | return new this.modem.Promise(function(resolve, reject) {
|
106 | self.modem.dial(opts, function(err, data) {
|
107 | if (err) {
|
108 | return reject(err);
|
109 | }
|
110 | resolve(data);
|
111 | });
|
112 | });
|
113 | } else {
|
114 | this.modem.dial(opts, function(err, data) {
|
115 | if (err) return callback(err, data);
|
116 | callback(err, data);
|
117 | });
|
118 | }
|
119 | };
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | Image.prototype.get = function(callback) {
|
126 | var self = this;
|
127 | var opts = {
|
128 | path: '/images/' + this.name + '/get',
|
129 | method: 'GET',
|
130 | isStream: true,
|
131 | statusCodes: {
|
132 | 200: true,
|
133 | 500: 'server error'
|
134 | }
|
135 | };
|
136 |
|
137 | if(callback === undefined) {
|
138 | return new this.modem.Promise(function(resolve, reject) {
|
139 | self.modem.dial(opts, function(err, data) {
|
140 | if (err) {
|
141 | return reject(err);
|
142 | }
|
143 | resolve(data);
|
144 | });
|
145 | });
|
146 | } else {
|
147 | this.modem.dial(opts, function(err, data) {
|
148 | if (err) return callback(err, data);
|
149 | callback(err, data);
|
150 | });
|
151 | }
|
152 | };
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | Image.prototype.push = function(opts, callback, auth) {
|
161 | var self = this;
|
162 | var args = util.processArgs(opts, callback);
|
163 | var isStream = true;
|
164 | if (args.opts.stream === false) {
|
165 | isStream = false;
|
166 | }
|
167 | var optsf = {
|
168 | path: '/images/' + this.name + '/push?',
|
169 | method: 'POST',
|
170 | options: args.opts,
|
171 | authconfig: args.opts.authconfig || auth,
|
172 | isStream: isStream,
|
173 | statusCodes: {
|
174 | 200: true,
|
175 | 404: 'no such image',
|
176 | 500: 'server error'
|
177 | }
|
178 | };
|
179 |
|
180 | delete optsf.options.authconfig;
|
181 |
|
182 | if(callback === undefined) {
|
183 | return new this.modem.Promise(function(resolve, reject) {
|
184 | self.modem.dial(optsf, function(err, data) {
|
185 | if (err) {
|
186 | return reject(err);
|
187 | }
|
188 | resolve(data);
|
189 | });
|
190 | });
|
191 | } else {
|
192 | this.modem.dial(optsf, function(err, data) {
|
193 | callback(err, data);
|
194 | });
|
195 | }
|
196 | };
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | Image.prototype.tag = function(opts, callback) {
|
204 | var self = this;
|
205 | var optsf = {
|
206 | path: '/images/' + this.name + '/tag?',
|
207 | method: 'POST',
|
208 | options: opts,
|
209 | statusCodes: {
|
210 | 200: true,
|
211 | 201: true,
|
212 | 400: 'bad parameter',
|
213 | 404: 'no such image',
|
214 | 409: 'conflict',
|
215 | 500: 'server error'
|
216 | }
|
217 | };
|
218 |
|
219 | if(callback === undefined) {
|
220 | return new this.modem.Promise(function(resolve, reject) {
|
221 | self.modem.dial(optsf, function(err, data) {
|
222 | if (err) {
|
223 | return reject(err);
|
224 | }
|
225 | resolve(data);
|
226 | });
|
227 | });
|
228 | } else {
|
229 | this.modem.dial(optsf, function(err, data) {
|
230 | callback(err, data);
|
231 | });
|
232 | }
|
233 | };
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 | Image.prototype.remove = function(opts, callback) {
|
241 | var self = this;
|
242 | var args = util.processArgs(opts, callback);
|
243 |
|
244 |
|
245 | var optsf = {
|
246 | path: '/images/' + this.name + '?',
|
247 | method: 'DELETE',
|
248 | statusCodes: {
|
249 | 200: true,
|
250 | 404: 'no such image',
|
251 | 409: 'conflict',
|
252 | 500: 'server error'
|
253 | },
|
254 | options: args.opts
|
255 | };
|
256 |
|
257 |
|
258 | if(args.callback === undefined) {
|
259 | return new this.modem.Promise(function(resolve, reject) {
|
260 | self.modem.dial(optsf, function(err, data) {
|
261 | if (err) {
|
262 | return reject(err);
|
263 | }
|
264 | resolve(data);
|
265 | });
|
266 | });
|
267 | } else {
|
268 | this.modem.dial(optsf, function(err, data) {
|
269 | args.callback(err, data);
|
270 | });
|
271 | }
|
272 | };
|
273 |
|
274 | module.exports = Image;
|