285 lines
12 KiB
Python
285 lines
12 KiB
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy import (
|
|
ForeignKey,
|
|
Index,
|
|
Integer,
|
|
String,
|
|
Text,
|
|
UniqueConstraint,
|
|
text,
|
|
)
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
class HostRow(Base):
|
|
__tablename__ = "host_registrations"
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"agent_instance_id",
|
|
name="uq_host_registrations_agent_instance_id",
|
|
),
|
|
UniqueConstraint(
|
|
"credential_digest",
|
|
name="uq_host_registrations_credential_digest",
|
|
),
|
|
UniqueConstraint(
|
|
"enrollment_token_digest",
|
|
name="uq_host_registrations_enrollment_token_digest",
|
|
),
|
|
)
|
|
|
|
host_id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
address: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
last_seen_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
agent_instance_id: Mapped[str | None] = mapped_column(
|
|
String,
|
|
nullable=True,
|
|
)
|
|
credential_digest: Mapped[str | None] = mapped_column(
|
|
String,
|
|
nullable=True,
|
|
)
|
|
enrollment_token_digest: Mapped[str | None] = mapped_column(
|
|
String,
|
|
nullable=True,
|
|
)
|
|
display_name: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
enrolled_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
revoked_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
|
|
|
|
class DeviceEnrollmentRow(Base):
|
|
__tablename__ = "device_enrollments"
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"host_id",
|
|
"local_device_id",
|
|
name="uq_device_enrollments_host_local",
|
|
),
|
|
Index("ix_device_enrollments_host_id", "host_id"),
|
|
)
|
|
|
|
device_id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
host_id: Mapped[str] = mapped_column(String, nullable=False)
|
|
local_device_id: Mapped[str] = mapped_column(String, nullable=False)
|
|
driver_type: Mapped[str] = mapped_column(String, nullable=False)
|
|
name: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
capability_tags_json: Mapped[str] = mapped_column(Text, nullable=False)
|
|
enrolled_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
revoked_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
|
|
|
|
class PooledDeviceRow(Base):
|
|
__tablename__ = "pooled_devices"
|
|
|
|
host_id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
device_id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
driver_type: Mapped[str] = mapped_column(String, nullable=False)
|
|
status: Mapped[str] = mapped_column(String, nullable=False)
|
|
capability_tags_json: Mapped[str] = mapped_column(Text, nullable=False)
|
|
synced_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
|
|
|
|
class ScheduledTaskRow(Base):
|
|
__tablename__ = "scheduled_tasks"
|
|
|
|
id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
goal: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
workflow_definition_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
constraints_json: Mapped[str] = mapped_column(Text, nullable=False)
|
|
status: Mapped[str] = mapped_column(String, nullable=False)
|
|
assigned_device_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
assigned_host_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
attempt_count: Mapped[int] = mapped_column(
|
|
Integer,
|
|
nullable=False,
|
|
default=0,
|
|
server_default=text("0"),
|
|
)
|
|
lease_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
lease_expires_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
failure_reason: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
result_json: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
updated_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
created_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
|
|
|
|
class TaskAttemptRow(Base):
|
|
__tablename__ = "task_attempts"
|
|
|
|
task_id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
attempt: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
lease_id: Mapped[str] = mapped_column(String, nullable=False)
|
|
host_id: Mapped[str] = mapped_column(String, nullable=False)
|
|
device_id: Mapped[str] = mapped_column(String, nullable=False)
|
|
status: Mapped[str] = mapped_column(String, nullable=False)
|
|
lease_expires_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
created_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
completed_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
failure_reason: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
result_json: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
|
|
class PluginRow(Base):
|
|
__tablename__ = "plugins"
|
|
|
|
name: Mapped[str] = mapped_column(String, primary_key=True)
|
|
version: Mapped[str] = mapped_column(String, nullable=False)
|
|
entry_point_kind: Mapped[str] = mapped_column(String, nullable=False)
|
|
target: Mapped[str] = mapped_column(String, nullable=False)
|
|
wired: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
|
|
|
|
class UserRow(Base):
|
|
__tablename__ = "cloud_users"
|
|
__table_args__ = (
|
|
UniqueConstraint("username_normalized", name="uq_cloud_users_username_normalized"),
|
|
Index("ix_cloud_users_enabled_role", "enabled", "role"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
username: Mapped[str] = mapped_column(String, nullable=False)
|
|
username_normalized: Mapped[str] = mapped_column(String, nullable=False)
|
|
display_name: Mapped[str] = mapped_column(String, nullable=False)
|
|
password_hash: Mapped[str] = mapped_column(Text, nullable=False)
|
|
role: Mapped[str] = mapped_column(String, nullable=False)
|
|
enabled: Mapped[int] = mapped_column(Integer, nullable=False, default=1, server_default=text("1"))
|
|
must_change_password: Mapped[int] = mapped_column(
|
|
Integer,
|
|
nullable=False,
|
|
default=0,
|
|
server_default=text("0"),
|
|
)
|
|
authentication_version: Mapped[int] = mapped_column(
|
|
Integer,
|
|
nullable=False,
|
|
default=1,
|
|
server_default=text("1"),
|
|
)
|
|
created_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
updated_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
last_login_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
|
|
|
|
class UserSessionRow(Base):
|
|
__tablename__ = "cloud_user_sessions"
|
|
__table_args__ = (
|
|
UniqueConstraint("token_digest", name="uq_cloud_user_sessions_token_digest"),
|
|
Index("ix_cloud_user_sessions_user_id", "user_id"),
|
|
Index("ix_cloud_user_sessions_absolute_expires_at", "absolute_expires_at"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
user_id: Mapped[str] = mapped_column(
|
|
ForeignKey("cloud_users.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
)
|
|
token_digest: Mapped[str] = mapped_column(String, nullable=False)
|
|
csrf_digest: Mapped[str] = mapped_column(String, nullable=False)
|
|
authentication_version: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
issued_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
last_seen_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
idle_expires_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
absolute_expires_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
revoked_at: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
|
|
|
|
class LoginThrottleRow(Base):
|
|
__tablename__ = "cloud_login_throttles"
|
|
|
|
username_normalized: Mapped[str] = mapped_column(String, primary_key=True)
|
|
client_bucket: Mapped[str] = mapped_column(String, primary_key=True)
|
|
failure_count: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
window_started_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
last_attempt_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
blocked_until: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
|
|
|
|
class AuthAuditRow(Base):
|
|
__tablename__ = "cloud_auth_audit_events"
|
|
__table_args__ = (
|
|
Index("ix_cloud_auth_audit_events_occurred_at", "occurred_at"),
|
|
Index("ix_cloud_auth_audit_events_target_user_id", "target_user_id"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
occurred_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
actor_principal_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
target_user_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
action: Mapped[str] = mapped_column(String, nullable=False)
|
|
outcome: Mapped[str] = mapped_column(String, nullable=False)
|
|
correlation_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
metadata_json: Mapped[str] = mapped_column(Text, nullable=False, default="{}")
|
|
|
|
|
|
class UserSubmissionPolicyRow(Base):
|
|
__tablename__ = "cloud_user_submission_policies"
|
|
|
|
user_id: Mapped[str] = mapped_column(
|
|
ForeignKey("cloud_users.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
revision: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
submission_enabled: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
allowed_host_ids_json: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
allowed_device_targets_json: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
updated_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
|
|
|
|
class HostGovernancePolicyRow(Base):
|
|
__tablename__ = "cloud_host_governance_policies"
|
|
|
|
host_id: Mapped[str] = mapped_column(
|
|
ForeignKey("host_registrations.host_id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
revision: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
self_submission_enabled: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
max_active_tasks: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
daily_token_budget: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
updated_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
|
|
|
|
class TokenReservationRow(Base):
|
|
__tablename__ = "cloud_token_reservations"
|
|
__table_args__ = (
|
|
Index("ix_cloud_token_reservations_host_day", "host_id", "usage_day"),
|
|
Index("ix_cloud_token_reservations_expires_at", "expires_at"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
host_id: Mapped[str] = mapped_column(
|
|
ForeignKey("host_registrations.host_id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
usage_day: Mapped[str] = mapped_column(String, nullable=False)
|
|
reserved_tokens: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
task_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
attempt: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
created_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
expires_at: Mapped[str] = mapped_column(String, nullable=False)
|
|
|
|
|
|
class TokenUsageEventRow(Base):
|
|
__tablename__ = "cloud_token_usage_events"
|
|
__table_args__ = (
|
|
Index("ix_cloud_token_usage_events_host_day", "host_id", "usage_day"),
|
|
Index("ix_cloud_token_usage_events_occurred_at", "occurred_at"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String, primary_key=True)
|
|
host_id: Mapped[str] = mapped_column(
|
|
ForeignKey("host_registrations.host_id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
usage_day: Mapped[str] = mapped_column(String, nullable=False)
|
|
task_id: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
attempt: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
provider: Mapped[str] = mapped_column(String, nullable=False)
|
|
model: Mapped[str] = mapped_column(String, nullable=False)
|
|
input_tokens: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
output_tokens: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
total_tokens: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
occurred_at: Mapped[str] = mapped_column(String, nullable=False)
|