2016-09-16 13:55:46 +00:00
|
|
|
import Base from './base';
|
2016-09-13 19:50:37 +00:00
|
|
|
import endpoints from './endpoints';
|
2016-10-27 16:14:30 +00:00
|
|
|
import { appendTargetTypeToTargets } from '../redux/nodes/entities/targets/helpers';
|
2016-09-13 19:50:37 +00:00
|
|
|
|
2016-09-16 13:55:46 +00:00
|
|
|
class Kolide extends Base {
|
2016-11-07 16:42:39 +00:00
|
|
|
createQuery = ({ description, name, query }) => {
|
|
|
|
const { QUERIES } = endpoints;
|
|
|
|
|
|
|
|
return this.authenticatedPost(this.endpoint(QUERIES), JSON.stringify({ description, name, query }))
|
|
|
|
.then((response) => { return response.query; });
|
|
|
|
}
|
|
|
|
|
2016-09-19 23:43:35 +00:00
|
|
|
forgotPassword ({ email }) {
|
|
|
|
const { FORGOT_PASSWORD } = endpoints;
|
|
|
|
const forgotPasswordEndpoint = this.baseURL + FORGOT_PASSWORD;
|
|
|
|
|
2016-10-21 23:13:41 +00:00
|
|
|
return Base.post(forgotPasswordEndpoint, JSON.stringify({ email }));
|
2016-09-19 23:43:35 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 23:43:37 +00:00
|
|
|
getConfig = () => {
|
|
|
|
const { CONFIG } = endpoints;
|
|
|
|
|
|
|
|
return this.authenticatedGet(this.endpoint(CONFIG))
|
2016-10-21 23:13:41 +00:00
|
|
|
.then((response) => { return response.org_info; });
|
2016-10-05 23:43:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 21:08:57 +00:00
|
|
|
getInvites = () => {
|
|
|
|
const { INVITES } = endpoints;
|
|
|
|
|
|
|
|
return this.authenticatedGet(this.endpoint(INVITES))
|
2016-10-21 23:13:41 +00:00
|
|
|
.then((response) => { return response.invites; });
|
2016-10-14 21:08:57 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 18:55:03 +00:00
|
|
|
getHosts = () => {
|
|
|
|
const { HOSTS } = endpoints;
|
|
|
|
|
|
|
|
return this.authenticatedGet(this.endpoint(HOSTS))
|
2016-10-21 23:13:41 +00:00
|
|
|
.then((response) => { return response.hosts; });
|
2016-10-17 18:55:03 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 16:14:30 +00:00
|
|
|
getLabelHosts = (labelID) => {
|
|
|
|
const { LABEL_HOSTS } = endpoints;
|
|
|
|
console.log(LABEL_HOSTS(labelID));
|
|
|
|
|
|
|
|
const stubbedResponse = {
|
|
|
|
hosts: [
|
|
|
|
{
|
|
|
|
detail_updated_at: '2016-10-25T16:24:27.679472917-04:00',
|
|
|
|
hostname: 'jmeller-mbp.local',
|
|
|
|
id: 1,
|
|
|
|
ip: '192.168.1.10',
|
|
|
|
mac: '10:11:12:13:14:15',
|
|
|
|
memory: 4145483776,
|
|
|
|
os_version: 'Mac OS X 10.11.6',
|
|
|
|
osquery_version: '2.0.0',
|
|
|
|
platform: 'darwin',
|
|
|
|
status: 'online',
|
|
|
|
updated_at: '0001-01-01T00:00:00Z',
|
|
|
|
uptime: 3600000000000,
|
|
|
|
uuid: '1234-5678-9101',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
detail_updated_at: '2016-10-25T16:24:27.679472917-04:00',
|
|
|
|
hostname: 'Jason Meller\'s Windows Note',
|
|
|
|
id: 2,
|
|
|
|
ip: '192.168.1.11',
|
|
|
|
mac: '0C-BA-8D-45-FD-B9',
|
|
|
|
memory: 4145483776,
|
|
|
|
os_version: 'Windows Vista 0.0.1',
|
|
|
|
osquery_version: '2.0.0',
|
|
|
|
platform: 'windows',
|
|
|
|
status: 'offline',
|
|
|
|
updated_at: '0001-01-01T00:00:00Z',
|
|
|
|
uptime: 3600000000000,
|
|
|
|
uuid: '1234-5678-9101',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
return Promise.resolve(stubbedResponse)
|
|
|
|
.then((response) => { return response.hosts; });
|
|
|
|
}
|
|
|
|
|
2016-11-07 16:42:39 +00:00
|
|
|
getQuery = (queryID) => {
|
|
|
|
const { QUERIES } = endpoints;
|
|
|
|
const getQueryEndpoint = `${this.baseURL}${QUERIES}/${queryID}`;
|
|
|
|
|
|
|
|
return this.authenticatedGet(getQueryEndpoint)
|
|
|
|
.then((response) => { return response.query; });
|
|
|
|
}
|
|
|
|
|
2016-11-03 19:40:54 +00:00
|
|
|
getTargets = () => {
|
2016-10-27 16:14:30 +00:00
|
|
|
const stubbedResponse = {
|
|
|
|
targets: {
|
|
|
|
hosts: [
|
|
|
|
{
|
|
|
|
detail_updated_at: '2016-10-25T16:24:27.679472917-04:00',
|
|
|
|
hostname: 'jmeller-mbp.local',
|
|
|
|
id: 1,
|
|
|
|
ip: '192.168.1.10',
|
|
|
|
label: 'jmeller-mbp.local',
|
|
|
|
mac: '10:11:12:13:14:15',
|
|
|
|
memory: 4145483776,
|
|
|
|
os_version: 'Mac OS X 10.11.6',
|
|
|
|
osquery_version: '2.0.0',
|
|
|
|
platform: 'darwin',
|
|
|
|
status: 'online',
|
|
|
|
updated_at: '0001-01-01T00:00:00Z',
|
|
|
|
uptime: 3600000000000,
|
|
|
|
uuid: '1234-5678-9101',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
detail_updated_at: '2016-10-25T16:24:27.679472917-04:00',
|
|
|
|
hostname: 'Jason Meller\'s Windows Note',
|
|
|
|
id: 2,
|
|
|
|
ip: '192.168.1.11',
|
|
|
|
label: 'Jason Meller\'s Windows Note',
|
|
|
|
mac: '0C-BA-8D-45-FD-B9',
|
|
|
|
memory: 4145483776,
|
|
|
|
os_version: 'Windows Vista 0.0.1',
|
|
|
|
osquery_version: '2.0.0',
|
|
|
|
platform: 'windows',
|
|
|
|
status: 'offline',
|
|
|
|
updated_at: '0001-01-01T00:00:00Z',
|
|
|
|
uptime: 3600000000000,
|
|
|
|
uuid: '1234-5678-9101',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
labels: [
|
|
|
|
{
|
|
|
|
count: 1234,
|
|
|
|
id: 4,
|
|
|
|
label: 'All Hosts',
|
|
|
|
name: 'all',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
count: 38,
|
|
|
|
description: 'This group consists of machines utilized for developing within the WIN 10 environment',
|
|
|
|
id: 5,
|
|
|
|
label: 'Windows 10 Development',
|
|
|
|
name: 'windows10',
|
|
|
|
query: "SELECT * FROM last WHERE username = 'root' AND last.time > ((SELECT unix_time FROM time) - 3600);",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
selected_targets_count: 1234,
|
|
|
|
};
|
|
|
|
|
|
|
|
return Promise.resolve(stubbedResponse)
|
|
|
|
.then((response) => { return appendTargetTypeToTargets(response); });
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:54:22 +00:00
|
|
|
getUsers = () => {
|
|
|
|
const { USERS } = endpoints;
|
|
|
|
|
|
|
|
return this.authenticatedGet(this.endpoint(USERS))
|
2016-10-21 23:13:41 +00:00
|
|
|
.then((response) => { return response.users; });
|
2016-10-03 17:54:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 15:34:52 +00:00
|
|
|
inviteUser = (formData) => {
|
|
|
|
const { INVITES } = endpoints;
|
|
|
|
|
2016-10-14 21:08:57 +00:00
|
|
|
return this.authenticatedPost(this.endpoint(INVITES), JSON.stringify(formData))
|
2016-10-21 23:13:41 +00:00
|
|
|
.then((response) => { return response.invite; });
|
2016-10-11 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2016-09-13 19:50:37 +00:00
|
|
|
loginUser ({ username, password }) {
|
|
|
|
const { LOGIN } = endpoints;
|
2016-09-16 13:55:46 +00:00
|
|
|
const loginEndpoint = this.baseURL + LOGIN;
|
2016-09-13 19:50:37 +00:00
|
|
|
|
2016-10-21 23:13:41 +00:00
|
|
|
return Base.post(loginEndpoint, JSON.stringify({ username, password }));
|
2016-09-16 13:55:46 +00:00
|
|
|
}
|
2016-09-13 19:50:37 +00:00
|
|
|
|
2016-09-19 23:43:35 +00:00
|
|
|
logout () {
|
|
|
|
const { LOGOUT } = endpoints;
|
|
|
|
const logoutEndpoint = this.baseURL + LOGOUT;
|
2016-09-13 19:50:37 +00:00
|
|
|
|
2016-09-19 23:43:35 +00:00
|
|
|
return this.authenticatedPost(logoutEndpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
me () {
|
|
|
|
const { ME } = endpoints;
|
|
|
|
const meEndpoint = this.baseURL + ME;
|
|
|
|
|
|
|
|
return this.authenticatedGet(meEndpoint);
|
2016-09-13 19:50:37 +00:00
|
|
|
}
|
2016-09-19 15:35:38 +00:00
|
|
|
|
|
|
|
resetPassword (formData) {
|
|
|
|
const { RESET_PASSWORD } = endpoints;
|
|
|
|
const resetPasswordEndpoint = this.baseURL + RESET_PASSWORD;
|
|
|
|
|
2016-10-21 23:13:41 +00:00
|
|
|
return Base.post(resetPasswordEndpoint, JSON.stringify(formData));
|
2016-09-19 15:35:38 +00:00
|
|
|
}
|
2016-10-03 17:54:22 +00:00
|
|
|
|
2016-10-14 21:08:57 +00:00
|
|
|
revokeInvite = ({ entityID }) => {
|
|
|
|
const { INVITES } = endpoints;
|
|
|
|
const endpoint = `${this.endpoint(INVITES)}/${entityID}`;
|
|
|
|
|
|
|
|
return this.authenticatedDelete(endpoint);
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:54:22 +00:00
|
|
|
updateUser = (user, formData) => {
|
|
|
|
const { USERS } = endpoints;
|
|
|
|
const updateUserEndpoint = `${this.baseURL}${USERS}/${user.id}`;
|
|
|
|
|
2016-10-11 16:22:11 +00:00
|
|
|
return this.authenticatedPatch(updateUserEndpoint, JSON.stringify(formData))
|
2016-10-21 23:13:41 +00:00
|
|
|
.then((response) => { return response.user; });
|
2016-10-03 17:54:22 +00:00
|
|
|
}
|
2016-09-13 19:50:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new Kolide();
|