2017-01-31 23:26:29 +00:00
|
|
|
angular.module('portainer.services')
|
2017-10-15 17:24:40 +00:00
|
|
|
.factory('FileUploadService', ['$q', 'Upload', 'EndpointProvider', function FileUploadFactory($q, Upload, EndpointProvider) {
|
2017-01-31 23:26:29 +00:00
|
|
|
'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
|
|
|
|
2017-11-01 09:30:02 +00:00
|
|
|
service.createStack = function(stackName, swarmId, file, env) {
|
2017-10-15 17:24:40 +00:00
|
|
|
var endpointID = EndpointProvider.endpointID();
|
2017-11-12 19:27:28 +00:00
|
|
|
return Upload.upload({
|
|
|
|
url: 'api/endpoints/' + endpointID + '/stacks?method=file',
|
|
|
|
data: {
|
|
|
|
file: file,
|
|
|
|
Name: stackName,
|
|
|
|
SwarmID: swarmId,
|
|
|
|
Env: Upload.json(env)
|
|
|
|
},
|
|
|
|
ignoreLoadingBar: true
|
|
|
|
});
|
2017-10-15 17:24:40 +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
|
|
|
}]);
|