Skip to content

Commit 752527b

Browse files
authored
Merge pull request #366 from splunk/master
Master -> Develop
2 parents ed75051 + b36d6eb commit 752527b

13 files changed

Lines changed: 293 additions & 5 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Logs or Screenshots**
24+
If applicable, add logs or screenshots to help explain your problem.
25+
26+
**Splunk (please complete the following information):**
27+
- Version: [e.g. 8.0.5]
28+
- OS: [e.g. Ubuntu 20.04.1]
29+
- Deployment: [e.g. single-instance]
30+
31+
**SDK (please complete the following information):**
32+
- Version: [e.g. 1.6.14]
33+
- Language Runtime Version: [e.g. Python 3.7]
34+
- OS: [e.g. MacOS 10.15.7]
35+
36+
**Additional context**
37+
Add any other context about the problem here.

‎.github/ISSUE_TEMPLATE/custom.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Custom issue template
3+
about: Describe this issue template's purpose here.
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

‎CHANGELOG.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Splunk Enterprise SDK for Python Changelog
22

3+
## Version 1.6.15
4+
5+
### Bug fixes
6+
[#301](https://github.com/splunk/splunk-sdk-python/pull/301) Fix chunk synchronization
7+
[#327](https://github.com/splunk/splunk-sdk-python/pull/327) Rename and cleanup follow-up for chunk synchronization
8+
[#352](https://github.com/splunk/splunk-sdk-python/pull/352) Allow supplying of a key-value body when calling Context.post()
9+
10+
### Minor changes
11+
[#350](https://github.com/splunk/splunk-sdk-python/pull/350) Initial end-to-end tests for streaming, reporting, generating custom search commands
12+
[#348](https://github.com/splunk/splunk-sdk-python/pull/348) Update copyright years to 2020
13+
[#346](https://github.com/splunk/splunk-sdk-python/pull/346) Readme updates to urls, terminology, and formatting
14+
[#317](https://github.com/splunk/splunk-sdk-python/pull/317) Fix deprecation warnings
15+
316
## Version 1.6.14
417

518
### Bug fix

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# The Splunk Enterprise Software Development Kit for Python
55

6-
#### Version 1.6.14
6+
#### Version 1.6.15
77

88
The Splunk Enterprise Software Development Kit (SDK) for Python contains library code and examples designed to enable developers to build applications using the Splunk platform.
99

‎examples/searchcommands_app/setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def run(self):
439439
setup(
440440
description='Custom Search Command examples',
441441
name=os.path.basename(project_dir),
442-
version='1.6.14',
442+
version='1.6.15',
443443
author='Splunk, Inc.',
444444
author_email='devinfo@splunk.com',
445445
url='http://github.com/splunk/splunk-sdk-python',

‎splunklib/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
from __future__ import absolute_import
1818
from splunklib.six.moves import map
19-
__version_info__ = (1, 6, 14)
19+
__version_info__ = (1, 6, 15)
2020
__version__ = ".".join(map(str, __version_info__))

‎splunklib/binding.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ def request(url, message, **kwargs):
13851385
head = {
13861386
"Content-Length": str(len(body)),
13871387
"Host": host,
1388-
"User-Agent": "splunk-sdk-python/1.6.14",
1388+
"User-Agent": "splunk-sdk-python/1.6.15",
13891389
"Accept": "*/*",
13901390
"Connection": "Close",
13911391
} # defaults

‎splunklib/searchcommands/search_command.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ def _execute(self, ifile, process):
856856

857857
@staticmethod
858858
def _as_binary_stream(ifile):
859-
if six.PY2:
859+
naught = ifile.read(0)
860+
if isinstance(naught, bytes):
860861
return ifile
861862

862863
try:
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import collections
2+
import csv
3+
import io
4+
import json
5+
6+
import splunklib.searchcommands.internals
7+
from splunklib import six
8+
9+
10+
class Chunk(object):
11+
def __init__(self, version, meta, data):
12+
self.version = six.ensure_str(version)
13+
self.meta = json.loads(meta)
14+
dialect = splunklib.searchcommands.internals.CsvDialect
15+
self.data = csv.DictReader(io.StringIO(data.decode("utf-8")),
16+
dialect=dialect)
17+
18+
19+
class ChunkedDataStreamIter(collections.Iterator):
20+
def __init__(self, chunk_stream):
21+
self.chunk_stream = chunk_stream
22+
23+
def __next__(self):
24+
return self.next()
25+
26+
def next(self):
27+
try:
28+
return self.chunk_stream.read_chunk()
29+
except EOFError:
30+
raise StopIteration
31+
32+
33+
class ChunkedDataStream(collections.Iterable):
34+
def __iter__(self):
35+
return ChunkedDataStreamIter(self)
36+
37+
def __init__(self, stream):
38+
empty = stream.read(0)
39+
assert isinstance(empty, bytes)
40+
self.stream = stream
41+
42+
def read_chunk(self):
43+
header = self.stream.readline()
44+
45+
while len(header) > 0 and header.strip() == b'':
46+
header = self.stream.readline() # Skip empty lines
47+
if len(header) == 0:
48+
raise EOFError
49+
50+
version, meta, data = header.rstrip().split(b',')
51+
metabytes = self.stream.read(int(meta))
52+
databytes = self.stream.read(int(data))
53+
return Chunk(version, metabytes, databytes)
54+
55+
56+
def build_chunk(keyval, data=None):
57+
metadata = six.ensure_binary(json.dumps(keyval), 'utf-8')
58+
data_output = _build_data_csv(data)
59+
return b"chunked 1.0,%d,%d\n%s%s" % (len(metadata), len(data_output), metadata, data_output)
60+
61+
62+
def build_empty_searchinfo():
63+
return {
64+
'earliest_time': 0,
65+
'latest_time': 0,
66+
'search': "",
67+
'dispatch_dir': "",
68+
'sid': "",
69+
'args': [],
70+
'splunk_version': "42.3.4",
71+
}
72+
73+
74+
def build_getinfo_chunk():
75+
return build_chunk({
76+
'action': 'getinfo',
77+
'preview': False,
78+
'searchinfo': build_empty_searchinfo()})
79+
80+
81+
def build_data_chunk(data, finished=True):
82+
return build_chunk({'action': 'execute', 'finished': finished}, data)
83+
84+
85+
def _build_data_csv(data):
86+
if data is None:
87+
return b''
88+
if isinstance(data, bytes):
89+
return data
90+
csvout = splunklib.six.StringIO()
91+
92+
headers = set()
93+
for datum in data:
94+
headers.update(datum.keys())
95+
writer = csv.DictWriter(csvout, headers,
96+
dialect=splunklib.searchcommands.internals.CsvDialect)
97+
writer.writeheader()
98+
for datum in data:
99+
writer.writerow(datum)
100+
return six.ensure_binary(csvout.getvalue())

0 commit comments

Comments
 (0)