mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(uac): add multi user management and UAC (#647)
This commit is contained in:
parent
f28f223624
commit
80d50378c5
91 changed files with 3973 additions and 866 deletions
|
@ -1,84 +1,92 @@
|
|||
angular.module('portainer.services')
|
||||
.factory('EndpointService', ['$q', 'Endpoints', 'FileUploadService', function EndpointServiceFactory($q, Endpoints, FileUploadService) {
|
||||
'use strict';
|
||||
return {
|
||||
getActive: function() {
|
||||
return Endpoints.getActiveEndpoint().$promise;
|
||||
},
|
||||
setActive: function(endpointID) {
|
||||
return Endpoints.setActiveEndpoint({id: endpointID}).$promise;
|
||||
},
|
||||
endpoint: function(endpointID) {
|
||||
return Endpoints.get({id: endpointID}).$promise;
|
||||
},
|
||||
endpoints: function() {
|
||||
return Endpoints.query({}).$promise;
|
||||
},
|
||||
updateEndpoint: function(ID, name, URL, TLS, TLSCAFile, TLSCertFile, TLSKeyFile, type) {
|
||||
var endpoint = {
|
||||
id: ID,
|
||||
Name: name,
|
||||
URL: type === 'local' ? ("unix://" + URL) : ("tcp://" + URL),
|
||||
TLS: TLS
|
||||
};
|
||||
var deferred = $q.defer();
|
||||
Endpoints.update({}, endpoint, function success(data) {
|
||||
FileUploadService.uploadTLSFilesForEndpoint(ID, TLSCAFile, TLSCertFile, TLSKeyFile).then(function success(data) {
|
||||
var service = {};
|
||||
|
||||
service.endpoint = function(endpointID) {
|
||||
return Endpoints.get({id: endpointID}).$promise;
|
||||
};
|
||||
|
||||
service.endpoints = function() {
|
||||
return Endpoints.query({}).$promise;
|
||||
};
|
||||
|
||||
service.updateAuthorizedUsers = function(id, authorizedUserIDs) {
|
||||
return Endpoints.updateAccess({id: id}, {authorizedUsers: authorizedUserIDs}).$promise;
|
||||
};
|
||||
|
||||
service.updateEndpoint = function(id, endpointParams) {
|
||||
var query = {
|
||||
name: endpointParams.name,
|
||||
TLS: endpointParams.TLS,
|
||||
authorizedUsers: endpointParams.authorizedUsers
|
||||
};
|
||||
if (endpointParams.type && endpointParams.URL) {
|
||||
query.URL = endpointParams.type === 'local' ? ("unix://" + endpointParams.URL) : ("tcp://" + endpointParams.URL);
|
||||
}
|
||||
var deferred = $q.defer();
|
||||
Endpoints.update({id: id}, query).$promise
|
||||
.then(function success() {
|
||||
return FileUploadService.uploadTLSFilesForEndpoint(id, endpointParams.TLSCAFile, endpointParams.TLSCertFile, endpointParams.TLSKeyFile);
|
||||
})
|
||||
.then(function success(data) {
|
||||
deferred.notify({upload: false});
|
||||
deferred.resolve(data);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.notify({upload: false});
|
||||
deferred.reject({msg: 'Unable to update endpoint', err: err});
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.deleteEndpoint = function(endpointID) {
|
||||
return Endpoints.remove({id: endpointID}).$promise;
|
||||
};
|
||||
|
||||
service.createLocalEndpoint = function(name, URL, TLS, active) {
|
||||
var endpoint = {
|
||||
Name: "local",
|
||||
URL: "unix:///var/run/docker.sock",
|
||||
TLS: false
|
||||
};
|
||||
return Endpoints.create({}, endpoint).$promise;
|
||||
};
|
||||
|
||||
service.createRemoteEndpoint = function(name, URL, TLS, TLSCAFile, TLSCertFile, TLSKeyFile, active) {
|
||||
var endpoint = {
|
||||
Name: name,
|
||||
URL: 'tcp://' + URL,
|
||||
TLS: TLS
|
||||
};
|
||||
var deferred = $q.defer();
|
||||
Endpoints.create({active: active}, endpoint, function success(data) {
|
||||
var endpointID = data.Id;
|
||||
if (TLS) {
|
||||
deferred.notify({upload: true});
|
||||
FileUploadService.uploadTLSFilesForEndpoint(endpointID, TLSCAFile, TLSCertFile, TLSKeyFile).then(function success(data) {
|
||||
deferred.notify({upload: false});
|
||||
deferred.resolve(data);
|
||||
if (active) {
|
||||
Endpoints.setActiveEndpoint({}, {id: endpointID}, function success(data) {
|
||||
deferred.resolve(data);
|
||||
}, function error(err) {
|
||||
deferred.reject({msg: 'Unable to create endpoint', err: err});
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(data);
|
||||
}
|
||||
}, function error(err) {
|
||||
deferred.notify({upload: false});
|
||||
deferred.reject({msg: 'Unable to upload TLS certs', err: err});
|
||||
});
|
||||
}, function error(err) {
|
||||
deferred.reject({msg: 'Unable to update endpoint', err: err});
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
deleteEndpoint: function(endpointID) {
|
||||
return Endpoints.remove({id: endpointID}).$promise;
|
||||
},
|
||||
createLocalEndpoint: function(name, URL, TLS, active) {
|
||||
var endpoint = {
|
||||
Name: "local",
|
||||
URL: "unix:///var/run/docker.sock",
|
||||
TLS: false
|
||||
};
|
||||
return Endpoints.create({active: active}, endpoint).$promise;
|
||||
},
|
||||
createRemoteEndpoint: function(name, URL, TLS, TLSCAFile, TLSCertFile, TLSKeyFile, active) {
|
||||
var endpoint = {
|
||||
Name: name,
|
||||
URL: 'tcp://' + URL,
|
||||
TLS: TLS
|
||||
};
|
||||
var deferred = $q.defer();
|
||||
Endpoints.create({active: active}, endpoint, function success(data) {
|
||||
var endpointID = data.Id;
|
||||
if (TLS) {
|
||||
deferred.notify({upload: true});
|
||||
FileUploadService.uploadTLSFilesForEndpoint(endpointID, TLSCAFile, TLSCertFile, TLSKeyFile).then(function success(data) {
|
||||
deferred.notify({upload: false});
|
||||
if (active) {
|
||||
Endpoints.setActiveEndpoint({}, {id: endpointID}, function success(data) {
|
||||
deferred.resolve(data);
|
||||
}, function error(err) {
|
||||
deferred.reject({msg: 'Unable to create endpoint', err: err});
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(data);
|
||||
}
|
||||
}, function error(err) {
|
||||
deferred.notify({upload: false});
|
||||
deferred.reject({msg: 'Unable to upload TLS certs', err: err});
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(data);
|
||||
}
|
||||
}, function error(err) {
|
||||
deferred.reject({msg: 'Unable to create endpoint', err: err});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
} else {
|
||||
deferred.resolve(data);
|
||||
}
|
||||
}, function error(err) {
|
||||
deferred.reject({msg: 'Unable to create endpoint', err: err});
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue