Skip to content

Commit

Permalink
fix(biz/validators): 修复发布环境校验的后端配置问题 (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
F-cq authored Oct 30, 2024
1 parent 6da81af commit 56b990f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/dashboard/apigateway/apigateway/biz/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,15 @@ def __init__(self, gateway: Gateway, stage: Stage, resource_version: Optional[Re

def _validate_stage_backends(self):
"""校验待发布环境的backend配置"""
backend_configs = BackendConfig.objects.filter(stage=self.stage)
resource_version = self.resource_version

if resource_version and resource_version.data:
backend_ids = list({resource["proxy"]["backend_id"] for resource in resource_version.data
if resource["proxy"].get("backend_id", None)})
backend_configs = BackendConfig.objects.filter(backend_id__in=backend_ids)
else:
backend_configs = BackendConfig.objects.filter(stage=self.stage)

for backend_config in backend_configs:
for host in backend_config.config["hosts"]:
if not core_constants.HOST_WITHOUT_SCHEME_PATTERN.match(host["host"]):
Expand Down
49 changes: 49 additions & 0 deletions src/dashboard/apigateway/apigateway/tests/biz/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,55 @@ def test_validate_stage_plugins(
with pytest.raises(ReleaseValidationError):
publish_validator._validate_stage_plugins()

def test_validate_stage_backends(
self,
fake_stage,
fake_gateway
):

backend = G(
Backend,
gateway=fake_gateway,
type="http",
name="test_name",
description="test",
)

backend_config = G(
BackendConfig,
gateway=fake_gateway,
backend_id=backend.id,
stage_id=227,
config={"timeout": 30, "loadbalance": "roundrobin",
"hosts": [{"scheme": "http", "host": "ee.com", "weight": 100}]},
)

resource_version = G(
ResourceVersion,
gateway=fake_gateway,
version="1",
name="11",
title="11",
_data=json.dumps([{
"id": 1,
"name": "approval_add_workitems",
"proxy": {
"id": 28,
"type": "http",
"backend_id": backend.id,
"config": json.dumps({
"method": "ANY",
"path": "/api/v2/",
"match_subpath": False,
"timeout": 0
})
}
}]),
)

publish_validator = PublishValidator(fake_gateway, fake_stage, resource_version)
publish_validator._validate_stage_backends()


class TestSchemeInputValidator:
@pytest.mark.parametrize(
Expand Down

0 comments on commit 56b990f

Please sign in to comment.