RestAPI.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. class RestAPI(object):
  2. """
  3. This Class is representing the rest API with all its configuration.
  4. """
  5. def __init__(self,
  6. password_protected=None,
  7. login=None, password=None,
  8. active=None,
  9. port=None,
  10. allowed_cors_origin=None):
  11. """
  12. :param password_protected: If true, the rest api will ask for an authentication
  13. :param login: login used if auth is activated
  14. :param password: password used if auth is activated
  15. :param active: specify if the rest api is loaded on start with Kalliope
  16. :param allowed_cors_origin: specify allowed origins
  17. """
  18. self.password_protected = password_protected
  19. self.login = login
  20. self.password = password
  21. self.active = active
  22. self.port = port
  23. self.allowed_cors_origin = allowed_cors_origin
  24. def __str__(self):
  25. return str(self.serialize())
  26. def serialize(self):
  27. """
  28. This method allows to serialize in a proper way this object
  29. :return: A dict of order
  30. :rtype: Dict
  31. """
  32. return {
  33. 'password_protected': self.password_protected,
  34. 'login': self.login,
  35. 'password': self.password,
  36. 'active': self.active,
  37. 'port': self.port,
  38. 'allowed_cors_origin': self.allowed_cors_origin
  39. }
  40. def __eq__(self, other):
  41. """
  42. This is used to compare 2 objects
  43. :param other:
  44. :return:
  45. """
  46. return self.__dict__ == other.__dict__