2016-12-25 20:34:02 +00:00
|
|
|
angular.module('endpoint', [])
|
2017-09-21 14:00:53 +00:00
|
|
|
.controller('EndpointController', ['$scope', '$state', '$transition$', '$filter', 'EndpointService', 'Notifications',
|
|
|
|
function ($scope, $state, $transition$, $filter, EndpointService, Notifications) {
|
2017-02-06 05:29:34 +00:00
|
|
|
|
|
|
|
if (!$scope.applicationState.application.endpointManagement) {
|
|
|
|
$state.go('endpoints');
|
|
|
|
}
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.state = {
|
|
|
|
uploadInProgress: false
|
|
|
|
};
|
2017-04-09 18:38:41 +00:00
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.formValues = {
|
2017-09-14 06:08:37 +00:00
|
|
|
SecurityFormData: new EndpointSecurityFormData()
|
2016-12-25 20:34:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updateEndpoint = function() {
|
2017-09-14 06:08:37 +00:00
|
|
|
var endpoint = $scope.endpoint;
|
|
|
|
var securityData = $scope.formValues.SecurityFormData;
|
|
|
|
var TLS = securityData.TLS;
|
|
|
|
var TLSMode = securityData.TLSMode;
|
|
|
|
var TLSSkipVerify = TLS && (TLSMode === 'tls_client_noca' || TLSMode === 'tls_only');
|
|
|
|
var TLSSkipClientVerify = TLS && (TLSMode === 'tls_ca' || TLSMode === 'tls_only');
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
var endpointParams = {
|
2017-09-14 06:08:37 +00:00
|
|
|
name: endpoint.Name,
|
|
|
|
URL: endpoint.URL,
|
|
|
|
PublicURL: endpoint.PublicURL,
|
|
|
|
TLS: TLS,
|
|
|
|
TLSSkipVerify: TLSSkipVerify,
|
|
|
|
TLSSkipClientVerify: TLSSkipClientVerify,
|
|
|
|
TLSCACert: TLSSkipVerify || securityData.TLSCACert === endpoint.TLSConfig.TLSCACert ? null : securityData.TLSCACert,
|
|
|
|
TLSCert: TLSSkipClientVerify || securityData.TLSCert === endpoint.TLSConfig.TLSCert ? null : securityData.TLSCert,
|
|
|
|
TLSKey: TLSSkipClientVerify || securityData.TLSKey === endpoint.TLSConfig.TLSKey ? null : securityData.TLSKey,
|
2017-03-12 16:24:15 +00:00
|
|
|
type: $scope.endpointType
|
|
|
|
};
|
|
|
|
|
2017-09-14 06:08:37 +00:00
|
|
|
$('updateResourceSpinner').show();
|
|
|
|
EndpointService.updateEndpoint(endpoint.Id, endpointParams)
|
2017-03-12 16:24:15 +00:00
|
|
|
.then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Endpoint updated', $scope.endpoint.Name);
|
2016-12-25 20:34:02 +00:00
|
|
|
$state.go('endpoints');
|
|
|
|
}, function error(err) {
|
2017-09-14 06:08:37 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to update endpoint');
|
2016-12-25 20:34:02 +00:00
|
|
|
}, function update(evt) {
|
|
|
|
if (evt.upload) {
|
|
|
|
$scope.state.uploadInProgress = evt.upload;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-09-14 06:08:37 +00:00
|
|
|
function initView() {
|
2016-12-25 20:34:02 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2017-09-21 14:00:53 +00:00
|
|
|
EndpointService.endpoint($transition$.params().id)
|
2017-09-14 06:08:37 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
var endpoint = data;
|
|
|
|
if (endpoint.URL.indexOf('unix://') === 0) {
|
2016-12-25 20:34:02 +00:00
|
|
|
$scope.endpointType = 'local';
|
|
|
|
} else {
|
|
|
|
$scope.endpointType = 'remote';
|
|
|
|
}
|
2017-09-22 05:34:17 +00:00
|
|
|
endpoint.URL = $filter('stripprotocol')(endpoint.URL);
|
|
|
|
$scope.endpoint = endpoint;
|
2017-09-14 06:08:37 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve endpoint details');
|
2017-09-14 06:08:37 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2016-12-25 20:34:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-14 06:08:37 +00:00
|
|
|
initView();
|
2016-12-25 20:34:02 +00:00
|
|
|
}]);
|