Skip to content

Commit 3cafbbd

Browse files
committed
IDEV-1985: Enhance implementation
1 parent f996449 commit 3cafbbd

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

domaintools_iris_connector.py

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ class DomainToolsConnector(BaseConnector):
3333
ACTION_ID_LOAD_HASH = "load_hash"
3434
ACTION_ID_ON_POLL = "on_poll"
3535
ACTION_ID_CONFIGURE_SCHEDULED_PLAYBOOK = "configure_monitoring_scheduled_playbooks"
36+
37+
# RTUF action_ids
3638
ACTION_ID_NOD_FEED = "nod_feed"
3739
ACTION_ID_NAD_FEED = "nad_feed"
3840
ACTION_ID_DOMAIN_DISCOVERY_FEED = "domain_discovery_feed"
41+
RTUF_SERVICES_LIST = ["nod", "nad", "domaindiscovery"]
3942

4043
def __init__(self):
4144
# Call the BaseConnectors init first
@@ -47,6 +50,22 @@ def __init__(self):
4750
self._domains = None
4851
self._proxy_url = None
4952
self._scheduled_playbooks_list_name = "domaintools_scheduled_playbooks"
53+
self.ACTION_ID_TO_ACTION = {
54+
phantom.ACTION_ID_TEST_ASSET_CONNECTIVITY: self._test_connectivity,
55+
self.ACTION_ID_DOMAIN_REPUTATION: self._domain_reputation,
56+
self.ACTION_ID_DOMAIN_ENRICH: self._domain_enrich,
57+
self.ACTION_ID_DOMAIN_INVESTIGATE: self._domain_investigate,
58+
self.ACTION_ID_PIVOT: self._pivot_action,
59+
self.ACTION_ID_REVERSE_IP: self._reverse_lookup_ip,
60+
self.ACTION_ID_REVERSE_EMAIL: self._reverse_whois_email,
61+
self.ACTION_ID_REVERSE_DOMAIN: self._reverse_lookup_domain,
62+
self.ACTION_ID_LOAD_HASH: self._load_hash,
63+
self.ACTION_ID_ON_POLL: self._on_poll,
64+
self.ACTION_ID_CONFIGURE_SCHEDULED_PLAYBOOK: self._configure_monitoring_scheduled_playbooks,
65+
self.ACTION_ID_NOD_FEED: self._nod_feed,
66+
self.ACTION_ID_NAD_FEED: self._nad_feed,
67+
self.ACTION_ID_DOMAIN_DISCOVERY_FEED: self._domain_discovery_feed,
68+
}
5069

5170
def initialize(self):
5271
# get the app configuation - super class pulls domaintools_iris.json
@@ -68,9 +87,6 @@ def initialize(self):
6887

6988
return phantom.APP_SUCCESS
7089

71-
def _is_feeds_service(self, service):
72-
return service in ("nod", "nad", "domaindiscovery")
73-
7490
def _handle_py_ver_for_byte(self, input_str):
7591
"""
7692
This method returns the binary|original string based on the Python version.
@@ -114,7 +130,7 @@ def _parse_feeds_response(self, service, action_result, feeds_results):
114130
rows = response.strip().split("\n")
115131

116132
for row in rows:
117-
if service in ("nod", "nad", "domaindiscovery"):
133+
if service in self.RTUF_SERVICES_LIST:
118134
feed_result = json.loads(row)
119135
data.append(
120136
{
@@ -244,7 +260,7 @@ def _do_query(self, service, action_result, query_args=None):
244260
response = service_api(**query_args, position=position)
245261

246262
try:
247-
if self._is_feeds_service(service):
263+
if service in self.RTUF_SERVICES_LIST:
248264
# Separate parsing of feeds product
249265
return self._parse_feeds_response(service, action_result, response)
250266

@@ -324,8 +340,6 @@ def _test_connectivity(self):
324340
)
325341

326342
def handle_action(self, param):
327-
ret_val = phantom.APP_SUCCESS
328-
329343
# Get the action that we are supposed to execute for this App Run
330344
action_id = self.get_action_identifier()
331345

@@ -352,36 +366,15 @@ def handle_action(self, param):
352366
self._domains = self._get_domains(hostnames)
353367

354368
# Handle the actions
355-
if action_id == phantom.ACTION_ID_TEST_ASSET_CONNECTIVITY:
356-
ret_val = self._test_connectivity()
357-
elif action_id == self.ACTION_ID_DOMAIN_ENRICH:
358-
ret_val = self._domain_enrich(param)
359-
elif action_id == self.ACTION_ID_DOMAIN_INVESTIGATE:
360-
ret_val = self._domain_investigate(param)
361-
elif action_id == self.ACTION_ID_DOMAIN_REPUTATION:
362-
ret_val = self._domain_reputation(param)
363-
elif action_id == self.ACTION_ID_PIVOT:
364-
ret_val = self._pivot_action(param)
365-
elif action_id == self.ACTION_ID_REVERSE_IP:
366-
ret_val = self._reverse_lookup_ip(param)
367-
elif action_id == self.ACTION_ID_REVERSE_EMAIL:
368-
ret_val = self._reverse_whois_email(param)
369-
elif action_id == self.ACTION_ID_REVERSE_DOMAIN:
370-
ret_val = self._reverse_lookup_domain(param)
371-
elif action_id == self.ACTION_ID_LOAD_HASH:
372-
ret_val = self._load_hash(param)
373-
elif action_id == self.ACTION_ID_ON_POLL:
374-
ret_val = self._on_poll(param)
375-
elif action_id == self.ACTION_ID_CONFIGURE_SCHEDULED_PLAYBOOK:
376-
ret_val = self._configure_monitoring_scheduled_playbooks(param)
377-
elif action_id == self.ACTION_ID_NOD_FEED:
378-
ret_val = self._nod_feed(param)
379-
elif action_id == self.ACTION_ID_NAD_FEED:
380-
ret_val = self._nad_feed(param)
381-
elif action_id == self.ACTION_ID_DOMAIN_DISCOVERY_FEED:
382-
ret_val = self._domain_discovery_feed(param)
383-
384-
return ret_val
369+
action = self.ACTION_ID_TO_ACTION.get(action_id)
370+
if action:
371+
if action_id == phantom.ACTION_ID_TEST_ASSET_CONNECTIVITY:
372+
# Special handling as this requires no param
373+
return action()
374+
375+
return action(param)
376+
377+
return phantom.APP_SUCCESS
385378

386379
def _get_proxy_url(self, config):
387380
proxy_url = None

0 commit comments

Comments
 (0)