1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | /**
|
4 | * Class reprensenting a plugin
|
5 | */
|
6 | class Plugin {
|
7 | /**
|
8 | * Creates a new plugin
|
9 | * @param {Modem} modem Modem to connect to the remote service
|
10 | * @param {string} id Id of the plugin (optional)
|
11 | */
|
12 | constructor(modem, id) {
|
13 | this.modem = modem;
|
14 | this.id = id;
|
15 | }
|
16 | /**
|
17 | * Get the list of plugins
|
18 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/list-plugins
|
19 | * @param {Object} opts Query params in the request (optional)
|
20 | * @return {Promise} Promise returning the result as a list of plugins
|
21 | */
|
22 | list(opts) {
|
23 | const call = {
|
24 | path: '/plugins?',
|
25 | method: 'GET',
|
26 | options: opts,
|
27 | statusCodes: {
|
28 | 200: true,
|
29 | 500: 'server error'
|
30 | }
|
31 | };
|
32 | return new Promise((resolve, reject) => {
|
33 | this.modem.dial(call, (err, plugins) => {
|
34 | if (err)
|
35 | return reject(err);
|
36 | if (!plugins || !plugins.length)
|
37 | return resolve([]);
|
38 | resolve(plugins.map((conf) => {
|
39 | const plugin = new Plugin(this.modem, conf.Id);
|
40 | return Object.assign(plugin, conf);
|
41 | }));
|
42 | });
|
43 | });
|
44 | }
|
45 | /**
|
46 | * upgrade a plugin
|
47 | * https://docs.docker.com/engine/api/v1.26/#operation/PluginUpgrade
|
48 | * @param {Object} opts Query params in the request (optional)
|
49 | * @return {Promise} Promise return the new plugin
|
50 | */
|
51 | upgrade(opts) {
|
52 | let id;
|
53 | [opts, id] = this.__processArguments(opts);
|
54 | const call = {
|
55 | path: `/plugins/${id}/upgrade?`,
|
56 | method: 'POST',
|
57 | options: opts,
|
58 | statusCodes: {
|
59 | 204: true,
|
60 | 404: 'plugin not installed',
|
61 | 500: 'server error'
|
62 | }
|
63 | };
|
64 | return new Promise((resolve, reject) => {
|
65 | this.modem.dial(call, (err, conf) => {
|
66 | if (err)
|
67 | return reject(err);
|
68 | const plugin = new Plugin(this.modem, opts.name);
|
69 | resolve(plugin);
|
70 | });
|
71 | });
|
72 | }
|
73 | /**
|
74 | * Create a plugin
|
75 | * https://docs.docker.com/engine/api/v1.25/#operation/PluginCreate
|
76 | * @param {Object} opts Query params in the request (optional)
|
77 | * @return {Promise} Promise return the new plugin
|
78 | */
|
79 | create(opts) {
|
80 | const call = {
|
81 | path: '/plugins/create?',
|
82 | method: 'POST',
|
83 | options: opts,
|
84 | statusCodes: {
|
85 | 204: true,
|
86 | 500: 'server error'
|
87 | }
|
88 | };
|
89 | return new Promise((resolve, reject) => {
|
90 | this.modem.dial(call, (err, conf) => {
|
91 | if (err)
|
92 | return reject(err);
|
93 | const plugin = new Plugin(this.modem, opts.name);
|
94 | resolve(plugin);
|
95 | });
|
96 | });
|
97 | }
|
98 | /**
|
99 | * install a plugin
|
100 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/install-a-plugin
|
101 | * @param {Object} opts Query params in the request (optional)
|
102 | * @return {Promise} Promise return the new plugin
|
103 | */
|
104 | install(opts) {
|
105 | const call = {
|
106 | path: '/plugins/pull?',
|
107 | method: 'POST',
|
108 | options: opts,
|
109 | statusCodes: {
|
110 | 200: true,
|
111 | 500: 'server error'
|
112 | }
|
113 | };
|
114 | return new Promise((resolve, reject) => {
|
115 | this.modem.dial(call, (err, conf) => {
|
116 | if (err)
|
117 | return reject(err);
|
118 | const plugin = new Plugin(this.modem, opts.name);
|
119 | resolve(plugin);
|
120 | });
|
121 | });
|
122 | }
|
123 | /**
|
124 | * Get low-level information on a plugin
|
125 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/inspect-a-plugin
|
126 | * The reason why this module isn't called inspect is because that interferes with the inspect utility of node.
|
127 | * @param {Object} opts Query params in the request (optional)
|
128 | * @param {String} id ID of the plugin to inspect, if it's not set, use the id of the object (optional)
|
129 | * @return {Promise} Promise return the plugin
|
130 | */
|
131 | status(opts, id) {
|
132 | [opts, id] = this.__processArguments(opts, id);
|
133 | const call = {
|
134 | path: `/plugins/${id}?`,
|
135 | method: 'GET',
|
136 | options: opts,
|
137 | statusCodes: {
|
138 | 200: true,
|
139 | 404: 'no such plugin',
|
140 | 500: 'server error'
|
141 | }
|
142 | };
|
143 | return new Promise((resolve, reject) => {
|
144 | this.modem.dial(call, (err, conf) => {
|
145 | if (err)
|
146 | return reject(err);
|
147 | const plugin = new Plugin(this.modem, id);
|
148 | resolve(Object.assign(plugin, conf));
|
149 | });
|
150 | });
|
151 | }
|
152 | /**
|
153 | * Remove a plugin
|
154 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/remove-a-plugin
|
155 | * @param {Object} opts Query params in the request (optional)
|
156 | * @param {String} id ID of the plugin to inspect, if it's not set, use the id of the object (optional)
|
157 | * @return {Promise} Promise return the result
|
158 | */
|
159 | remove(opts, id) {
|
160 | [opts, id] = this.__processArguments(opts, id);
|
161 | const call = {
|
162 | path: `/plugins/${id}?`,
|
163 | method: 'DELETE',
|
164 | options: opts,
|
165 | statusCodes: {
|
166 | 200: true,
|
167 | 404: 'no such plugin',
|
168 | 500: 'server error'
|
169 | }
|
170 | };
|
171 | return new Promise((resolve, reject) => {
|
172 | this.modem.dial(call, (err, res) => {
|
173 | if (err)
|
174 | return reject(err);
|
175 | resolve(res);
|
176 | });
|
177 | });
|
178 | }
|
179 | /**
|
180 | * push a plugin
|
181 | * https://docs.docker.com/engine/api/v1.26/#operation/PluginPush
|
182 | * @param {Object} opts Query params in the request (optional)
|
183 | * @param {String} id ID of the plugin, if it's not set, use the id of the object (optional)
|
184 | * @return {Promise} Promise return the plugin
|
185 | */
|
186 | push(opts, id) {
|
187 | [opts, id] = this.__processArguments(opts, id);
|
188 | const call = {
|
189 | path: `/plugins/${id}/push?`,
|
190 | method: 'POST',
|
191 | options: opts,
|
192 | statusCodes: {
|
193 | 200: true,
|
194 | 404: 'plugin not found',
|
195 | 500: 'server error'
|
196 | }
|
197 | };
|
198 | return new Promise((resolve, reject) => {
|
199 | this.modem.dial(call, (err, conf) => {
|
200 | if (err)
|
201 | return reject(err);
|
202 | const plugin = new Plugin(this.modem, id);
|
203 | resolve(plugin);
|
204 | });
|
205 | });
|
206 | }
|
207 | /**
|
208 | * Set a plugin configuration
|
209 | * https://docs.docker.com/engine/api/v1.25/#operation/PluginSet
|
210 | * @param {Object} opts Query params in the request (optional)
|
211 | * @param {String} id ID of the plugin, if it's not set, use the id of the object (optional)
|
212 | * @return {Promise} Promise return the plugin
|
213 | */
|
214 | set(opts, id) {
|
215 | [opts, id] = this.__processArguments(opts, id);
|
216 | const call = {
|
217 | path: `/plugins/${id}/set?`,
|
218 | method: 'POST',
|
219 | options: opts,
|
220 | statusCodes: {
|
221 | 204: true,
|
222 | 404: 'plugin not found',
|
223 | 500: 'server error'
|
224 | }
|
225 | };
|
226 | return new Promise((resolve, reject) => {
|
227 | this.modem.dial(call, (err, conf) => {
|
228 | if (err)
|
229 | return reject(err);
|
230 | const plugin = new Plugin(this.modem, id);
|
231 | resolve(plugin);
|
232 | });
|
233 | });
|
234 | }
|
235 | /**
|
236 | * Enable a plugin
|
237 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/enable-a-plugin
|
238 | * @param {Object} opts Query params in the request (optional)
|
239 | * @param {String} id ID of the plugin, if it's not set, use the id of the object (optional)
|
240 | * @return {Promise} Promise return the plugin
|
241 | */
|
242 | enable(opts, id) {
|
243 | [opts, id] = this.__processArguments(opts, id);
|
244 | const call = {
|
245 | path: `/plugins/${id}/enable?`,
|
246 | method: 'POST',
|
247 | options: opts,
|
248 | statusCodes: {
|
249 | 200: true,
|
250 | 500: 'server error'
|
251 | }
|
252 | };
|
253 | return new Promise((resolve, reject) => {
|
254 | this.modem.dial(call, (err, conf) => {
|
255 | if (err)
|
256 | return reject(err);
|
257 | const plugin = new Plugin(this.modem, id);
|
258 | resolve(plugin);
|
259 | });
|
260 | });
|
261 | }
|
262 | /**
|
263 | * Disable a plugin
|
264 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/disable-a-plugin
|
265 | * @param {Object} opts Query params in the request (optional)
|
266 | * @param {String} id ID of the plugin, if it's not set, use the id of the object (optional)
|
267 | * @return {Promise} Promise return the plugin
|
268 | */
|
269 | disable(opts, id) {
|
270 | [opts, id] = this.__processArguments(opts, id);
|
271 | const call = {
|
272 | path: `/plugins/${id}/disable?`,
|
273 | method: 'POST',
|
274 | options: opts,
|
275 | statusCodes: {
|
276 | 200: true,
|
277 | 500: 'server error'
|
278 | }
|
279 | };
|
280 | return new Promise((resolve, reject) => {
|
281 | this.modem.dial(call, (err, conf) => {
|
282 | if (err)
|
283 | return reject(err);
|
284 | const plugin = new Plugin(this.modem, id);
|
285 | resolve(plugin);
|
286 | });
|
287 | });
|
288 | }
|
289 | __processArguments(opts, id) {
|
290 | if (typeof opts === 'string' && !id) {
|
291 | id = opts;
|
292 | }
|
293 | if (!id && this.id) {
|
294 | id = this.id;
|
295 | }
|
296 | if (!opts)
|
297 | opts = {};
|
298 | return [opts, id];
|
299 | }
|
300 | }
|
301 | exports.default = Plugin;
|
302 | //# sourceMappingURL=plugin.js.map |
\ | No newline at end of file |