applyConfigEnvironmentVariables function

void applyConfigEnvironmentVariables({
  1. required Map<String, String>? getGlobalConfigEnv(),
  2. required Map<String, String>? getAllSettingsEnv(),
  3. void clearCACertsCache()?,
  4. void clearMTLSCache()?,
  5. void clearProxyCache()?,
  6. void configureGlobalAgents()?,
})

Apply ALL environment variables after trust is established.

Implementation

void applyConfigEnvironmentVariables({
  required Map<String, String>? Function() getGlobalConfigEnv,
  required Map<String, String>? Function() getAllSettingsEnv,
  void Function()? clearCACertsCache,
  void Function()? clearMTLSCache,
  void Function()? clearProxyCache,
  void Function()? configureGlobalAgents,
}) {
  final globalEnv = filterSettingsEnv(getGlobalConfigEnv());
  globalEnv.forEach((key, value) {
    Platform.environment[key] = value;
  });

  final settingsEnv = filterSettingsEnv(getAllSettingsEnv());
  settingsEnv.forEach((key, value) {
    Platform.environment[key] = value;
  });

  // Clear caches so agents are rebuilt with the new env vars
  clearCACertsCache?.call();
  clearMTLSCache?.call();
  clearProxyCache?.call();

  // Reconfigure proxy/mTLS agents to pick up any proxy env vars from settings
  configureGlobalAgents?.call();
}