mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-14 19:12:08 +03:00
fix post validation for roles
This commit is contained in:
parent
69d3fd9269
commit
f520d4b8dd
@ -719,6 +719,18 @@ class FrigateConfig(FrigateBaseModel):
|
||||
"Frigate+ is configured but clean snapshots are not enabled, submissions to Frigate+ will not be possible./"
|
||||
)
|
||||
|
||||
# Validate auth roles against cameras
|
||||
camera_names = set(self.cameras.keys())
|
||||
|
||||
for role, allowed_cameras in self.auth.roles.items():
|
||||
invalid_cameras = [
|
||||
cam for cam in allowed_cameras if cam not in camera_names
|
||||
]
|
||||
if invalid_cameras:
|
||||
logger.warning(
|
||||
f"Role '{role}' references non-existent cameras: {invalid_cameras}. "
|
||||
)
|
||||
|
||||
return self
|
||||
|
||||
@field_validator("cameras")
|
||||
@ -730,27 +742,6 @@ class FrigateConfig(FrigateBaseModel):
|
||||
raise ValueError("Zones cannot share names with cameras")
|
||||
return v
|
||||
|
||||
@field_validator("auth")
|
||||
@classmethod
|
||||
def validate_auth_roles(cls, v: AuthConfig, info: ValidationInfo) -> AuthConfig:
|
||||
# Access cameras from the validated model
|
||||
frigate_config = info.data.get("cameras", {})
|
||||
camera_names = (
|
||||
set(frigate_config.keys()) if isinstance(frigate_config, dict) else set()
|
||||
)
|
||||
|
||||
for role, allowed_cameras in v.roles.items():
|
||||
invalid_cameras = [
|
||||
cam for cam in allowed_cameras if cam not in camera_names
|
||||
]
|
||||
if invalid_cameras:
|
||||
logger.warning(
|
||||
f"Role '{role}' references non-existent cameras: {invalid_cameras}. "
|
||||
f"These will grant no access until cameras are added."
|
||||
)
|
||||
|
||||
return v
|
||||
|
||||
@classmethod
|
||||
def load(cls, **kwargs):
|
||||
"""Loads the Frigate config file, runs migrations, and creates the config object."""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user