2017-08-28 18:59:13 +00:00
|
|
|
angular.module('initEndpoint', [])
|
|
|
|
.controller('InitEndpointController', ['$scope', '$state', 'EndpointService', 'StateManager', 'EndpointProvider', 'Notifications',
|
2017-04-12 19:47:22 +00:00
|
|
|
function ($scope, $state, EndpointService, StateManager, EndpointProvider, Notifications) {
|
2017-08-28 18:59:13 +00:00
|
|
|
|
2017-09-14 06:08:37 +00:00
|
|
|
if (!_.isEmpty($scope.applicationState.endpoint)) {
|
|
|
|
$state.go('dashboard');
|
|
|
|
}
|
|
|
|
|
2017-08-28 18:59:13 +00:00
|
|
|
$scope.logo = StateManager.getState().application.logo;
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state = {
|
|
|
|
uploadInProgress: false
|
|
|
|
};
|
2017-04-08 18:38:19 +00:00
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.formValues = {
|
2017-08-28 18:59:13 +00:00
|
|
|
EndpointType: 'remote',
|
2016-12-25 20:34:02 +00:00
|
|
|
Name: '',
|
|
|
|
URL: '',
|
|
|
|
TLS: false,
|
2017-09-14 06:08:37 +00:00
|
|
|
TLSSkipVerify: false,
|
|
|
|
TLSSKipClientVerify: false,
|
2016-12-25 20:34:02 +00:00
|
|
|
TLSCACert: null,
|
|
|
|
TLSCert: null,
|
|
|
|
TLSKey: null
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.createLocalEndpoint = function() {
|
2017-08-28 18:59:13 +00:00
|
|
|
$('#createResourceSpinner').show();
|
2017-05-23 18:56:10 +00:00
|
|
|
var name = 'local';
|
|
|
|
var URL = 'unix:///var/run/docker.sock';
|
2017-03-12 16:24:15 +00:00
|
|
|
|
2017-09-14 06:08:37 +00:00
|
|
|
var endpointID = 1;
|
2017-08-28 18:59:13 +00:00
|
|
|
EndpointService.createLocalEndpoint(name, URL, false, true)
|
2017-04-08 18:38:19 +00:00
|
|
|
.then(function success(data) {
|
2017-09-14 06:08:37 +00:00
|
|
|
endpointID = data.Id;
|
2017-08-28 18:59:13 +00:00
|
|
|
EndpointProvider.setEndpointID(endpointID);
|
|
|
|
return StateManager.updateEndpointState(false);
|
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
$state.go('dashboard');
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-09-14 06:08:37 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to connect to the Docker environment');
|
|
|
|
EndpointService.deleteEndpoint(endpointID);
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
2017-08-28 18:59:13 +00:00
|
|
|
$('#createResourceSpinner').hide();
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.createRemoteEndpoint = function() {
|
2017-08-28 18:59:13 +00:00
|
|
|
$('#createResourceSpinner').show();
|
2016-12-25 20:34:02 +00:00
|
|
|
var name = $scope.formValues.Name;
|
|
|
|
var URL = $scope.formValues.URL;
|
2017-05-01 10:19:43 +00:00
|
|
|
var PublicURL = URL.split(':')[0];
|
2016-12-25 20:34:02 +00:00
|
|
|
var TLS = $scope.formValues.TLS;
|
2017-09-14 06:08:37 +00:00
|
|
|
var TLSSkipVerify = TLS && $scope.formValues.TLSSkipVerify;
|
|
|
|
var TLSSKipClientVerify = TLS && $scope.formValues.TLSSKipClientVerify;
|
|
|
|
var TLSCAFile = TLSSkipVerify ? null : $scope.formValues.TLSCACert;
|
|
|
|
var TLSCertFile = TLSSKipClientVerify ? null : $scope.formValues.TLSCert;
|
|
|
|
var TLSKeyFile = TLSSKipClientVerify ? null : $scope.formValues.TLSKey;
|
2017-04-08 18:38:19 +00:00
|
|
|
|
2017-09-14 06:08:37 +00:00
|
|
|
var endpointID = 1;
|
|
|
|
EndpointService.createRemoteEndpoint(name, URL, PublicURL, TLS, TLSSkipVerify, TLSSKipClientVerify, TLSCAFile, TLSCertFile, TLSKeyFile)
|
2017-01-22 23:14:34 +00:00
|
|
|
.then(function success(data) {
|
2017-09-14 06:08:37 +00:00
|
|
|
endpointID = data.Id;
|
2017-08-28 18:59:13 +00:00
|
|
|
EndpointProvider.setEndpointID(endpointID);
|
|
|
|
return StateManager.updateEndpointState(false);
|
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
$state.go('dashboard');
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-09-14 06:08:37 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to connect to the Docker environment');
|
|
|
|
EndpointService.deleteEndpoint(endpointID);
|
2017-04-08 18:38:19 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
2017-08-28 18:59:13 +00:00
|
|
|
$('#createResourceSpinner').hide();
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}]);
|