2017-01-31 23:26:29 +00:00
|
|
|
angular.module('portainer.services')
|
|
|
|
.factory('FileUploadService', ['$q', 'Upload', function FileUploadFactory($q, Upload) {
|
|
|
|
'use strict';
|
2017-08-10 08:35:23 +00:00
|
|
|
|
|
|
|
var service = {};
|
|
|
|
|
2017-01-31 23:26:29 +00:00
|
|
|
function uploadFile(url, file) {
|
2017-08-10 08:35:23 +00:00
|
|
|
return Upload.upload({ url: url, data: { file: file }});
|
2017-01-31 23:26:29 +00:00
|
|
|
}
|
2017-08-10 08:35:23 +00:00
|
|
|
|
|
|
|
service.uploadLDAPTLSFiles = function(TLSCAFile, TLSCertFile, TLSKeyFile) {
|
|
|
|
var queue = [];
|
|
|
|
|
|
|
|
if (TLSCAFile) {
|
|
|
|
queue.push(uploadFile('api/upload/tls/ca?folder=ldap', TLSCAFile));
|
2017-01-31 23:26:29 +00:00
|
|
|
}
|
2017-08-10 08:35:23 +00:00
|
|
|
if (TLSCertFile) {
|
|
|
|
queue.push(uploadFile('api/upload/tls/cert?folder=ldap', TLSCertFile));
|
|
|
|
}
|
|
|
|
if (TLSKeyFile) {
|
|
|
|
queue.push(uploadFile('api/upload/tls/key?folder=ldap', TLSKeyFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $q.all(queue);
|
2017-01-31 23:26:29 +00:00
|
|
|
};
|
2017-08-10 08:35:23 +00:00
|
|
|
|
|
|
|
service.uploadTLSFilesForEndpoint = function(endpointID, TLSCAFile, TLSCertFile, TLSKeyFile) {
|
|
|
|
var queue = [];
|
|
|
|
|
|
|
|
if (TLSCAFile) {
|
|
|
|
queue.push(uploadFile('api/upload/tls/ca?folder=' + endpointID, TLSCAFile));
|
|
|
|
}
|
|
|
|
if (TLSCertFile) {
|
|
|
|
queue.push(uploadFile('api/upload/tls/cert?folder=' + endpointID, TLSCertFile));
|
|
|
|
}
|
|
|
|
if (TLSKeyFile) {
|
|
|
|
queue.push(uploadFile('api/upload/tls/key?folder=' + endpointID, TLSKeyFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $q.all(queue);
|
|
|
|
};
|
|
|
|
|
|
|
|
return service;
|
2017-01-31 23:26:29 +00:00
|
|
|
}]);
|