mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
* refactor(tags): replace tags with tag ids * refactor(tags): revert tags to be strings and add tagids * refactor(tags): enable search by tag in home view * refactor(tags): show endpoint tags * refactor(endpoints): expect tagIds on create payload * refactor(endpoints): expect tagIds on update payload * refactor(endpoints): replace TagIds to TagIDs * refactor(endpoints): set endpoint group to get TagIDs * refactor(endpoints): refactor tag-selector to receive tag-ids * refactor(endpoints): show tags in multi-endpoint-selector * chore(tags): revert reformat * refactor(endpoints): remove unneeded bind * refactor(endpoints): change param tags to tagids in endpoint create * refactor(endpoints): remove console.log * refactor(tags): remove deleted tag from endpoint and endpoint group * fix(endpoints): show loading label while loading tags * chore(go): remove obsolete import labels * chore(db): add db version comment * fix(db): add tag service to migrator * refactor(db): add error checks in migrator * style(db): sort props in alphabetical order * style(tags): fix typo Co-Authored-By: Anthony Lapenna <anthony.lapenna@portainer.io> * refactor(endpoints): replace tagsMap with tag string representation * refactor(tags): rewrite tag delete to be more readable * refactor(home): rearange code to match former style * refactor(tags): guard against missing model in tag-selector * refactor(tags): rename vars in tag_delete * refactor(tags): allow any authenticated user to fetch tag list * refactor(endpoints): replace controller function with class * refactor(endpoints): replace function with helper * refactor(endpoints): replace controller with class * refactor(tags): revert tags-selector to use 1 way bindings * refactor(endpoints): load empty tag array instead of nil * refactor(endpoints): revert default tag ids * refactor(endpoints): use function in place * refactor(tags): use lodash * style(tags): use parens in arrow functions * fix(tags): remove tag from tag model Co-authored-by: Anthony Lapenna <anthony.lapenna@portainer.io>
186 lines
5.1 KiB
JavaScript
186 lines
5.1 KiB
JavaScript
import {genericHandler, jsonObjectsToArrayHandler} from '../../docker/rest/response/handlers';
|
|
|
|
angular.module('portainer.app')
|
|
.factory('FileUploadService', ['$q', 'Upload', 'EndpointProvider', function FileUploadFactory($q, Upload, EndpointProvider) {
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
function uploadFile(url, file) {
|
|
return Upload.upload({ url: url, data: { file: file }});
|
|
}
|
|
|
|
service.buildImage = function(names, file, path) {
|
|
var endpointID = EndpointProvider.endpointID();
|
|
return Upload.http({
|
|
url: 'api/endpoints/' + endpointID + '/docker/build',
|
|
headers : {
|
|
'Content-Type': file.type
|
|
},
|
|
data: file,
|
|
params: {
|
|
t: names,
|
|
dockerfile: path
|
|
},
|
|
ignoreLoadingBar: true,
|
|
transformResponse: function(data) {
|
|
return jsonObjectsToArrayHandler(data);
|
|
}
|
|
});
|
|
};
|
|
|
|
service.loadImages = function(file) {
|
|
var endpointID = EndpointProvider.endpointID();
|
|
return Upload.http({
|
|
url: 'api/endpoints/' + endpointID + '/docker/images/load',
|
|
headers : {
|
|
'Content-Type': file.type
|
|
},
|
|
data: file,
|
|
ignoreLoadingBar: true,
|
|
transformResponse: genericHandler
|
|
});
|
|
};
|
|
|
|
service.createSchedule = function(payload) {
|
|
return Upload.upload({
|
|
url: 'api/schedules?method=file',
|
|
data: {
|
|
file: payload.File,
|
|
Name: payload.Name,
|
|
CronExpression: payload.CronExpression,
|
|
Image: payload.Image,
|
|
Endpoints: Upload.json(payload.Endpoints),
|
|
RetryCount: payload.RetryCount,
|
|
RetryInterval: payload.RetryInterval
|
|
}
|
|
});
|
|
};
|
|
|
|
service.createSwarmStack = function(stackName, swarmId, file, env, endpointId) {
|
|
return Upload.upload({
|
|
url: 'api/stacks?method=file&type=1&endpointId=' + endpointId,
|
|
data: {
|
|
file: file,
|
|
Name: stackName,
|
|
SwarmID: swarmId,
|
|
Env: Upload.json(env)
|
|
},
|
|
ignoreLoadingBar: true
|
|
});
|
|
};
|
|
|
|
service.createComposeStack = function(stackName, file, env, endpointId) {
|
|
return Upload.upload({
|
|
url: 'api/stacks?method=file&type=2&endpointId=' + endpointId,
|
|
data: {
|
|
file: file,
|
|
Name: stackName,
|
|
Env: Upload.json(env)
|
|
},
|
|
ignoreLoadingBar: true
|
|
});
|
|
};
|
|
|
|
service.configureRegistry = function(registryId, registryManagementConfigurationModel) {
|
|
return Upload.upload({
|
|
url: 'api/registries/' + registryId + '/configure',
|
|
data: registryManagementConfigurationModel
|
|
});
|
|
};
|
|
|
|
service.executeEndpointJob = function (imageName, file, endpointId, nodeName) {
|
|
return Upload.upload({
|
|
url: 'api/endpoints/' + endpointId + '/job?method=file&nodeName=' + nodeName,
|
|
data: {
|
|
File: file,
|
|
Image: imageName
|
|
},
|
|
ignoreLoadingBar: true
|
|
});
|
|
};
|
|
|
|
service.createEndpoint = function(name, type, URL, PublicURL, groupID, tagIds, TLS, TLSSkipVerify, TLSSkipClientVerify, TLSCAFile, TLSCertFile, TLSKeyFile) {
|
|
return Upload.upload({
|
|
url: 'api/endpoints',
|
|
data: {
|
|
Name: name,
|
|
EndpointType: type,
|
|
URL: URL,
|
|
PublicURL: PublicURL,
|
|
GroupID: groupID,
|
|
TagIds: Upload.json(tagIds),
|
|
TLS: TLS,
|
|
TLSSkipVerify: TLSSkipVerify,
|
|
TLSSkipClientVerify: TLSSkipClientVerify,
|
|
TLSCACertFile: TLSCAFile,
|
|
TLSCertFile: TLSCertFile,
|
|
TLSKeyFile: TLSKeyFile
|
|
},
|
|
ignoreLoadingBar: true
|
|
});
|
|
};
|
|
|
|
service.createAzureEndpoint = function(name, applicationId, tenantId, authenticationKey, groupId, tagIds) {
|
|
return Upload.upload({
|
|
url: 'api/endpoints',
|
|
data: {
|
|
Name: name,
|
|
EndpointType: 3,
|
|
GroupID: groupId,
|
|
TagIds: Upload.json(tagIds),
|
|
AzureApplicationID: applicationId,
|
|
AzureTenantID: tenantId,
|
|
AzureAuthenticationKey: authenticationKey
|
|
},
|
|
ignoreLoadingBar: true
|
|
});
|
|
};
|
|
|
|
service.uploadLDAPTLSFiles = function(TLSCAFile, TLSCertFile, TLSKeyFile) {
|
|
var queue = [];
|
|
|
|
if (TLSCAFile) {
|
|
queue.push(uploadFile('api/upload/tls/ca?folder=ldap', TLSCAFile));
|
|
}
|
|
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);
|
|
};
|
|
|
|
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);
|
|
};
|
|
|
|
service.uploadExtension = function(license, extensionFile) {
|
|
const payload = {
|
|
License: license,
|
|
file: extensionFile,
|
|
ArchiveFileName: extensionFile.name
|
|
};
|
|
return Upload.upload({
|
|
url: 'api/extensions/upload',
|
|
data: payload,
|
|
ignoreLoadingBar: true
|
|
});
|
|
};
|
|
|
|
return service;
|
|
}]);
|