Skip to content

Commit

Permalink
wdutil: add client and config
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed May 15, 2024
1 parent e044a20 commit a4f2669
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Github issues and feature requests welcomed.
| Google Cloud | google auth api<br/>google people api<br/>google sheets api |
| Helpers | os<br/>subprocess<br/>threading<br/>socket<br/>datetime |
| Logging | sentryio |
| MacOS | airport<br/>macchanger |
| MacOS | airport<br/>macchanger<br/>wdutil |
| Python | logging<br/>requests |
| SOAR | swimlane<br/>splunk soar |
| Recon | nmap |
Expand Down
2 changes: 2 additions & 0 deletions automon/integrations/mac/wdutil/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .client import WdutilClient
from .config import WdutilConfig
33 changes: 33 additions & 0 deletions automon/integrations/mac/wdutil/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from automon import logging
from automon import os_is_mac
from automon.helpers import Run

from .config import WdutilConfig

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


class WdutilClient(object):

def __init__(self, config: WdutilConfig = None, wdutil_path: str = None):
self.config = config or WdutilConfig(wdutil_path=wdutil_path)
self.wdutil = self.config.wdutil_path()

self._runner = Run()

def run(self, arg: str):
self.config.is_ready()

command = f'echo {self.config.password} | sudo -S {self.wdutil} {arg}'
command = f'{self.wdutil} {arg}'
log.info(f'{command}')
self._runner.run(command=command, shell=True)

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

def help(self):
return self.run('help')
38 changes: 38 additions & 0 deletions automon/integrations/mac/wdutil/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from automon import Run
from automon import environ
from automon import logging
from automon import os_is_mac

from .exceptions import *

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


class WdutilConfig(object):

def __init__(self, password: str = None, wdutil_path: str = None):
self.password = password or environ('WDUTIL_PASSWORD')
self._wdutil_path = wdutil_path
self._runner = Run()

def is_ready(self):
if self.password and self.wdutil_path:
return True

raise (WdutilConfigNotReady(f'missing WDUTIL_PASSWORD or missing wdutil'))

def wdutil_path(self):
if os_is_mac():

if self._wdutil_path:
return self._wdutil_path

if self._runner.which('wdutil'):
self._wdutil_path = self._runner.stdout.decode().strip()
log.info(str(dict(
wdutil_path=self._wdutil_path
)))
return self._wdutil_path

return False
2 changes: 2 additions & 0 deletions automon/integrations/mac/wdutil/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class WdutilConfigNotReady(Exception):
pass
Empty file.
18 changes: 18 additions & 0 deletions automon/integrations/mac/wdutil/tests/test_client_ready.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest

from automon import os_is_mac
from automon.integrations.mac.wdutil import WdutilClient, WdutilConfig


class MyTestCase(unittest.TestCase):
if os_is_mac():
if WdutilConfig().is_ready():

def test_something(self):
self.assertTrue(
WdutilClient().is_ready()
)


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

from automon import os_is_mac
from automon.integrations.mac.wdutil import WdutilConfig


class MyTestCase(unittest.TestCase):
if os_is_mac():
def test_something(self):
with self.assertRaises(Exception):
WdutilConfig().is_ready()


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

from automon import os_is_mac
from automon.integrations.mac.wdutil import WdutilClient


class MyTestCase(unittest.TestCase):

if os_is_mac():
def test_something(self):
self.assertTrue(WdutilClient().wdutil)


if __name__ == '__main__':
unittest.main()
3 changes: 3 additions & 0 deletions env-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ LDAP_PORT=
VDS_BIND_USER=cn=automon,ou=people,dc=automon,dc=com
VDS_BASE_DN=dc=automon,dc=com
VDS_PASSWORD=

# Wdutil
WDUTIL_PASSWORD=

0 comments on commit a4f2669

Please sign in to comment.