Fixed circular imports
This commit is contained in:
parent
1ffdc7528f
commit
44a1f70da9
|
@ -4,7 +4,8 @@ import random
|
|||
import string
|
||||
import subprocess
|
||||
|
||||
from infection_monkey.utils.auto_new_user import NewUserError, create_auto_new_user
|
||||
from infection_monkey.utils.new_user_error import NewUserError
|
||||
from infection_monkey.utils.auto_new_user_factory import create_auto_new_user
|
||||
from common.data.post_breach_consts import POST_BREACH_COMMUNICATE_AS_NEW_USER
|
||||
from infection_monkey.post_breach.pba import PBA
|
||||
from infection_monkey.telemetry.post_breach_telem import PostBreachTelem
|
||||
|
|
|
@ -1,17 +1,9 @@
|
|||
import logging
|
||||
import abc
|
||||
|
||||
from infection_monkey.utils.environment import is_windows_os
|
||||
from infection_monkey.utils.linux.users import AutoNewLinuxUser
|
||||
from infection_monkey.utils.windows.users import AutoNewWindowsUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NewUserError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AutoNewUser:
|
||||
"""
|
||||
RAII object to use for creating and using a new user. Use with `with`.
|
||||
|
@ -40,23 +32,3 @@ class AutoNewUser:
|
|||
@abc.abstractmethod
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def create_auto_new_user(username, password, is_windows=is_windows_os()):
|
||||
"""
|
||||
Factory method for creating an AutoNewUser. See AutoNewUser's documentation for more information.
|
||||
Example usage:
|
||||
with create_auto_new_user(username, PASSWORD) as new_user:
|
||||
...
|
||||
:param username: The username of the new user.
|
||||
:param password: The password of the new user.
|
||||
:param is_windows: If True, a new Windows user is created. Otherwise, a Linux user is created. Leave blank for
|
||||
automatic detection.
|
||||
:return: The new AutoNewUser object - use with a `with` scope.
|
||||
"""
|
||||
if is_windows:
|
||||
return AutoNewWindowsUser(username, password)
|
||||
else:
|
||||
return AutoNewLinuxUser(username, password)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
from infection_monkey.utils.environment import is_windows_os
|
||||
from infection_monkey.utils.linux.users import AutoNewLinuxUser
|
||||
from infection_monkey.utils.windows.users import AutoNewWindowsUser
|
||||
|
||||
|
||||
def create_auto_new_user(username, password, is_windows=is_windows_os()):
|
||||
"""
|
||||
Factory method for creating an AutoNewUser. See AutoNewUser's documentation for more information.
|
||||
Example usage:
|
||||
with create_auto_new_user(username, PASSWORD) as new_user:
|
||||
...
|
||||
:param username: The username of the new user.
|
||||
:param password: The password of the new user.
|
||||
:param is_windows: If True, a new Windows user is created. Otherwise, a Linux user is created. Leave blank for
|
||||
automatic detection.
|
||||
:return: The new AutoNewUser object - use with a `with` scope.
|
||||
"""
|
||||
if is_windows:
|
||||
return AutoNewWindowsUser(username, password)
|
||||
else:
|
||||
return AutoNewLinuxUser(username, password)
|
|
@ -0,0 +1,2 @@
|
|||
class NewUserError(Exception):
|
||||
pass
|
|
@ -1,6 +1,7 @@
|
|||
import subprocess
|
||||
|
||||
from infection_monkey.utils.auto_new_user import AutoNewUser, NewUserError
|
||||
from infection_monkey.utils.auto_new_user import AutoNewUser
|
||||
from infection_monkey.utils.new_user_error import NewUserError
|
||||
|
||||
ACTIVE_NO_NET_USER = '/ACTIVE:NO'
|
||||
|
||||
|
|
Loading…
Reference in New Issue