|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | +from __future__ import annotations |
| 13 | + |
| 14 | +import typing |
| 15 | + |
| 16 | +from uuid import UUID |
| 17 | + |
| 18 | +from sqlalchemy import ForeignKey, orm |
| 19 | +from sqlalchemy.dialects.postgresql import CITEXT, JSONB |
| 20 | +from sqlalchemy.orm import Mapped, mapped_column |
| 21 | + |
| 22 | +from warehouse import db |
| 23 | + |
| 24 | +if typing.TYPE_CHECKING: |
| 25 | + from warehouse.packaging.models import File |
| 26 | + |
| 27 | + |
| 28 | +class Provenance(db.Model): |
| 29 | + """ |
| 30 | + A table for PEP 740 provenance objects. |
| 31 | +
|
| 32 | + Provenance objects contain one or more attestation objects. |
| 33 | + These attestation objects are grouped into "bundles," each of which |
| 34 | + contains one or more attestations along with the Trusted Publisher |
| 35 | + identity that produced them. |
| 36 | + """ |
| 37 | + |
| 38 | + __tablename__ = "provenance" |
| 39 | + |
| 40 | + file_id: Mapped[UUID] = mapped_column( |
| 41 | + ForeignKey("release_files.id", onupdate="CASCADE", ondelete="CASCADE"), |
| 42 | + ) |
| 43 | + file: Mapped[File] = orm.relationship(back_populates="provenance") |
| 44 | + |
| 45 | + # This JSONB has the structure of a PEP 740 provenance object. |
| 46 | + provenance: Mapped[dict] = mapped_column(JSONB, nullable=False, deferred=True) |
| 47 | + |
| 48 | + # The SHA-2/256 digest of the provenance object stored in this row. |
| 49 | + # Postgres uses a compact binary representation under the hood and is |
| 50 | + # unlikely to provide a permanently stable serialization, so this is the |
| 51 | + # hash of the RFC 8785 serialization. |
| 52 | + provenance_digest: Mapped[str] = mapped_column(CITEXT) |
0 commit comments