mirror of
https://github.com/andrewthetechie/py-healthchecks.io.git
synced 2026-04-30 18:55:58 +02:00
Bump to pydantic 2.8.0 (#702)
* deps: bump pydantic from 1.10.15 to 2.8.0 Bumps [pydantic](https://github.com/pydantic/pydantic) from 1.10.15 to 2.8.0. - [Release notes](https://github.com/pydantic/pydantic/releases) - [Changelog](https://github.com/pydantic/pydantic/blob/main/HISTORY.md) - [Commits](https://github.com/pydantic/pydantic/compare/v1.10.15...v2.8.0) --- updated-dependencies: - dependency-name: pydantic dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Update dependencies run the bump-pydantic tool. * Migrate the validate_uuid using field_validator. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -302,6 +302,7 @@ class Client(AbstractClient):
|
||||
|
||||
svg, json, shields: reports two states: "up" and "down". It considers any checks in the grace period
|
||||
as still "up".
|
||||
|
||||
svg3, json3, shields3: reports three states: "up", "late", and "down".
|
||||
|
||||
The response includes a special * entry: this pseudo-tag reports the overal status
|
||||
|
||||
@@ -14,45 +14,45 @@ from urllib.parse import urlparse
|
||||
|
||||
import pytz
|
||||
from croniter import croniter
|
||||
from pydantic import BaseModel
|
||||
from pydantic import field_validator, BaseModel, ValidationInfo
|
||||
from pydantic import Field
|
||||
from pydantic import validator
|
||||
|
||||
|
||||
class Check(BaseModel):
|
||||
"""Schema for a check object, either from a readonly api request or a rw api request."""
|
||||
|
||||
unique_key: Optional[str]
|
||||
unique_key: Optional[str] = None
|
||||
name: str
|
||||
slug: str
|
||||
tags: Optional[str]
|
||||
desc: Optional[str]
|
||||
tags: Optional[str] = None
|
||||
desc: Optional[str] = None
|
||||
grace: int
|
||||
n_pings: int
|
||||
status: str
|
||||
last_ping: Optional[datetime]
|
||||
next_ping: Optional[datetime]
|
||||
last_ping: Optional[datetime] = None
|
||||
next_ping: Optional[datetime] = None
|
||||
manual_resume: bool
|
||||
methods: Optional[str]
|
||||
methods: Optional[str] = None
|
||||
# healthchecks.io's api doesn't return a scheme so we cant use Pydantic AnyUrl here
|
||||
ping_url: Optional[str]
|
||||
update_url: Optional[str]
|
||||
pause_url: Optional[str]
|
||||
channels: Optional[str]
|
||||
timeout: Optional[int]
|
||||
uuid: Optional[str]
|
||||
ping_url: Optional[str] = None
|
||||
update_url: Optional[str] = None
|
||||
pause_url: Optional[str] = None
|
||||
channels: Optional[str] = None
|
||||
timeout: Optional[int] = None
|
||||
uuid: Optional[str] = Field(default=None, validate_default=True)
|
||||
|
||||
@validator("uuid", always=True)
|
||||
def validate_uuid(cls, value: Optional[str], values: Dict[str, Any]) -> Optional[str]: # noqa: B902
|
||||
@field_validator("uuid")
|
||||
@classmethod
|
||||
def validate_uuid(cls, value: Optional[str], info: ValidationInfo) -> Optional[str]: # noqa: B902
|
||||
"""Tries to set the uuid from the ping_url.
|
||||
|
||||
Will return none if a read only token is used because it cannot retrieve the UUID of a check
|
||||
"""
|
||||
if value is None and values.get("ping_url", None) is not None:
|
||||
if value is None and info.data.get("ping_url", None) is not None:
|
||||
# url is like healthchecks.io/ping/8f57b84b-86c2-4546-8923-03f83d27604a, so we want just the
|
||||
# UUID off the end
|
||||
# Parse the url, grab the path and then just get the name using pathlib
|
||||
path = PurePath(str(urlparse(values.get("ping_url")).path))
|
||||
path = PurePath(str(urlparse(info.data.get("ping_url")).path))
|
||||
return path.name
|
||||
return value
|
||||
|
||||
@@ -126,28 +126,32 @@ class CheckCreate(BaseModel):
|
||||
"for the unique field are name, tags, timeout, and grace.",
|
||||
)
|
||||
|
||||
@validator("schedule")
|
||||
@field_validator("schedule")
|
||||
@classmethod
|
||||
def validate_schedule(cls, value: str) -> str:
|
||||
"""Validates that the schedule is a valid cron expression."""
|
||||
if not croniter.is_valid(value):
|
||||
raise ValueError("Schedule is not a valid cron expression")
|
||||
return value
|
||||
|
||||
@validator("tz")
|
||||
@field_validator("tz")
|
||||
@classmethod
|
||||
def validate_tz(cls, value: str) -> str:
|
||||
"""Validates that the timezone is a valid timezone string."""
|
||||
if value not in pytz.all_timezones:
|
||||
raise ValueError("Tz is not a valid timezone")
|
||||
return value
|
||||
|
||||
@validator("methods")
|
||||
@field_validator("methods")
|
||||
@classmethod
|
||||
def validate_methods(cls, value: str) -> str:
|
||||
"""Validate that methods."""
|
||||
if value not in ("", "POST"):
|
||||
raise ValueError("Methods is invalid, it should be either an empty string or POST")
|
||||
return value
|
||||
|
||||
@validator("unique")
|
||||
@field_validator("unique")
|
||||
@classmethod
|
||||
def validate_unique(cls, value: List[Optional[str]]) -> List[Optional[str]]:
|
||||
"""Validate unique list."""
|
||||
for unique in value:
|
||||
|
||||
Reference in New Issue
Block a user