-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLGN-429] - Sentinelone -Adding new action for move agents between s…
…ites (#2097) (#2098) * [PLGN-429] - Sentinelone -Adding new action for move agents between sites (#2097) * PLGN-429-Adding new action for move agents between sites * PLGN-429-renaming var from filet to agents_filter * PLGN-429-making ID capital letetrs and rewording version history text * PLGN-429-making ID capital letetrs and rewording version history text * PLGN-429-Adding in required user permissons to description * PLGN-429-rewording required user permissons to description * PLGN-429-Making sure type string is not in quotes, minor fix to description of action (#2099) * PLGN-429-Making sure type string is not in quotes, minor fix to description of action * PLGN-429-Making sure type string is not in quotes, minor fix to description of action
- Loading branch information
1 parent
e4de8b0
commit 12eee92
Showing
19 changed files
with
243 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,5 @@ | |
|
||
from .run_remote_script.action import RunRemoteScript | ||
|
||
from .move_between_sites.action import MoveBetweenSites | ||
|
2 changes: 2 additions & 0 deletions
2
plugins/sentinelone/komand_sentinelone/actions/move_between_sites/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT | ||
from .action import MoveBetweenSites |
26 changes: 26 additions & 0 deletions
26
plugins/sentinelone/komand_sentinelone/actions/move_between_sites/action.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import insightconnect_plugin_runtime | ||
from .schema import MoveBetweenSitesInput, MoveBetweenSitesOutput, Input, Output, Component | ||
|
||
# Custom imports below | ||
|
||
|
||
class MoveBetweenSites(insightconnect_plugin_runtime.Action): | ||
def __init__(self): | ||
super(self.__class__, self).__init__( | ||
name="move_between_sites", | ||
description=Component.DESCRIPTION, | ||
input=MoveBetweenSitesInput(), | ||
output=MoveBetweenSitesOutput(), | ||
) | ||
|
||
def run(self, params={}): | ||
agents_filter = params.get(Input.FILTER, {}) | ||
data = {"targetSiteId": (params.get(Input.TARGETSITEID, ""))} | ||
|
||
return { | ||
Output.AFFECTED: self.connection.client.agents_action_move_agent_to_new_site( | ||
agents_filter, data, "move-to-site" | ||
) | ||
.get("data", {}) | ||
.get("affected", 0) | ||
} |
67 changes: 67 additions & 0 deletions
67
plugins/sentinelone/komand_sentinelone/actions/move_between_sites/schema.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT | ||
import insightconnect_plugin_runtime | ||
import json | ||
|
||
|
||
class Component: | ||
DESCRIPTION = "Move an agent to another site. This action requires Account or Global level access for your user role" | ||
|
||
|
||
class Input: | ||
FILTER = "filter" | ||
TARGETSITEID = "targetSiteId" | ||
|
||
|
||
class Output: | ||
AFFECTED = "affected" | ||
|
||
|
||
class MoveBetweenSitesInput(insightconnect_plugin_runtime.Input): | ||
schema = json.loads(r""" | ||
{ | ||
"type": "object", | ||
"title": "Variables", | ||
"properties": { | ||
"filter": { | ||
"type": "object", | ||
"title": "Filter JSON", | ||
"description": "Applied filter - only matched agents will be affected by the requested action. Leave empty to apply the action on all applicable agents", | ||
"order": 2 | ||
}, | ||
"targetSiteId": { | ||
"type": "string", | ||
"title": "Target Site ID", | ||
"description": "The ID of the new site to move the agents to", | ||
"order": 1 | ||
} | ||
}, | ||
"required": [ | ||
"targetSiteId" | ||
], | ||
"definitions": {} | ||
} | ||
""") | ||
|
||
def __init__(self): | ||
super(self.__class__, self).__init__(self.schema) | ||
|
||
|
||
class MoveBetweenSitesOutput(insightconnect_plugin_runtime.Output): | ||
schema = json.loads(r""" | ||
{ | ||
"type": "object", | ||
"title": "Variables", | ||
"properties": { | ||
"affected": { | ||
"type": "integer", | ||
"title": "Affected", | ||
"description": "Number of entities affected by the requested operation", | ||
"order": 1 | ||
} | ||
}, | ||
"definitions": {} | ||
} | ||
""") | ||
|
||
def __init__(self): | ||
super(self.__class__, self).__init__(self.schema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
plugins/sentinelone/unit_test/expected/move_between_sites_data.json.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"affected": 1 | ||
} |
3 changes: 3 additions & 0 deletions
3
plugins/sentinelone/unit_test/expected/move_between_sites_minimum.json.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"affected": 2 | ||
} |
6 changes: 6 additions & 0 deletions
6
plugins/sentinelone/unit_test/inputs/move_between_sites_data.json.inp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"targetSiteId" : "1234567891234567891", | ||
"filter": { | ||
"computerName": "WindowsX64" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
plugins/sentinelone/unit_test/inputs/move_between_sites_minimum.json.inp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"targetSiteId" : "1234567891234567890" | ||
} |
5 changes: 5 additions & 0 deletions
5
plugins/sentinelone/unit_test/responses/move_between_sites_data.json.resp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"affected": 1 | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
plugins/sentinelone/unit_test/responses/move_between_sites_minimum.json.resp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"affected": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
import os | ||
|
||
sys.path.append(os.path.abspath("../")) | ||
|
||
from unittest import TestCase | ||
from unittest.mock import patch | ||
from komand_sentinelone.actions.move_between_sites import MoveBetweenSites | ||
from util import Util | ||
from parameterized import parameterized | ||
|
||
|
||
@patch("requests.request", side_effect=Util.mocked_requests_get) | ||
class TestMoveBetweenSites(TestCase): | ||
@classmethod | ||
@patch("requests.post", side_effect=Util.mocked_requests_get) | ||
def setUpClass(cls, mock_request) -> None: | ||
cls.action = Util.default_connector(MoveBetweenSites()) | ||
|
||
@parameterized.expand( | ||
[ | ||
[ | ||
"move_between_sites_minimum", | ||
Util.read_file_to_dict("inputs/move_between_sites_minimum.json.inp"), | ||
Util.read_file_to_dict("expected/move_between_sites_minimum.json.exp"), | ||
], | ||
[ | ||
"move_between_sites_data", | ||
Util.read_file_to_dict("inputs/move_between_sites_data.json.inp"), | ||
Util.read_file_to_dict("expected/move_between_sites_data.json.exp"), | ||
], | ||
] | ||
) | ||
def test_agents_action(self, mock_request, test_name, input_params, expected): | ||
actual = self.action.run(input_params) | ||
self.assertEqual(expected, actual) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters