2017-10-20 19:12:08 +00:00
|
|
|
import chrome from 'ui/chrome';
|
|
|
|
require('ui/modules').get('app/wazuh', [])
|
2017-10-30 10:35:30 +00:00
|
|
|
.service('testAPI', function ($q, $http) {
|
|
|
|
return {
|
2017-12-20 16:48:44 +00:00
|
|
|
check_stored: data => {
|
2017-10-30 10:35:30 +00:00
|
|
|
let defered = $q.defer();
|
2017-12-14 15:08:38 +00:00
|
|
|
$http.post(chrome.addBasePath('/api/wazuh-api/checkStoredAPI'), data,{timeout: 4000})
|
2017-10-30 10:35:30 +00:00
|
|
|
.then((response) => {
|
|
|
|
if (response.error) {
|
|
|
|
defered.reject(response);
|
|
|
|
} else {
|
|
|
|
defered.resolve(response);
|
|
|
|
}
|
|
|
|
})
|
2017-12-14 15:08:38 +00:00
|
|
|
.catch(error => {
|
|
|
|
if(error.status && error.status === -1){
|
|
|
|
defered.reject({data: 'request_timeout_checkstored'});
|
|
|
|
} else if (error.error) {
|
2017-10-30 10:35:30 +00:00
|
|
|
defered.reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return defered.promise;
|
|
|
|
},
|
2017-12-20 16:48:44 +00:00
|
|
|
check: data => {
|
2017-10-30 10:35:30 +00:00
|
|
|
let defered = $q.defer();
|
2017-12-14 15:08:38 +00:00
|
|
|
$http.post(chrome.addBasePath("/api/wazuh-api/checkAPI"), data, {timeout: 4000})
|
2017-10-30 10:35:30 +00:00
|
|
|
.then((response) => {
|
|
|
|
if (response.error) {
|
|
|
|
defered.reject(response);
|
|
|
|
} else {
|
|
|
|
defered.resolve(response);
|
|
|
|
}
|
|
|
|
})
|
2017-12-14 15:08:38 +00:00
|
|
|
.catch(error => {
|
|
|
|
if(error.status && error.status === -1){
|
|
|
|
defered.reject({data: 'request_timeout_checkapi'});
|
2017-12-20 16:48:44 +00:00
|
|
|
} else if (error.data && error.data.message && error.data.message === 'wrong_credentials') {
|
|
|
|
defered.reject({data: 'wrong_credentials'});
|
2017-12-14 15:08:38 +00:00
|
|
|
}else if (error.error) {
|
2017-10-30 10:35:30 +00:00
|
|
|
defered.reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return defered.promise;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|