-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fedora-infra:main' into dev_user_endpoint
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SPDX-FileCopyrightText: Contributors to the Fedora Project | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from sqlalchemy import Column, Integer, UnicodeText, Boolean, ForeignKey, DateTime | ||
from webhook_to_fedora_messaging.models.util import UUIDCreatableMixin, CreatableMixin | ||
|
||
from webhook_to_fedora_messaging.database import Base | ||
|
||
from uuid import uuid4 | ||
|
||
|
||
class APIKey(Base, UUIDCreatableMixin, CreatableMixin): | ||
__tablename__ = "apikeys" | ||
|
||
id = Column(Integer, primary_key=True, nullable=False) | ||
user_id = Column(Integer, ForeignKey("user.id", ondelete="CASCADE"), unique=False, nullable=False) | ||
name = Column(UnicodeText, nullable=False) | ||
token = Column(UnicodeText, unique=True, nullable=False, default=uuid4().hex) | ||
expiry_date = Column(DateTime, nullable=True) | ||
disabled = Column(Boolean, nullable=False, default=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# SPDX-FileCopyrightText: Contributors to the Fedora Project | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from sqlalchemy import Column, Integer, UnicodeText, Boolean, ForeignKey | ||
from webhook_to_fedora_messaging.models.util import UUIDCreatableMixin, CreatableMixin | ||
|
||
from webhook_to_fedora_messaging.database import Base | ||
|
||
|
||
class Service(Base, UUIDCreatableMixin, CreatableMixin): | ||
__tablename__ = "services" | ||
|
||
id = Column(Integer, primary_key=True, nullable=False) | ||
user_id = Column(Integer, ForeignKey("user.id", ondelete="CASCADE"), unique=False, nullable=False) | ||
name = Column(UnicodeText, nullable=False) | ||
type = Column(UnicodeText, nullable=False) | ||
desc = Column(UnicodeText, nullable=False) | ||
disabled = Column(Boolean, nullable=False, default=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# SPDX-FileCopyrightText: Contributors to the Fedora Project | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from sqlalchemy import Column, Integer, UnicodeText, Boolean | ||
from webhook_to_fedora_messaging.models.util import UUIDCreatableMixin, CreatableMixin | ||
|
||
from webhook_to_fedora_messaging.database import Base | ||
|
||
|
||
class User(Base, UUIDCreatableMixin, CreatableMixin): | ||
__tablename__ = "users" | ||
|
||
id = Column(Integer, primary_key=True, nullable=False) | ||
username = Column(UnicodeText, unique=True, nullable=False) | ||
is_admin = Column(Boolean, nullable=False, default=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# SPDX-FileCopyrightText: Contributors to the Fedora Project | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
|
||
from sqlalchemy import Column, UnicodeText | ||
from sqlalchemy.ext.compiler import compiles | ||
from sqlalchemy.sql.expression import FunctionElement | ||
from sqlalchemy.types import DateTime as SQLDateTime | ||
|
||
from uuid import uuid4 | ||
|
||
|
||
class utcnow(FunctionElement): | ||
""" | ||
Current timestamp in UTC for SQL expressions | ||
""" | ||
type = SQLDateTime | ||
inherit_cache = True | ||
|
||
|
||
@compiles(utcnow, "postgresql") | ||
def _postgresql_utcnow(element, compiler, **kwargs): | ||
return "(NOW() AT TIME ZONE 'utc')" | ||
|
||
|
||
class UUIDCreatableMixin: | ||
""" | ||
An SQLAlchemy mixin to automatically generate a custom 8-digit UUID string | ||
""" | ||
|
||
uuid = Column("uuid", UnicodeText, unique=True, nullable=False, default=uuid4().hex[0:8]) | ||
|
||
|
||
class CreatableMixin: | ||
""" | ||
An SQLAlchemy mixin to store the time when an entity was created | ||
""" | ||
|
||
creation_date = Column("creation_date", SQLDateTime, nullable=False, server_default=utcnow()) |