Skip to content

Commit bce95e7

Browse files
committed
Version 1.1.8 - Merged pull request from calesanz #16 to allow a new sslVerify option to pass in the CA certificate file, or to leave SSL validation disabled
In addition this pull request adds a requestingAddress which optionally controls the call-back ip when using the postversioncontrolrestore command Finally this pull requests adds scripts and a testing suite using docker Updated python SDK to 1.6.15 Minor fixes to the pull request
1 parent 14aa4f6 commit bce95e7

File tree

12 files changed

+124
-95
lines changed

12 files changed

+124
-95
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ To do this you will need to install Version Control For SplunkCloud on your Splu
265265
## Release Notes
266266
### 1.1.8
267267
README.md update - git repositories must be dedicated per-backup and not shared with other items as the root level / top level directory is used
268+
Merged pull request from calesanz https://github.com/gjanders/SplunkVersionControl/pull/16 to allow a new sslVerify option to pass in the CA certificate file, or to leave SSL validation disabled
269+
In addition this pull request adds a requestingAddress which optionally controls the call-back ip when using the postversioncontrolrestore command
270+
Finally this pull requests adds scripts and a testing suite using docker into the github version, for SplunkBase the test directory is removed (you can access it on https://github.com/gjanders/SplunkVersionControl)
271+
272+
Updated Splunk python SDK to 1.6.15
268273

269274
### 1.1.7
270275
Increase timeout for commands to a default of 60 seconds

SplunkVersionControl.tgz

-169 KB
Binary file not shown.

bin/splunkversioncontrol_rest_restore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def handle_POST(self):
163163
else:
164164
time_wait = 600
165165

166-
if 'requestingAddress' in payload:
166+
if 'requestingAddress' in payload and payload['requestingAddress'][0].lower() != 'false':
167167
requestingAddress = payload['requestingAddress'][0]
168168
else:
169169
requestingAddress = None

default/app.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ label = SplunkVersionControl
1212
[launcher]
1313
author = Gareth Anderson
1414
description = Version Control software for Splunk instances (backup/restore from git)
15-
version = 1.1.7
15+
version = 1.1.8
1616

1717
[package]
1818
id = SplunkVersionControl

default/macros.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ definition = 30
2020
iseval = 0
2121

2222
[sslVerify]
23-
definition = false
23+
definition = False
2424
iseval = 0
2525

2626
[requestingAddress]
27-
definition = false
27+
definition = False
2828
iseval = 0
2929

lib/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__))

lib/splunklib/binding.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,12 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, *
724724
:type headers: ``list`` of 2-tuples.
725725
:param query: All other keyword arguments, which are used as query
726726
parameters.
727-
:type query: ``string``
727+
:param body: Parameters to be used in the post body. If specified,
728+
any parameters in the query will be applied to the URL instead of
729+
the body. If a dict is supplied, the key-value pairs will be form
730+
encoded. If a string is supplied, the body will be passed through
731+
in the request unchanged.
732+
:type body: ``dict`` or ``str``
728733
:return: The response from the server.
729734
:rtype: ``dict`` with keys ``body``, ``headers``, ``reason``,
730735
and ``status``
@@ -1223,6 +1228,8 @@ def post(self, url, headers=None, **kwargs):
12231228
headers.append(("Content-Type", "application/x-www-form-urlencoded"))
12241229

12251230
body = kwargs.pop('body')
1231+
if isinstance(body, dict):
1232+
body = _encode(**body).encode('utf-8')
12261233
if len(kwargs) > 0:
12271234
url = url + UrlEncoded('?' + _encode(**kwargs), skip_encode=True)
12281235
else:
@@ -1378,7 +1385,7 @@ def request(url, message, **kwargs):
13781385
head = {
13791386
"Content-Length": str(len(body)),
13801387
"Host": host,
1381-
"User-Agent": "splunk-sdk-python/1.6.14",
1388+
"User-Agent": "splunk-sdk-python/1.6.15",
13821389
"Accept": "*/*",
13831390
"Connection": "Close",
13841391
} # defaults

lib/splunklib/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ def delete(self, username, realm=None):
18721872
name = UrlEncoded(realm, encode_slash=True) + ":" + UrlEncoded(username, encode_slash=True)
18731873

18741874
# Append the : expected at the end of the name
1875-
if name[-1] is not ":":
1875+
if name[-1] != ":":
18761876
name = name + ":"
18771877
return Collection.delete(self, name)
18781878

lib/splunklib/searchcommands/generating_command.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,21 @@ def _execute(self, ifile, process):
204204
205205
"""
206206
if self._protocol_version == 2:
207-
result = self._read_chunk(self._as_binary_stream(ifile))
207+
self._execute_v2(ifile, self.generate())
208+
else:
209+
assert self._protocol_version == 1
210+
self._record_writer.write_records(self.generate())
211+
self.finish()
208212

209-
if not result:
213+
def _execute_chunk_v2(self, process, chunk):
214+
count = 0
215+
for row in process:
216+
self._record_writer.write_record(row)
217+
count += 1
218+
if count == self._record_writer._maxresultrows:
219+
self._finished = False
210220
return
211-
212-
metadata, body = result
213-
action = getattr(metadata, 'action', None)
214-
215-
if action != 'execute':
216-
raise RuntimeError('Expected execute action, not {}'.format(action))
217-
218-
self._record_writer.write_records(self.generate())
219-
self.finish()
221+
self._finished = True
220222

221223
# endregion
222224

lib/splunklib/searchcommands/internals.py

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import os
3636
import re
3737
import sys
38+
import warnings
3839

3940
from . import environment
4041

@@ -74,7 +75,7 @@ def set_binary_mode(fh):
7475

7576

7677
class CommandLineParser(object):
77-
""" Parses the arguments to a search command.
78+
r""" Parses the arguments to a search command.
7879
7980
A search command line is described by the following syntax.
8081
@@ -505,8 +506,8 @@ def __init__(self, ofile, maxresultrows=None):
505506

506507
self._inspector = OrderedDict()
507508
self._chunk_count = 0
508-
self._record_count = 0
509-
self._total_record_count = 0
509+
self._pending_record_count = 0
510+
self._committed_record_count = 0
510511

511512
@property
512513
def is_flushed(self):
@@ -524,6 +525,30 @@ def ofile(self):
524525
def ofile(self, value):
525526
self._ofile = set_binary_mode(value)
526527

528+
@property
529+
def pending_record_count(self):
530+
return self._pending_record_count
531+
532+
@property
533+
def _record_count(self):
534+
warnings.warn(
535+
"_record_count will be deprecated soon. Use pending_record_count instead.",
536+
PendingDeprecationWarning
537+
)
538+
return self.pending_record_count
539+
540+
@property
541+
def committed_record_count(self):
542+
return self._committed_record_count
543+
544+
@property
545+
def _total_record_count(self):
546+
warnings.warn(
547+
"_total_record_count will be deprecated soon. Use committed_record_count instead.",
548+
PendingDeprecationWarning
549+
)
550+
return self.committed_record_count
551+
527552
def write(self, data):
528553
bytes_type = bytes if sys.version_info >= (3, 0) else str
529554
if not isinstance(data, bytes_type):
@@ -555,8 +580,7 @@ def _clear(self):
555580
self._buffer.seek(0)
556581
self._buffer.truncate()
557582
self._inspector.clear()
558-
self._record_count = 0
559-
self._flushed = False
583+
self._pending_record_count = 0
560584

561585
def _ensure_validity(self):
562586
if self._finished is True:
@@ -651,9 +675,9 @@ def _write_record(self, record):
651675
values += (repr(value), None)
652676

653677
self._writerow(values)
654-
self._record_count += 1
678+
self._pending_record_count += 1
655679

656-
if self._record_count >= self._maxresultrows:
680+
if self.pending_record_count >= self._maxresultrows:
657681
self.flush(partial=True)
658682

659683
try:
@@ -690,7 +714,7 @@ def flush(self, finished=None, partial=None):
690714

691715
RecordWriter.flush(self, finished, partial) # validates arguments and the state of this instance
692716

693-
if self._record_count > 0 or (self._chunk_count == 0 and 'messages' in self._inspector):
717+
if self.pending_record_count > 0 or (self._chunk_count == 0 and 'messages' in self._inspector):
694718

695719
messages = self._inspector.get('messages')
696720

@@ -728,9 +752,9 @@ def flush(self, finished=None, partial=None):
728752
print(level, text, file=stderr)
729753

730754
self.write(self._buffer.getvalue())
731-
self._clear()
732755
self._chunk_count += 1
733-
self._total_record_count += self._record_count
756+
self._committed_record_count += self.pending_record_count
757+
self._clear()
734758

735759
self._finished = finished is True
736760

@@ -748,37 +772,36 @@ class RecordWriterV2(RecordWriter):
748772
def flush(self, finished=None, partial=None):
749773

750774
RecordWriter.flush(self, finished, partial) # validates arguments and the state of this instance
751-
inspector = self._inspector
752-
753-
if self._flushed is False:
754-
755-
self._total_record_count += self._record_count
756-
self._chunk_count += 1
757-
758-
# TODO: DVPL-6448: splunklib.searchcommands | Add support for partial: true when it is implemented in
759-
# ChunkedExternProcessor (See SPL-103525)
760-
#
761-
# We will need to replace the following block of code with this block:
762-
#
763-
# metadata = [
764-
# ('inspector', self._inspector if len(self._inspector) else None),
765-
# ('finished', finished),
766-
# ('partial', partial)]
767-
768-
if len(inspector) == 0:
769-
inspector = None
770-
771-
if partial is True:
772-
finished = False
773775

774-
metadata = [item for item in (('inspector', inspector), ('finished', finished))]
775-
self._write_chunk(metadata, self._buffer.getvalue())
776-
self._clear()
776+
if partial or not finished:
777+
# Don't flush partial chunks, since the SCP v2 protocol does not
778+
# provide a way to send partial chunks yet.
779+
return
777780

778-
elif finished is True:
779-
self._write_chunk((('finished', True),), '')
781+
if not self.is_flushed:
782+
self.write_chunk(finished=True)
780783

781-
self._finished = finished is True
784+
def write_chunk(self, finished=None):
785+
inspector = self._inspector
786+
self._committed_record_count += self.pending_record_count
787+
self._chunk_count += 1
788+
789+
# TODO: DVPL-6448: splunklib.searchcommands | Add support for partial: true when it is implemented in
790+
# ChunkedExternProcessor (See SPL-103525)
791+
#
792+
# We will need to replace the following block of code with this block:
793+
#
794+
# metadata = [item for item in (('inspector', inspector), ('finished', finished), ('partial', partial))]
795+
#
796+
# if partial is True:
797+
# finished = False
798+
799+
if len(inspector) == 0:
800+
inspector = None
801+
802+
metadata = [item for item in (('inspector', inspector), ('finished', finished))]
803+
self._write_chunk(metadata, self._buffer.getvalue())
804+
self._clear()
782805

783806
def write_metadata(self, configuration):
784807
self._ensure_validity()
@@ -793,7 +816,7 @@ def write_metric(self, name, value):
793816
self._inspector['metric.' + name] = value
794817

795818
def _clear(self):
796-
RecordWriter._clear(self)
819+
super(RecordWriterV2, self)._clear()
797820
self._fieldnames = None
798821

799822
def _write_chunk(self, metadata, body):
@@ -818,4 +841,4 @@ def _write_chunk(self, metadata, body):
818841
self.write(metadata)
819842
self.write(body)
820843
self._ofile.flush()
821-
self._flushed = False
844+
self._flushed = True

0 commit comments

Comments
 (0)