2018-06-04 14:31:26 +00:00
|
|
|
/*
|
2018-12-13 10:02:53 +00:00
|
|
|
* Wazuh app - Factory to share an agent between controllers
|
|
|
|
*
|
2019-01-14 16:36:47 +00:00
|
|
|
* Copyright (C) 2015-2019 Wazuh, Inc.
|
2018-12-13 10:02:53 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Find more information about this on the LICENSE file.
|
|
|
|
*/
|
2018-09-11 09:52:54 +00:00
|
|
|
export class ShareAgent {
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Class constructor
|
|
|
|
*/
|
2018-09-10 08:32:49 +00:00
|
|
|
constructor() {
|
|
|
|
this.agent = null;
|
2018-09-24 15:47:10 +00:00
|
|
|
this.selectedGroup = null;
|
2018-10-03 14:14:51 +00:00
|
|
|
this.targetLocation = null;
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-06-04 14:31:26 +00:00
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Get current agent
|
|
|
|
*/
|
2018-09-10 08:32:49 +00:00
|
|
|
getAgent() {
|
|
|
|
return this.agent;
|
|
|
|
}
|
2018-08-20 07:00:50 +00:00
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Get selected group
|
|
|
|
*/
|
2018-09-24 15:47:10 +00:00
|
|
|
getSelectedGroup() {
|
2018-12-13 10:02:53 +00:00
|
|
|
if (
|
|
|
|
this.agent &&
|
|
|
|
this.agent.group &&
|
|
|
|
(this.selectedGroup || this.selectedGroup === 0)
|
|
|
|
) {
|
2018-11-05 13:36:01 +00:00
|
|
|
return this.agent.group[this.selectedGroup];
|
|
|
|
}
|
|
|
|
return null;
|
2018-09-24 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Set a given agent and group as current
|
2018-12-13 10:02:53 +00:00
|
|
|
* @param {*} ag
|
|
|
|
* @param {*} group
|
2018-12-12 11:47:05 +00:00
|
|
|
*/
|
2018-09-24 15:47:10 +00:00
|
|
|
setAgent(ag, group) {
|
2018-09-10 08:32:49 +00:00
|
|
|
this.agent = ag;
|
2018-09-24 15:47:10 +00:00
|
|
|
this.selectedGroup = group;
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-08-20 07:00:50 +00:00
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Delete current agent
|
|
|
|
*/
|
2018-09-10 08:32:49 +00:00
|
|
|
deleteAgent() {
|
|
|
|
this.agent = null;
|
2018-09-24 15:47:10 +00:00
|
|
|
this.selectedGroup = null;
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-10-03 14:14:51 +00:00
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Get Target location
|
|
|
|
*/
|
2018-10-03 14:14:51 +00:00
|
|
|
getTargetLocation() {
|
|
|
|
return this.targetLocation;
|
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Set Target location
|
2018-12-13 10:02:53 +00:00
|
|
|
* @param {Object} loc
|
2018-12-12 11:47:05 +00:00
|
|
|
*/
|
2018-10-03 14:14:51 +00:00
|
|
|
setTargetLocation(loc) {
|
2018-11-02 17:23:00 +00:00
|
|
|
if (!loc || typeof loc !== 'object') return;
|
2018-10-03 14:14:51 +00:00
|
|
|
this.targetLocation = {};
|
|
|
|
Object.assign(this.targetLocation, loc);
|
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Delete target location
|
|
|
|
*/
|
2018-10-03 14:14:51 +00:00
|
|
|
deleteTargetLocation() {
|
|
|
|
this.targetLocation = null;
|
|
|
|
}
|
2018-08-20 07:00:50 +00:00
|
|
|
}
|