-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
150 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .client import WdutilClient | ||
from .config import WdutilConfig |
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,34 @@ | ||
from automon import logging | ||
from automon import log_secret | ||
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() | ||
|
||
secret = f'echo {self.config.password} | ' | ||
command = f'sudo -S {self.wdutil} {arg}' | ||
|
||
log.info(f'echo {log_secret(self.config.password)} | {command}') | ||
return self._runner.run(command=f'{secret}{command}', shell=True) | ||
|
||
def is_ready(self): | ||
if self.config.is_ready(): | ||
return True | ||
return False | ||
|
||
def help(self): | ||
return self.run('help') |
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,44 @@ | ||
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 not self.password: | ||
log.error(f'missing WDUTIL_PASSWORD') | ||
|
||
if not self.wdutil_path(): | ||
log.error(f'missing wdutil') | ||
|
||
if self.password and self.wdutil_path(): | ||
return True | ||
|
||
return False | ||
|
||
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 |
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 @@ | ||
class WdutilConfigNotReady(Exception): | ||
pass |
Empty file.
18 changes: 18 additions & 0 deletions
18
automon/integrations/mac/wdutil/tests/test_client_ready.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,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() |
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,16 @@ | ||
import unittest | ||
|
||
from automon import os_is_mac | ||
from automon.integrations.mac.wdutil import WdutilClient | ||
|
||
|
||
class MyTestCase(unittest.TestCase): | ||
if WdutilClient().is_ready(): | ||
def test_something(self): | ||
client = WdutilClient() | ||
self.assertTrue(client.run('info')) | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,14 @@ | ||
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): | ||
self.assertFalse(WdutilConfig().is_ready()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,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() |
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