Compare commits

..

No commits in common. "main" and "v0.1" have entirely different histories.
main ... v0.1

7 changed files with 11 additions and 22 deletions

Binary file not shown.

View File

@ -13,12 +13,12 @@ def get_pillar_name_sequence(name: str) -> list[str]:
def decode_pillar_value(pillar: Pillar) -> str | int | float | bool | list | dict:
match pillar.parameter_type:
case 'string': return str(json.loads(pillar.value))
case 'integer': return int(json.loads(pillar.value))
case 'float': return float(json.loads(pillar.value))
case 'boolean': return bool(json.loads(pillar.value))
case 'list': return list(json.loads(pillar.value))
case 'dict': return dict(json.loads(pillar.value))
case 'string': return str(pillar.value)
case 'integer': return int(pillar.value)
case 'float': return float(pillar.value)
case 'boolean': return bool(pillar.value)
case 'array': return json.loads(pillar.value)
case 'dict': return json.loads(pillar.value)
raise RuntimeError(f"Failed to decode pillar value: Invalid type '{pillar.parameter_type}'")
@ -43,6 +43,6 @@ def get_pillar_for_target(db: Session, target: UUID) -> dict:
current[label] = {}
current = current[label]
else:
current[label] = value
current[label] = json.loads(str(value))
return out

View File

@ -140,10 +140,10 @@ def hostgroup_create(req: Request, name: str, params: HostgroupParams):
print("[DEBUG] hostgroup_create: creating hostgroup hierarchy with {} label(s): {}".format(len(labels), labels))
stmt = select(Host).where(and_(Host.name == bindparam('name'), Host.is_hostgroup == True, Host.parent_id == bindparam('last')))
last = None
for label in labels:
stmt = select(Host).where(and_(Host.name == label, Host.is_hostgroup == True, Host.parent_id == last))
result = db.execute(stmt).fetchall()
result = db.execute(stmt, {'name': label, 'last': last}).fetchall()
if len(result) == 1:
# simply step down through the hierarchy

View File

@ -11,7 +11,7 @@ from starlette.requests import Request
from fastapi import APIRouter, Depends
from starlette.responses import JSONResponse
from pillar_tool.db import Host, Pillar, TopFile
from pillar_tool.db import Host, Pillar
from pillar_tool.db.models.top_data import State, StateAssignment
from pillar_tool.db.queries.pillar_queries import get_pillar_for_target
from pillar_tool.schemas import PillarParams, get_model_from_query
@ -83,20 +83,9 @@ def pillar_get(req: Request, target: str) -> JSONResponse:
path.reverse()
# create 'virtual' pillar for states
stmt_states = select(State).join(TopFile, TopFile.state_id == State.id).where(TopFile.host_id == host.id)
states_list: list[str] = [ x[0].name for x in db.execute(stmt_states).fetchall() ]
# create path name
hostgroup_name = '/'.join(x.name for x in path[:-1])
print("[DEBUG] pillar_get: resolved host hierarchy with {} hosts: {}".format(len(path), [h.name for h in path]))
out = merge([get_pillar_for_target(db, host.id) for host in path]) # type: ignore
out.update({
"states": states_list,
"hostgroup": hostgroup_name
})
print("[DEBUG] pillar_get: merged pillar data contains {} top-level key(s)".format(len(out)))
return JSONResponse(status_code=200, content=out)

View File

@ -1,6 +1,6 @@
[project]
name = "pillartool"
version = "0.6.0"
version = "0.1.0"
description = "Add your description here"
requires-python = ">=3.13"
dependencies = [