Models.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (c) 2020 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional, Dict, Any, List
  4. class BaseModel:
  5. def __init__(self, **kwargs: Any) -> None:
  6. self.__dict__.update(kwargs)
  7. class OAuth2Settings(BaseModel):
  8. """OAuth OAuth2Settings data template."""
  9. CALLBACK_PORT = None # type: Optional[int]
  10. OAUTH_SERVER_URL = None # type: Optional[str]
  11. CLIENT_ID = None # type: Optional[str]
  12. CLIENT_SCOPES = None # type: Optional[str]
  13. CALLBACK_URL = None # type: Optional[str]
  14. AUTH_DATA_PREFERENCE_KEY = "" # type: str
  15. AUTH_SUCCESS_REDIRECT = "https://ultimaker.com" # type: str
  16. AUTH_FAILED_REDIRECT = "https://ultimaker.com" # type: str
  17. class UserProfile(BaseModel):
  18. """User profile data template."""
  19. user_id = None # type: Optional[str]
  20. username = None # type: Optional[str]
  21. profile_image_url = None # type: Optional[str]
  22. organization_id = None # type: Optional[str]
  23. subscriptions = None # type: Optional[List[Dict[str, Any]]]
  24. class AuthenticationResponse(BaseModel):
  25. """Authentication data template."""
  26. # Data comes from the token response with success flag and error message added.
  27. success = True # type: bool
  28. token_type = None # type: Optional[str]
  29. access_token = None # type: Optional[str]
  30. refresh_token = None # type: Optional[str]
  31. expires_in = None # type: Optional[str]
  32. scope = None # type: Optional[str]
  33. err_message = None # type: Optional[str]
  34. received_at = None # type: Optional[str]
  35. class ResponseStatus(BaseModel):
  36. """Response status template."""
  37. code = 200 # type: int
  38. message = "" # type: str
  39. class ResponseData(BaseModel):
  40. """Response data template."""
  41. status = None # type: ResponseStatus
  42. data_stream = None # type: Optional[bytes]
  43. redirect_uri = None # type: Optional[str]
  44. content_type = "text/html" # type: str
  45. HTTP_STATUS = {
  46. """Possible HTTP responses."""
  47. "OK": ResponseStatus(code = 200, message = "OK"),
  48. "NOT_FOUND": ResponseStatus(code = 404, message = "NOT FOUND"),
  49. "REDIRECT": ResponseStatus(code = 302, message = "REDIRECT")
  50. } # type: Dict[str, ResponseStatus]