mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-19 00:01:29 +00:00
fix(proxy): wire general_settings.user_url_validation/user_url_allowed_hosts to litellm globals
This commit is contained in:
parent
c3f7158b2b
commit
ee3e812186
2 changed files with 63 additions and 0 deletions
|
|
@ -4060,6 +4060,15 @@ class ProxyConfig:
|
|||
raise ValueError(
|
||||
"allowed_ips is an Enterprise Feature. Please add a valid LITELLM_LICENSE to your envionment."
|
||||
)
|
||||
## URL VALIDATION SETTINGS ##
|
||||
_user_url_validation = general_settings.get("user_url_validation", None)
|
||||
if _user_url_validation is not None:
|
||||
litellm.user_url_validation = bool(_user_url_validation)
|
||||
_user_url_allowed_hosts = general_settings.get(
|
||||
"user_url_allowed_hosts", None
|
||||
)
|
||||
if _user_url_allowed_hosts is not None:
|
||||
litellm.user_url_allowed_hosts = list(_user_url_allowed_hosts)
|
||||
## BUDGET RESCHEDULER ##
|
||||
proxy_budget_rescheduler_min_time = general_settings.get(
|
||||
"proxy_budget_rescheduler_min_time", proxy_budget_rescheduler_min_time
|
||||
|
|
|
|||
|
|
@ -316,3 +316,57 @@ async def test_json_logs_calls_turn_on_json():
|
|||
# Cleanup
|
||||
os.unlink(temp_file_path)
|
||||
litellm.json_logs = False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_general_settings_url_validation_wired_to_litellm():
|
||||
"""
|
||||
Regression test for https://github.com/BerriAI/litellm/issues/26599
|
||||
|
||||
user_url_validation and user_url_allowed_hosts set in general_settings must be
|
||||
propagated to litellm module globals so that url_utils.validate_url /
|
||||
safe_get / async_safe_get honour them at runtime.
|
||||
"""
|
||||
import tempfile
|
||||
|
||||
import yaml
|
||||
|
||||
config_content = {
|
||||
"model_list": [
|
||||
{
|
||||
"model_name": "test-model",
|
||||
"litellm_params": {"model": "openai/gpt-4", "api_key": "test-key"},
|
||||
}
|
||||
],
|
||||
"general_settings": {
|
||||
"user_url_validation": False,
|
||||
"user_url_allowed_hosts": ["10.80.1.20", "internal.corp"],
|
||||
},
|
||||
}
|
||||
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", suffix=".yaml", delete=False
|
||||
) as temp_file:
|
||||
yaml.dump(config_content, temp_file)
|
||||
temp_file_path = temp_file.name
|
||||
|
||||
original_validation = litellm.user_url_validation
|
||||
original_hosts = litellm.user_url_allowed_hosts
|
||||
|
||||
try:
|
||||
proxy_config = ProxyConfig()
|
||||
await proxy_config.load_config(
|
||||
router=None,
|
||||
config_file_path=temp_file_path,
|
||||
)
|
||||
|
||||
assert litellm.user_url_validation is False, (
|
||||
"user_url_validation from general_settings should set litellm.user_url_validation"
|
||||
)
|
||||
assert litellm.user_url_allowed_hosts == ["10.80.1.20", "internal.corp"], (
|
||||
"user_url_allowed_hosts from general_settings should set litellm.user_url_allowed_hosts"
|
||||
)
|
||||
finally:
|
||||
os.unlink(temp_file_path)
|
||||
litellm.user_url_validation = original_validation
|
||||
litellm.user_url_allowed_hosts = original_hosts
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue