Skip to main content

Pydantic models for GitLab webhook payloads

Project description

Pydantic models for GitLab Webhooks

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

Usage

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_header_and_body, validate_event_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(
    "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("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_dict(event_body)
assert parsed_event.group.full_path == "twitter"

# Individual event models are available from the `pydantic_gitlab_webhooks.events` module. For
# example:
from pydantic_gitlab_webhooks.events import GroupAccessTokenEvent

parsed_event = GroupAccessTokenEvent.model_validate(event_body)

The available event models are:

  • CommitNoteEvent
  • DeploymentEvent
  • EmojiEvent
  • FeatureFlagEvent
  • GroupAccessTokenEvent
  • GroupMemberEvent
  • IssueEvent
  • IssueNoteEvent
  • JobEvent
  • MergeRequestEvent
  • MergeRequestNoteEvent
  • PipelineEvent
  • ProjectAccessTokenEvent
  • ProjectEvent
  • PushEvent
  • ReleaseEvent
  • SnippetNoteEvent
  • SubgroupEvent
  • TagPushEvent
  • WikiPageEvent

Making a release

Manually trigger the release workflow.

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

Uploaded Source

Built Distribution

pydantic_gitlab_webhooks-0.1.5-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for pydantic_gitlab_webhooks-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b9b886e829a62d8d2c11e52ce01535dad412ed1da420baffca018eb8c2659018
MD5 fb1e2954cf29fadbe48b01ced3962523
BLAKE2b-256 5568263229e1d767f75124a13adc1aacdfe5bc444af4d83dffe853f11430eafc

See more details on using hashes here.

Provenance

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

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

Attestations:

File details

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

File metadata

File hashes

Hashes for pydantic_gitlab_webhooks-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 796cdc45d435fd3716fa3801684143f37820865242044dddbd8d1d001a5698d7
MD5 1fe346c45100e9d9553711cb9cc9a207
BLAKE2b-256 100db2c81cc3e4441a9c576c667e1bc09de369a1a0aa3df75a51c342682e27fa

See more details on using hashes here.

Provenance

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

Publisher: release.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