Repository navigation
Deduplicate WIF auth - #7247
Deduplicate WIF auth#7247nishusheth wants to merge 2 commits into
Conversation
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class WifConfig: |
There was a problem hiding this comment.
Instead of storing the env var names in the config class, the config class should hold the values themselves. Resolving env vars isn't the job of configure(), and moving that responsibility out gives us more flexibility to customize validation as needed.
I would make WifConfig an interface (i.e., inherit from Protocol). Then, for each provider, I would create a pydantic_settings model that maps env vars to its fields via a prefix configuration. Where a field name doesn't match the env var name after the prefix, we can use an alias on that field.
4f98320 to
80e1866
Compare
|
|
||
| name: ClassVar[str] = "OpenAI" | ||
| provider_id: ClassVar[str] = "openai" | ||
| token_file_env: ClassVar[str] = "OPENAI_IDENTITY_TOKEN_FILE" |
There was a problem hiding this comment.
This isn't quite what I had in mind. We don't need os.environ here at all, since pydantic_settings should handle that for us.
When the environment variable name doesn't match the field name in the provider-specific model, we can use Field() with an alias to customize it. For example:
| token_file_env: ClassVar[str] = "OPENAI_IDENTITY_TOKEN_FILE" | |
| token_file: Annotated[str, Field(validation_alias="OPENAI_IDENTITY_TOKEN_FILE")] |
To support both embedding in existing settings and standalone settings, we can use the from_env() pattern:
bugbug/libs/phabricator-client/phabricator_client/config.py
Lines 21 to 23 in 1bfdce8
There was a problem hiding this comment.
identity_token_file reads OPENAI_IDENTITY_TOKEN_FILE through the OPENAI_ prefix. I kept token_file_env because configure() needs the variable name to export the temp path when it isn't set (the os.environ write we discussed, now logged at info level). It's no longer used to read config.
b04f1aa to
a6e16f0
Compare
Fixes #6317