Exemplo n.º 1
0
def _filter_tree(
        struct_tree: Optional[StructuredDataNode]
) -> Optional[StructuredDataNode]:
    if struct_tree is None:
        return None

    if permitted_paths := _get_permitted_inventory_paths():
        return struct_tree.get_filtered_node(
            [make_filter(entry) for entry in permitted_paths if entry])
Exemplo n.º 2
0
def _filter_tree(struct_tree: Optional[StructuredDataNode]) -> Optional[StructuredDataNode]:
    if struct_tree is None:
        return None

    if permitted_paths := _get_permitted_inventory_paths():
        return struct_tree.get_filtered_node([
            make_filter((parse_visible_raw_path(entry["path"]), entry.get("attributes")))
            for entry in permitted_paths
        ])
Exemplo n.º 3
0
def test_make_filter(entry, expected_path, expected_filter_results):
    f = make_filter(entry)

    assert f.path == expected_path

    assert f.filter_nodes("node") is expected_filter_results.nodes
    assert f.filter_nodes("other") is expected_filter_results.restricted_nodes

    assert f.filter_attributes("key") is expected_filter_results.attributes
    assert f.filter_attributes(
        "other") is expected_filter_results.restricted_attributes

    assert f.filter_columns("key") is expected_filter_results.columns
    assert f.filter_columns(
        "other") is expected_filter_results.restricted_columns
Exemplo n.º 4
0
def inventory_of_host(host_name: HostName, api_request):
    raw_site = api_request.get("site")
    site = livestatus.SiteId(raw_site) if raw_site is not None else None
    verify_permission(host_name, site)

    row = get_status_data_via_livestatus(site, host_name)
    merged_tree = load_filtered_and_merged_tree(row)
    if not merged_tree:
        return {}

    if "paths" in api_request:
        merged_tree = merged_tree.get_filtered_node(
            [make_filter(parse_tree_path(path)) for path in api_request["paths"]])

    assert merged_tree is not None
    return merged_tree.get_raw_tree()
Exemplo n.º 5
0
def _make_filters(allowed_paths):
    return [make_filter(entry) for entry in allowed_paths]