Skip to content

Commit aedce02

Browse files
committed
Add LookupTableFile entity and LookupTableFiles collection
1 parent b77f3f9 commit aedce02

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

‎splunklib/client.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import socket
6565
from datetime import datetime, timedelta
6666
from time import sleep
67+
from typing import Any
6768
from urllib import parse
6869

6970
try:
@@ -124,6 +125,7 @@ def deprecated(message): # pyright: ignore[reportUnknownParameterType]
124125
PATH_RECEIVERS_STREAM = "/services/receivers/stream"
125126
PATH_RECEIVERS_SIMPLE = "/services/receivers/simple"
126127
PATH_STORAGE_PASSWORDS = "storage/passwords"
128+
PATH_LOOKUP_TABLE_FILES = "data/lookup-table-files/"
127129

128130
XNAMEF_ATOM = "{http://www.w3.org/2005/Atom}%s"
129131
XNAME_ENTRY = XNAMEF_ATOM % "entry"
@@ -554,6 +556,14 @@ def loggers(self):
554556
"""
555557
return Loggers(self)
556558

559+
@property
560+
def lookup_table_files(self):
561+
"""Returns the collection of lookup table files.
562+
563+
:return: A :class:`LookupTableFiles` collection of :class:`LookupTableFile` entities.
564+
"""
565+
return LookupTableFiles(self)
566+
557567
@property
558568
def messages(self):
559569
"""Returns the collection of service messages.
@@ -3881,6 +3891,36 @@ def delete(self, name):
38813891
return Collection.delete(self, name.lower())
38823892

38833893

3894+
class LookupTableFile(Entity):
3895+
"""Represents a lookup table CSV file."""
3896+
3897+
def __init__(self, service: "Service", path: str, **kwargs: Any) -> None:
3898+
Entity.__init__(self, service, path, **kwargs)
3899+
3900+
def download(self) -> Any:
3901+
"""Downloads the lookup file contents via ``| inputlookup``.
3902+
3903+
Runs a oneshot search to retrieve the CSV data for this lookup.
3904+
3905+
:return: A streaming response handle with the CSV content.
3906+
:rtype: ``InputStream``
3907+
"""
3908+
return self.service.jobs.oneshot( # pyright: ignore[reportUnknownVariableType]
3909+
f"| inputlookup {self.name}",
3910+
output_mode="csv",
3911+
)
3912+
3913+
3914+
class LookupTableFiles(Collection):
3915+
"""Provides access to the collection of lookup table files.
3916+
3917+
Retrieve this collection using :meth:`Service.lookup_table_files`.
3918+
"""
3919+
3920+
def __init__(self, service: "Service") -> None:
3921+
Collection.__init__(self, service, PATH_LOOKUP_TABLE_FILES, item=LookupTableFile)
3922+
3923+
38843924
class Application(Entity):
38853925
"""Represents a locally-installed Splunk app."""
38863926

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright © 2011-2026 Splunk, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
from splunklib.client import (
16+
PATH_LOOKUP_TABLE_FILES,
17+
Collection,
18+
Entity,
19+
LookupTableFile,
20+
LookupTableFiles,
21+
)
22+
23+
24+
class TestLookupTableFile:
25+
def test_is_entity_subclass(self) -> None:
26+
assert issubclass(LookupTableFile, Entity)
27+
28+
def test_path_constant(self) -> None:
29+
assert PATH_LOOKUP_TABLE_FILES == "data/lookup-table-files/"
30+
31+
32+
class TestLookupTableFiles:
33+
def test_is_collection_subclass(self) -> None:
34+
assert issubclass(LookupTableFiles, Collection)

0 commit comments

Comments
 (0)