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.49.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_gitlab_webhooks-0.3.49-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for pydantic_gitlab_webhooks-0.3.49.tar.gz
Algorithm Hash digest
SHA256 819560c77fcd75102613fcf837aa967f763bc6d0e6407a4f87bfcc780586283f
MD5 11e6955447f209fca7e5d6963ee3334f
BLAKE2b-256 4f3b767b1e21fcbfb019d459836b9d7a819317b461af3d154e9063203ff122e4

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pydantic_gitlab_webhooks-0.3.49-py3-none-any.whl
Algorithm Hash digest
SHA256 320fec4a05cbe1474b1a858bef465026cb908cc8ab42594af216674df21ca462
MD5 fb32af13a043582202e9bb844a47825d
BLAKE2b-256 b95c5ee0f0de9f381f7a68d64f0dc8443f5cb3a8d61c17abb3a5d58a14d66778

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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