Skip to content

Commit 29ccea8

Browse files
committed
check for duplicate users
1 parent 1621e9e commit 29ccea8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

nodeman/settings.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Annotated, Self
33

44
from argon2 import PasswordHasher
5-
from pydantic import AnyHttpUrl, BaseModel, Field, FilePath, StringConstraints, UrlConstraints
5+
from pydantic import AnyHttpUrl, BaseModel, Field, FilePath, StringConstraints, UrlConstraints, model_validator
66
from pydantic_core import Url
77
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource, SettingsConfigDict, TomlConfigSettingsSource
88

@@ -71,6 +71,15 @@ class Settings(BaseSettings):
7171

7272
model_config = SettingsConfigDict(toml_file="nodeman.toml")
7373

74+
@model_validator(mode="after")
75+
def validate_unique_usernames(self) -> Self:
76+
username_set = set()
77+
for user in self.users:
78+
if user.username in username_set:
79+
raise ValueError(f"Duplicate username found: {user.username}")
80+
username_set.add(user.username)
81+
return self
82+
7483
@classmethod
7584
def settings_customise_sources(
7685
cls,

0 commit comments

Comments
 (0)