Skip to content

Commit

Permalink
Merge branch 'refs/heads/add-xsoar'
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Jul 2, 2024
2 parents 6e73e6e + c7c39e9 commit 3a7001c
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Github issues and feature requests welcomed.
| Logging | sentryio |
| MacOS | airport<br/>macchanger<br/>wdutil |
| Python | logging<br/>requests |
| SOAR | swimlane<br/>splunk soar |
| SOAR | swimlane<br/>splunk soar<br/>xsoar |
| Recon | nmap |
| Test Automation | selenium |

Expand Down
16 changes: 12 additions & 4 deletions automon/integrations/requestsWrapper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def __init__(self, url: str = None, data: dict = None, headers: dict = None,

self.config = config or RequestsConfig()

self.url = url
self.data = data
self.errors = None
self.headers = headers
self.url: str = url
self.data: dict = data
self.errors: bytes = b''
self.headers: dict = headers
self.response = None
self.requests = requests
self.session = self.requests.Session()
Expand Down Expand Up @@ -122,6 +122,8 @@ async def get(
if self.status_code == 200:
return True

self.errors = self.content

return False
except Exception as e:
self.errors = e
Expand Down Expand Up @@ -151,6 +153,8 @@ async def patch(
if self.status_code == 200:
return True

self.errors = self.content

return False
except Exception as e:
self.errors = e
Expand Down Expand Up @@ -180,6 +184,8 @@ async def post(
if self.status_code == 200:
return True

self.errors = self.content

return False
except Exception as e:
self.errors = e
Expand Down Expand Up @@ -209,6 +215,8 @@ async def put(
if self.status_code == 200:
return True

self.errors = self.content

return False
except Exception as e:
self.errors = e
Expand Down
1 change: 1 addition & 0 deletions automon/integrations/requestsWrapper/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
logger = log.logging.getLogger(__name__)
logger.setLevel(log.DEBUG)


class BaseRestClient:
requests: RequestsClient
config: RequestsConfig
Expand Down
2 changes: 1 addition & 1 deletion automon/integrations/requestsWrapper/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Client(unittest.TestCase):
def test_get(self):
self.assertTrue(asyncio.run(r.get('https://1.1.1.1')))
self.assertTrue(r.requests.get('https://1.1.1.1'))
self.assertTrue(asyncio.run(r.requests.get('https://1.1.1.1')))
self.assertFalse(asyncio.run(r.get('x://127.0.0.1')))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from automon.integrations.requestsWrapper.rest import BaseRestClient


class Test(BaseRestClient):
class Inherit(BaseRestClient):

def __init__(self):
BaseRestClient.__init__(self)
super().__init__()
pass


class Client(unittest.TestCase):
def test_get(self):
self.assertTrue(asyncio.run(Test().get(url='https://1.1.1.1')))
self.assertTrue(asyncio.run(Inherit().get(url='https://1.1.1.1')))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion automon/integrations/seleniumWrapper/webdriver_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def chromedriver_path(self):
if os.path.exists(path):
return path

logger.error('missing SELENIUM_CHROMEDRIVER_PATH')
raise Exception('missing SELENIUM_CHROMEDRIVER_PATH')

@property
def chromedriverVersion(self):
Expand Down
2 changes: 2 additions & 0 deletions automon/integrations/xsoar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .client import XSOARClient
from .config import XSOARConfig
68 changes: 68 additions & 0 deletions automon/integrations/xsoar/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from automon.log import logging
from automon.integrations.requestsWrapper import RequestsClient

from .config import XSOARConfig
from .endpoints import v1

logger = logging.getLogger(__name__)
logger.setLevel(level=logging.DEBUG)


class XSOARClient(object):
"""XSOAR REST API client
referenc: https://cortex-panw.stoplight.io/docs/cortex-xsoar-8/kjn2q21a7yrbm-get-started-with-cortex-xsoar-8-ap-is
"""

def __init__(
self,
host: str = None,
api_key: str = None,
api_key_id: str = None,
config: XSOARConfig = None
):
self.config = config or XSOARConfig(host=host, api_key=api_key, api_key_id=api_key_id)
self._requests = RequestsClient()

async def is_ready(self):
if self.config.is_ready():
return True
return False

async def auth(self):
return

@property
def errors(self):
return self._requests.errors

async def get(self, endpoint: str):
logger.info(dict(
endpoint=f'{self.config.host}/{endpoint}'
))
response = await self._requests.get(url=f'{self.config.host}/{endpoint}', headers=self.config.headers)

if response:
return response

logger.error(self.errors)
raise Exception(self.errors)

async def post(self, endpoint: str):
logger.info(dict(
endpoint=f'{self.config.host}/{endpoint}'
))
response = self._requests.post(url=f'{self.config.host}/{endpoint}', headers=self.config.headers)

if response:
return response

logger.error(self.errors)
raise Exception(self.errors)

async def reports(self):
reports = await self.get(endpoint=v1.Reports.reports)
logger.info(dict(
reports=self._requests.content
))
return reports
41 changes: 41 additions & 0 deletions automon/integrations/xsoar/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from automon import environ
from automon.log import logging

logger = logging.getLogger(__name__)
logger.setLevel(level=logging.DEBUG)


class XSOARConfig(object):
"""XSOAR REST API client config"""

def __init__(
self,
host: str = None,
api_key: str = None,
api_key_id: str = None
):
self.host = host or environ('XSOAR_FQDN')
self.api_key = api_key or environ('XSOAR_API_KEY')
self.api_key_id = api_key_id or environ('XSOAR_API_KEY_ID')

def is_ready(self) -> bool:
if not self.host:
logger.error(f'missing XSOAR_FQDN')

if not self.api_key:
logger.error(f'missing XSOAR_API_KEY')

if not self.api_key_id:
logger.error(f'missing XSOAR_API_KEY_ID')

if self.host and self.api_key and self.api_key_id:
return True
return False

@property
def headers(self):
return {
'Authorization': f'{self.api_key}',
'x-xdr-auth-id': f'{self.api_key_id}',
"Content-Type": "application/json"
}
Empty file.
9 changes: 9 additions & 0 deletions automon/integrations/xsoar/endpoints/v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class V1:
xsoar: str = 'xsoar'
public: str = f'{xsoar}/public'
v1: str = f'{public}/v1'


class Reports:
"""xsoar/public/v1/reports"""
reports: str = f'{V1.v1}/reports'
Empty file.
17 changes: 17 additions & 0 deletions automon/integrations/xsoar/tests/test_client_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import asyncio
import unittest

from automon.integrations.xsoar import XSOARClient


class MyTestCase(unittest.TestCase):
test = XSOARClient()

if asyncio.run(test.is_ready()):
def test_auth(self):
result = asyncio.run(self.test.reports())
pass


if __name__ == '__main__':
unittest.main()
15 changes: 15 additions & 0 deletions automon/integrations/xsoar/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

from automon.integrations.xsoar import XSOARConfig


class MyTestCase(unittest.TestCase):
test = XSOARConfig()

if test.is_ready():
def test_config(self):
self.assertTrue(self.test.is_ready())


if __name__ == '__main__':
unittest.main()
5 changes: 5 additions & 0 deletions env-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ VDS_PASSWORD=

# Wdutil
WDUTIL_PASSWORD=

# XSOAR
XSOAR_FQDN=
XSOAR_API_KEY=
XSOAR_API_KEY_ID=
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pytz>=2021.1

# selenium
selenium>=3.141.0
beautifulsoup4>=4.10.0

# sentry.io
sentry-sdk>=1.5.1
Expand Down

0 comments on commit 3a7001c

Please sign in to comment.