2019-03-21 05:46:49 +00:00
|
|
|
import _ from 'lodash-es';
|
2020-04-10 21:54:53 +00:00
|
|
|
import { PluginViewModel } from '../models/plugin';
|
2019-03-21 05:46:49 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.docker').factory('PluginService', [
|
|
|
|
'$q',
|
|
|
|
'Plugin',
|
|
|
|
'SystemService',
|
|
|
|
function PluginServiceFactory($q, Plugin, SystemService) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.plugins = function () {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
var plugins = [];
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
Plugin.query({})
|
|
|
|
.$promise.then(function success(data) {
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
var plugin = new PluginViewModel(data[i]);
|
|
|
|
plugins.push(plugin);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
deferred.resolve(plugins);
|
|
|
|
});
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
|
|
|
};
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function servicePlugins(systemOnly, pluginType, pluginVersion) {
|
|
|
|
var deferred = $q.defer();
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$q.all({
|
|
|
|
system: SystemService.plugins(),
|
|
|
|
plugins: systemOnly ? [] : service.plugins(),
|
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
var aggregatedPlugins = [];
|
|
|
|
var systemPlugins = data.system;
|
|
|
|
var plugins = data.plugins;
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
if (systemPlugins[pluginType]) {
|
|
|
|
aggregatedPlugins = aggregatedPlugins.concat(systemPlugins[pluginType]);
|
|
|
|
}
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
for (var i = 0; i < plugins.length; i++) {
|
|
|
|
var plugin = plugins[i];
|
|
|
|
if (plugin.Enabled && _.includes(plugin.Config.Interface.Types, pluginVersion)) {
|
|
|
|
aggregatedPlugins.push(plugin.Name);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
deferred.resolve(aggregatedPlugins);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: err.msg, err: err });
|
|
|
|
});
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
|
|
|
}
|
2017-12-05 08:49:04 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.volumePlugins = function (systemOnly) {
|
|
|
|
return servicePlugins(systemOnly, 'Volume', 'docker.volumedriver/1.0');
|
|
|
|
};
|
2017-07-25 14:21:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.networkPlugins = function (systemOnly) {
|
|
|
|
return servicePlugins(systemOnly, 'Network', 'docker.networkdriver/1.0');
|
|
|
|
};
|
2017-09-06 13:11:38 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
service.loggingPlugins = function (systemOnly) {
|
|
|
|
return servicePlugins(systemOnly, 'Log', 'docker.logdriver/1.0');
|
|
|
|
};
|
2017-12-22 09:05:31 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return service;
|
|
|
|
},
|
|
|
|
]);
|