Skip to content

Class tigrbl_auth.orm.service_key.ServiceKey

tigrbl_auth.orm.service_key.ServiceKey

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

label class-attribute instance-attribute

label = acol(
    storage=S(String, nullable=False),
    field=F(
        constraints={"max_length": 120},
        required_in=("create",),
    ),
    io=IO(
        in_verbs=("create",),
        out_verbs=("read", "list"),
        filter_ops=("eq",),
    ),
)

service_id class-attribute instance-attribute

service_id = acol(
    storage=S(
        PgUUID(as_uuid=True),
        fk=ForeignKeySpec(target="authn.services.id"),
        index=True,
        nullable=False,
    ),
    field=F(py_type=UUID, required_in=("create",)),
    io=IO(
        in_verbs=("create",),
        out_verbs=("read", "list"),
        filter_ops=("eq",),
    ),
)

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()

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()