|
17 | 17 | from typing import Literal |
18 | 18 |
|
19 | 19 | from pydantic import Field, NonNegativeInt, PostgresDsn, RedisDsn |
| 20 | +from pydantic.main import BaseModel |
20 | 21 | from pydantic_settings import BaseSettings |
21 | 22 |
|
22 | 23 | from oauth2_lib.settings import oauth2lib_settings |
23 | 24 | from orchestrator.services.settings_env_variables import expose_settings |
| 25 | +from orchestrator.utils.auth import Authorizer |
24 | 26 | from orchestrator.utils.expose_settings import SecretStr as OrchSecretStr |
25 | 27 | from pydantic_forms.types import strEnum |
26 | 28 |
|
@@ -111,3 +113,28 @@ class AppSettings(BaseSettings): |
111 | 113 | expose_settings("app_settings", app_settings) # type: ignore |
112 | 114 | if app_settings.EXPOSE_OAUTH_SETTINGS: |
113 | 115 | expose_settings("oauth2lib_settings", oauth2lib_settings) # type: ignore |
| 116 | + |
| 117 | + |
| 118 | +class Authorizers(BaseModel): |
| 119 | + # Callbacks specifically for orchestrator-core callbacks. |
| 120 | + # Separate from defaults for user-defined workflows and steps. |
| 121 | + internal_authorize_callback: Authorizer | None = None |
| 122 | + internal_retry_auth_callback: Authorizer | None = None |
| 123 | + |
| 124 | + |
| 125 | +_authorizers = Authorizers() |
| 126 | + |
| 127 | + |
| 128 | +def get_authorizers() -> Authorizers: |
| 129 | + """Acquire singleton of app authorizers to assign these callbacks at app setup. |
| 130 | +
|
| 131 | + Ensures downstream users can acquire singleton without being tempted to do |
| 132 | + from orchestrator.settings import authorizers |
| 133 | + authorizers = my_authorizers |
| 134 | + or |
| 135 | + from orchestrator import settings |
| 136 | + settings.authorizers = my_authorizers |
| 137 | +
|
| 138 | + ...each of which goes wrong in its own way. |
| 139 | + """ |
| 140 | + return _authorizers |
0 commit comments