/grouper/plugin/base.py

https://github.com/dropbox/merou · Python · 225 lines · 160 code · 9 blank · 56 comment · 1 complexity · 86557590385a5fac35f1c6d553b70827 MD5 · raw file

  1. from typing import TYPE_CHECKING
  2. if TYPE_CHECKING:
  3. from grouper.models.audit_log import AuditLog
  4. from grouper.models.group import Group
  5. from grouper.models.user import User
  6. from sshpubkeys import SSHKey
  7. from ssl import SSLContext
  8. from sqlalchemy.orm import Session
  9. from tornado.httpserver import HTTPRequest
  10. from types import TracebackType
  11. from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union
  12. class BasePlugin:
  13. def configure(self, service_name):
  14. # type: (str) -> None
  15. """Configure the plugin.
  16. Called once the plugin is instantiated to identify the executable (grouper-api, grouper-fe,
  17. or grouper-background).
  18. """
  19. pass
  20. def check_machine_set(self, name, machine_set):
  21. # type: (str, str) -> None
  22. """Check whether a service account machine set is valid.
  23. Args:
  24. name: Name of the service account being changed
  25. machine_set: New machine set for a service account
  26. Raises:
  27. PluginRejectedMachineSet to reject the change. The exception message will be shown to
  28. the user.
  29. """
  30. pass
  31. def check_service_account_name(self, name):
  32. # type: (str) -> None
  33. """Check whether a service account name is allowed.
  34. Args:
  35. name: Name of a new service account being created (with domain)
  36. Raises:
  37. PluginRejectedServiceAccountName to reject the name. The exception message will be
  38. shown to the user.
  39. """
  40. pass
  41. def check_permission_argument(self, permission: str, argument: str) -> None:
  42. """Check permission argument for validity
  43. Args:
  44. permission: A Grouper permission name
  45. argument: The argument for that permission
  46. Raises:
  47. PluginRejectedPermissionArgument to reject the argument. The exception message will be
  48. shown to the user.
  49. """
  50. pass
  51. def get_aliases_for_mapped_permission(self, session, permission, argument):
  52. # type: (Session, str, str) -> Optional[Iterable[Tuple[str, str]]]
  53. """Called when building the graph to get aliases of a mapped permission.
  54. Args:
  55. session: database session
  56. permission: the name of the permission
  57. argument: the argument that the permission was granted with
  58. Returns:
  59. A list of (permission, argument) tuples that the permission is an alias for.
  60. """
  61. pass
  62. def get_github_app_client_secret(self):
  63. # type: () -> bytes
  64. "Return the client secret for the GitHub app used to authorize users."
  65. def get_owner_by_arg_by_perm(self, session):
  66. # type: (Session) -> Optional[Dict[str, Dict[str, List[Group]]]]
  67. """Called when determining owners for permission+arg granting.
  68. Args:
  69. session: database session
  70. Returns:
  71. dict of the form {'permission_name': {'argument': [owner1, owner2,
  72. ...], ...}, ...} where 'ownerN' is a models.Group corresponding to
  73. the grouper group that owns (read: is able to) grant that
  74. permission + argument pair.
  75. """
  76. pass
  77. def get_ssl_context(self):
  78. # type: () -> Optional[SSLContext]
  79. """Called to get the ssl.SSLContext for the application."""
  80. pass
  81. def log_auditlog_entry(self, entry):
  82. # type: (AuditLog) -> None
  83. """Called when an audit log entry is saved to the database.
  84. Args:
  85. entry: just-saved log object
  86. """
  87. pass
  88. def log_background_run(self, success):
  89. # type: (bool) -> None
  90. """Log a background processor run
  91. Arg(s):
  92. success: whether the run succeeded
  93. """
  94. pass
  95. def log_exception(
  96. self,
  97. request, # type: Optional[HTTPRequest]
  98. status, # type: Optional[int]
  99. exc_type, # type: Optional[Type[BaseException]]
  100. exc_value, # type: Optional[BaseException]
  101. exc_tb, # type: Optional[TracebackType]
  102. ):
  103. # type: (...) -> None
  104. """Called when an exception is triggered.
  105. Args:
  106. request: The request being handled (None for non-Tornado exceptions)
  107. status: The response status (None for non-Tornado exceptions)
  108. exc_type: The type of the exception
  109. exc_value: The exception object
  110. exc_tb: The traceback, in the same form as sys.exc_info()[2]
  111. """
  112. pass
  113. def log_graph_update_duration(self, duration_ms):
  114. # type: (int) -> None
  115. """Log a graph update duration
  116. Arg(s):
  117. duration_ms: the graph update latency
  118. """
  119. pass
  120. def log_periodic_graph_update(self, success):
  121. # type: (bool) -> None
  122. """Log a periodic graph update run
  123. Arg(s):
  124. success: whether the run succeeded
  125. """
  126. pass
  127. def log_request(self, handler, status, duration_ms, request):
  128. # type: (str, int, int, Optional[HTTPRequest]) -> None
  129. """Log information about a handled request
  130. Arg(s):
  131. handler: name of the handler class that handled the request
  132. status: the response status of the request (e.g., 200, 404, etc.)
  133. duration_ms: the request processing latency
  134. request: the Tornado request that was handled
  135. """
  136. pass
  137. def user_created(self, user, is_service_account=False):
  138. # type: (User, bool) -> None
  139. """Called when a new user is created
  140. When new users enter into Grouper, you might have reason to set metadata on those
  141. users for some reason. This method is called when that happens.
  142. Args:
  143. user: Object of new user.
  144. is_service_account: Whether this user is a service account (role user)
  145. Returns:
  146. The return code of this method is ignored.
  147. """
  148. pass
  149. def will_add_public_key(self, key):
  150. # type: (SSHKey) -> None
  151. """Called before adding a public key.
  152. Args:
  153. key: Parsed public key
  154. Raises:
  155. PluginRejectedPublicKey: if the plugin rejects the key
  156. """
  157. pass
  158. def will_disable_user(self, session, user):
  159. # type: (Session, User) -> None
  160. """Called before disabling a user.
  161. Args:
  162. session: database session
  163. user: User to be disabled
  164. Raises:
  165. PluginRejectedDisablingUser: if the plugin rejects the change
  166. """
  167. pass
  168. def will_update_group_membership(self, session, group, member, **updates):
  169. # type: (Session, Group, Union[User, Group], **Any) -> None
  170. """Called before applying changes to a group membership.
  171. Args:
  172. session: database session
  173. group: affected group
  174. member: affected User or Group
  175. updates: the updates to the membership (active, expiration, role)
  176. Raises:
  177. PluginRejectedGroupMembershipUpdate: if the plugin rejects the update
  178. """
  179. pass