Skip to content

Class tigrbl_auth.orm.api_key.ApiKey

tigrbl_auth.orm.api_key.ApiKey

Bases: Base, GUIDPk, Created, LastUsed, ValidityWindow, UserColumn, KeyDigest

label class-attribute instance-attribute

label = acol(
    storage=S(String, nullable=False),
    field=F(constraints={"max_length": 120}),
)

digest class-attribute instance-attribute

digest = acol(
    storage=S(
        String, nullable=False, unique=True, index=True
    ),
    field=F(constraints={"max_length": 64}),
    io=paired(
        make=_generate_pair,
        alias="api_key",
        verbs=("create",),
        emit="post_refresh",
        alias_field=F(py_type=str),
        mask_last=None,
    ),
)

raw_key property writable

raw_key

valid_from class-attribute instance-attribute

valid_from = acol(
    spec=ColumnSpec(
        storage=S(
            type_=TZDateTime,
            default=tzutcnow,
            nullable=False,
        ),
        field=F(py_type=datetime),
        io=CRUD_IO,
    )
)

valid_to class-attribute instance-attribute

valid_to = acol(
    spec=ColumnSpec(
        storage=S(
            type_=TZDateTime, default=tzutcnow_plus_day
        ),
        field=F(py_type=datetime),
        io=CRUD_IO,
    )
)

last_used_at class-attribute instance-attribute

last_used_at = acol(
    spec=ColumnSpec(
        storage=S(
            type_=TZDateTime,
            nullable=True,
            onupdate=tzutcnow,
        ),
        field=F(py_type=datetime),
        io=IO(out_verbs=("read", "list", "create")),
    )
)

created_at class-attribute instance-attribute

created_at = acol(
    spec=ColumnSpec(
        storage=S(
            type_=TZDateTime,
            default=tzutcnow,
            nullable=False,
        ),
        field=F(py_type=datetime),
        io=RO_IO,
    )
)

id class-attribute instance-attribute

id = acol(
    spec=ColumnSpec(
        storage=S(
            type_=PgUUID(as_uuid=True),
            primary_key=True,
            default=uuid4,
        ),
        field=F(
            py_type=UUID,
            constraints={"examples": [uuid_example]},
        ),
        io=RO_IO,
    )
)

metadata class-attribute instance-attribute

metadata = MetaData(
    naming_convention={
        "pk": "pk_%(table_name)s",
        "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
        "ix": "ix_%(table_name)s_%(column_0_name)s",
        "uq": "uq_%(table_name)s_%(column_0_name)s",
        "ck": "ck_%(table_name)s_%(column_0_name)s_%(constraint_type)s",
    }
)

digest_of staticmethod

digest_of(value)
Source code in tigrbl/orm/mixins/key_digest.py
34
35
36
@staticmethod
def digest_of(value: str) -> str:
    return sha256(value.encode()).hexdigest()

user_id

user_id()
Source code in tigrbl/orm/mixins/principals.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@declared_attr
def user_id(cls) -> Mapped[UUID]:
    schema = getattr(cls, "__user_table_schema__", None) or _infer_schema(cls)
    spec = ColumnSpec(
        storage=S(
            type_=PgUUID(as_uuid=True),
            fk=ForeignKeySpec(target=f"{schema}.users.id"),
            nullable=False,
            index=True,
        ),
        field=F(py_type=UUID, constraints={"examples": [uuid_example]}),
        io=CRUD_IO,
    )
    return acol(spec=spec)

touch

touch()

Mark the object as used now.

Source code in tigrbl/orm/mixins/lifecycle.py
40
41
42
def touch(self) -> None:
    """Mark the object as used now."""
    self.last_used_at = tzutcnow()