I’m creating a custom PydanticBaseSettingsSource for my config.
What I’m struggling with is how to read the current config values inside of my custom PydanticBaseSettingsSource class.
This is how I want to use my custom settings class:
class MyApp(MyConfig):
test01: ExternalSecret # A BaseModel representing my special config fields
# Instantiate my config class
config = MyApp(
# I want my custom source to read the input assigned all my ExternalSecret fields and return the secret value
test01 = ExternalSecret(id="sdfsdfds", account="sdfsdfsd")
)
So I need my custom PydanticBaseSettingsSource to read in the value assigned the test01
param which is used to fetch the actual value.
This is my config class:
class MyConfig(BaseSettings):
@classmethod
def settings_customise_sources(
cls,
settings_cls: Type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> Tuple[PydanticBaseSettingsSource, ...]:
return (
init_settings,
env_settings,
dotenv_settings,
# Can GetMySecrets get access to the values returned by the previous PydanticBaseSettingsSources here?
GetMySecrets(settings_cls),
file_secret_settings,
)
Is it possible to order GetMySecrets
to come after the other sources and retrieve = the current value of my config fields as processed by those previously run sources?
Am I going about this the wrong way? Is there a way to run a sort of post processor in my MyConfig class that would, after loading config from all sources, loop over all my fields and for each GetMySecrets
field pull in their values which it would then use to fetch and replace with values fetched from my custom source?