Skip to main content

Pydantic models for GitLab webhook payloads

Project description

Pydantic models for GitLab Webhooks

PyPI - Version PyPI - Python Version GitHub Release Test suite status

Module containing Pydantic models for validating bodies from GitLab webhook requests.

Documentation

The project documentation including an API reference can be found at https://rjw57.github.io/pydantic-gitlab-webhooks/.

Usage example

Intended usage is via a single validate_event_header_and_body function which will validate an incoming webhook's X-Gitlab-Event header and the body after being parsed into a Python dict.

from pydantic import ValidationError
from pydantic_gitlab_webhooks import (
    validate_event_body_dict,
    validate_event_header_and_body_dict,
)

event_body = {
    "object_kind": "access_token",
    "group": {
        "group_name": "Twitter",
        "group_path": "twitter",
        "group_id": 35,
        "full_path": "twitter"
    },
    "object_attributes": {
        "user_id": 90,
        "created_at": "2024-01-24 16:27:40 UTC",
        "id": 25,
        "name": "acd",
        "expires_at": "2024-01-26"
    },
    "event_name": "expiring_access_token"
}

# Use the value of the "X-Gitlab-Event" header and event body to validate
# the incoming event.
parsed_event = validate_event_header_and_body_dict(
    "Resource Access Token Hook",
    event_body
)
assert parsed_event.group.full_path == "twitter"

# Invalid event bodies or hook headers raise Pydantic validation errors
try:
    validate_event_header_and_body_dict("invalid hook", event_body)
except ValidationError:
    pass  # ok - expected error raised
else:
    assert False, "ValidationError was not raised"

# Event bodies can be parsed without the header hook if necessary although using
# the hook header is more efficient.
parsed_event = validate_event_body_dict(event_body)
assert parsed_event.group.full_path == "twitter"

# Event models may be imported individually. For example:
from pydantic_gitlab_webhooks.events import GroupAccessTokenEvent

parsed_event = GroupAccessTokenEvent.model_validate(event_body)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_gitlab_webhooks-0.3.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

pydantic_gitlab_webhooks-0.3.2-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_gitlab_webhooks-0.3.2.tar.gz.

File metadata

File hashes

Hashes for pydantic_gitlab_webhooks-0.3.2.tar.gz
Algorithm Hash digest
SHA256 599fdd17e207e916ba394962ddc2b7b278abb24cae828b50321d75e858d75a57
MD5 5d81c16612c0ab56c5321d15c00d2cd9
BLAKE2b-256 1783803c46b37ed77d061ebebe44957e3b4550df1b63132ae7245050f8b4c716

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_gitlab_webhooks-0.3.2.tar.gz:

Publisher: main.yml on rjw57/pydantic-gitlab-webhooks

Attestations:

File details

Details for the file pydantic_gitlab_webhooks-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_gitlab_webhooks-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dd66aad1e08938b4eb59de3d7b63f2df4fa1b031ac3cb9322f95cca78701c80c
MD5 521bc80c290bd1603f896cf8043048ad
BLAKE2b-256 b8387ed8673f1276c01d9d054e6b6d4d0d3417840375c5594df67f5a082daaf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_gitlab_webhooks-0.3.2-py3-none-any.whl:

Publisher: main.yml on rjw57/pydantic-gitlab-webhooks

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page