32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Agent poll payload: commands, desired config, pending update."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models import Host
|
|
from app.services.agent_commands import command_to_dict, get_command_for_host_poll
|
|
from app.services.agent_host_config import build_agent_config_payload
|
|
from app.services.agent_update_settings import get_effective_agent_update_config
|
|
|
|
|
|
def build_agent_poll_payload(db: Session, host: Host) -> dict[str, Any]:
|
|
cfg = get_effective_agent_update_config(db)
|
|
pending = get_command_for_host_poll(db, host)
|
|
config_payload = build_agent_config_payload(host)
|
|
|
|
update_block: dict[str, Any] = {
|
|
"requested": bool(host.pending_agent_update),
|
|
"target_version": host.pending_update_target_version,
|
|
"source": "sac" if cfg.sac_managed else "gpo",
|
|
}
|
|
|
|
return {
|
|
"config_revision": int(host.agent_config_revision or 0),
|
|
"config": config_payload,
|
|
"update": update_block,
|
|
"commands": [command_to_dict(c, include_run_as=True, db=db, host=host) for c in pending],
|
|
}
|