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 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydantic_gitlab_webhooks-0.2.1.tar.gz
.
File metadata
- Download URL: pydantic_gitlab_webhooks-0.2.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04eac727091da614d72436b84bdd1d6afc8b32ef8d9df641f5d216e0921ea33e |
|
MD5 | 5ba8f44066f814f91f8edd7c65a42658 |
|
BLAKE2b-256 | 2ac38f51d7ccc6014ee9ba99a22e0b272342f3d18dec9c19225ae429dc3a4cc1 |
Provenance
The following attestation bundles were made for pydantic_gitlab_webhooks-0.2.1.tar.gz
:
Publisher:
main.yml
on rjw57/pydantic-gitlab-webhooks
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pydantic_gitlab_webhooks-0.2.1.tar.gz
- Subject digest:
04eac727091da614d72436b84bdd1d6afc8b32ef8d9df641f5d216e0921ea33e
- Sigstore transparency entry: 149354674
- Sigstore integration time:
- Predicate type:
File details
Details for the file pydantic_gitlab_webhooks-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: pydantic_gitlab_webhooks-0.2.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 992fefeee6c83088de88995d54e414ebada3f0c9db9ed68f205f13ebd63b8936 |
|
MD5 | be4f550c6f8476bdc92977334fc7e5d2 |
|
BLAKE2b-256 | c853fa28bdaf11bda84a874aebcb35d70fef4e19ad22b1e4decbb6a732c17e64 |
Provenance
The following attestation bundles were made for pydantic_gitlab_webhooks-0.2.1-py3-none-any.whl
:
Publisher:
main.yml
on rjw57/pydantic-gitlab-webhooks
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pydantic_gitlab_webhooks-0.2.1-py3-none-any.whl
- Subject digest:
992fefeee6c83088de88995d54e414ebada3f0c9db9ed68f205f13ebd63b8936
- Sigstore transparency entry: 149354675
- Sigstore integration time:
- Predicate type: