# Path: lib/DomainObjects/EyeosCard.py
# class EyeosCard:
#     def __init__(self, card, signature):
#         self._card = card
#         self._signature = signature
# 
#     def to_headers(self):
#         return {
#             'card': json.dumps(self._card),
#             'signature': self._signature
#         }
# 
#     def __eq__(self, other):
#         return self._card == other._card and self._signature == other._signature
# 
# Path: lib/Errors/EyeosAPIError.py
# class EyeosAPIError(Exception):
#     pass
# 
# Path: lib/EyeosApi/EyeosApiCall.py
# class EyeosApiCall:
#     """Class that wraps the requests library but adds some utility related to eyeos. For now it accepts EyeosCard
#     objects and adds them to the headers.
#     """
#     def __init__(self):
#         requests.packages.urllib3.disable_warnings()
# 
#     def __dir__(self):
#         """Override dir(), returning requests' dir()"""
#         return dir(requests)
# 
#     def __getattr__(self, item):
#         """forward all attribute or method accesses to requests"""
#         wrapped = None
#         try:
#             wrapped = getattr(requests, item)
#         except AttributeError as e:
#             raise AttributeError("'{0}' has no attribute '{1}'".format(self.__class__.__name__, item)) from e
# 
#         if not callable(wrapped):
#             # If the attribute exists but is not callable, we can't wrap it in a function, return it directly
#             return wrapped
# 
#         # Wrap the method with a function that converts the card (if present) to headers
#         @functools.wraps(wrapped)
#         def wrapper(*args, card=None, **kwargs):
#             if card:
#                 kwargs = copy.deepcopy(kwargs)
#                 if 'headers' not in kwargs:
#                     kwargs['headers'] = {}
#                 kwargs['headers'].update(card.to_headers())
# 
#             return wrapped(*args, **kwargs)
# 
#         return wrapper
# 
# Path: lib/Settings.py
# class Settings:
#     def __init__(self,
#                  override_settings_path='settings.cfg'):
#         self.settingsFilePath = override_settings_path
#         self.parser = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
#         self.settings = None
#         self.getSettings()
# 
#     def getSettings(self):
#         self.parser.read('./settings.cfg')
#         self.settings = {section: dict(**self.parser[section]) for section in self.parser.sections()}
# 
#         return self.settings
# 
#     def getServiceIp(self, service):
#         return self.settings['general']['my_ip']
# 
# Path: lib/Wrappers/Logger.py
# class Logger:
#     def __init__(self, name):
#         if 'UNITTESTING' in os.environ:
#             self.logging = NullLogger()
#         else:
#             settings = Settings().getSettings()
#             logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
#                                 level=settings["logs"]["level"])
#             self.logging = logging.getLogger(name)
# 
#     def debug(self, *args, **kwargs):
#         self.logging.debug(*args, **kwargs)
# 
#     def info(self, *args, **kwargs):
#         self.logging.info(*args, **kwargs)
# 
#     def warning(self, *args, **kwargs):
#         self.logging.warning(*args, **kwargs)
# 
#     def error(self, *args, **kwargs):
#         self.logging.error(*args, **kwargs)
# 
#     def critical(self, *args, **kwargs):
#         self.logging.critical(*args, **kwargs)
# 
#     def log(self, *args, **kwargs):
#         self.logging.log(*args, **kwargs)


import getpass
from lib.DomainObjects.EyeosCard import EyeosCard
from lib.Errors.EyeosAPIError import EyeosAPIError
from lib.EyeosApi.EyeosApiCall import EyeosApiCall
from lib.Settings import Settings
from lib.Wrappers.Logger import Logger
        self.logger = Logger(__name__)
        self.eyeos_api_call = injected_eyeos_api_call or EyeosApiCall()

    def authenticate(self, username, password, domain=False):
        if not domain:
            domain = self.settings['general']['default_domain']
        self.logger.info("Retrieving a valid card...")
        data = {
            'type': 'Basic',
            'username': username,
            'password': password,
            'domain': domain
        }

        auth_url = "https://{0}/login/v1/methods/login/".format(self.proxy_ip)
        self.logger.debug('POST request to: {0}'.format(auth_url))
        req = self.eyeos_api_call.post(auth_url, verify=False, json=data)

        if req.status_code != 200:
            raise ValueError("Error authenticating with user {0} (Check if captcha is preventing access)"
                             .format(data['username']))

        try:
            login_card = req.json()
        except ValueError as e:
            raise EyeosAPIError("Error parsing JSON response: {0}".format(req.content)) from e

        try:
            return EyeosCard(login_card['card'], login_card['signature'])
        except KeyError as e:

# Path: lib/DomainObjects/EyeosCard.py
# class EyeosCard:
#     def __init__(self, card, signature):
#         self._card = card
#         self._signature = signature
# 
#     def to_headers(self):
#         return {
#             'card': json.dumps(self._card),
#             'signature': self._signature
#         }
# 
#     def __eq__(self, other):
#         return self._card == other._card and self._signature == other._signature
# 
# Path: lib/Errors/EyeosAPIError.py
# class EyeosAPIError(Exception):
#     pass
# 
# Path: lib/EyeosApi/EyeosApiCall.py
# class EyeosApiCall:
#     """Class that wraps the requests library but adds some utility related to eyeos. For now it accepts EyeosCard
#     objects and adds them to the headers.
#     """
#     def __init__(self):
#         requests.packages.urllib3.disable_warnings()
# 
#     def __dir__(self):
#         """Override dir(), returning requests' dir()"""
#         return dir(requests)
# 
#     def __getattr__(self, item):
#         """forward all attribute or method accesses to requests"""
#         wrapped = None
#         try:
#             wrapped = getattr(requests, item)
#         except AttributeError as e:
#             raise AttributeError("'{0}' has no attribute '{1}'".format(self.__class__.__name__, item)) from e
# 
#         if not callable(wrapped):
#             # If the attribute exists but is not callable, we can't wrap it in a function, return it directly
#             return wrapped
# 
#         # Wrap the method with a function that converts the card (if present) to headers
#         @functools.wraps(wrapped)
#         def wrapper(*args, card=None, **kwargs):
#             if card:
#                 kwargs = copy.deepcopy(kwargs)
#                 if 'headers' not in kwargs:
#                     kwargs['headers'] = {}
#                 kwargs['headers'].update(card.to_headers())
# 
#             return wrapped(*args, **kwargs)
# 
#         return wrapper
# 
# Path: lib/Settings.py
# class Settings:
#     def __init__(self,
#                  override_settings_path='settings.cfg'):
#         self.settingsFilePath = override_settings_path
#         self.parser = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
#         self.settings = None
#         self.getSettings()
# 
#     def getSettings(self):
#         self.parser.read('./settings.cfg')
#         self.settings = {section: dict(**self.parser[section]) for section in self.parser.sections()}
# 
#         return self.settings
# 
#     def getServiceIp(self, service):
#         return self.settings['general']['my_ip']
# 
# Path: lib/Wrappers/Logger.py
# class Logger:
#     def __init__(self, name):
#         if 'UNITTESTING' in os.environ:
#             self.logging = NullLogger()
#         else:
#             settings = Settings().getSettings()
#             logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
#                                 level=settings["logs"]["level"])
#             self.logging = logging.getLogger(name)
# 
#     def debug(self, *args, **kwargs):
#         self.logging.debug(*args, **kwargs)
# 
#     def info(self, *args, **kwargs):
#         self.logging.info(*args, **kwargs)
# 
#     def warning(self, *args, **kwargs):
#         self.logging.warning(*args, **kwargs)
# 
#     def error(self, *args, **kwargs):
#         self.logging.error(*args, **kwargs)
# 
#     def critical(self, *args, **kwargs):
#         self.logging.critical(*args, **kwargs)
# 
#     def log(self, *args, **kwargs):
#         self.logging.log(*args, **kwargs)


# Path: lib/EyeosApi/Login.py
import getpass
from lib.DomainObjects.EyeosCard import EyeosCard
from lib.Errors.EyeosAPIError import EyeosAPIError
from lib.EyeosApi.EyeosApiCall import EyeosApiCall
from lib.Settings import Settings
from lib.Wrappers.Logger import Logger

        self.logger = Logger(__name__)
        self.eyeos_api_call = injected_eyeos_api_call or EyeosApiCall()

    def authenticate(self, username, password, domain=False):
        if not domain:
            domain = self.settings['general']['default_domain']
        self.logger.info("Retrieving a valid card...")
        data = {
            'type': 'Basic',
            'username': username,
            'password': password,
            'domain': domain
        }

        auth_url = "https://{0}/login/v1/methods/login/".format(self.proxy_ip)
        self.logger.debug('POST request to: {0}'.format(auth_url))
        req = self.eyeos_api_call.post(auth_url, verify=False, json=data)

        if req.status_code != 200:
            raise ValueError("Error authenticating with user {0} (Check if captcha is preventing access)"
                             .format(data['username']))

        try:
            login_card = req.json()
        except ValueError as e:
            raise EyeosAPIError("Error parsing JSON response: {0}".format(req.content)) from e

        try:
            return EyeosCard(login_card['card'], login_card['signature'])
        except KeyError as e:

            raise EyeosAPIError("Can't retrieve card form login API") from e