Skip to content

Commit 51bd6b8

Browse files
author
Parul Upadhyaya
committed
Release 1.6.12
* release/1.6.12: add comment to document use of Splunk auth token update changelog and release version number in files error in checking to see if error output is a TextIOBase update version of embedded six.py update modular inputs to use text TextIO consistently across 2.7 and 3.x run tests in Splunk 8.0 Changed permissions from 755 to 644 for python files to pass appinspect checks Remove version check on ssl verify toggle Bearer token support (using Splunk Token presented in v7.3)
2 parents b4d50ab + f46bb46 commit 51bd6b8

20 files changed

+197
-54
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ before_install:
3232
env:
3333
- SPLUNK_VERSION=7.0-sdk
3434
- SPLUNK_VERSION=7.2-sdk
35+
- SPLUNK_VERSION=8.0-sdk
3536

3637
language: python
3738

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Splunk SDK for Python Changelog
22

3+
## Version 1.6.12
4+
5+
### New features and APIs
6+
* Added Bearer token support using Splunk Token in v7.3
7+
* Made modinput text consistent
8+
9+
### Bug fixes
10+
* Changed permissions from 755 to 644 for python files to pass appinspect checks
11+
* Removed version check on ssl verify toggle
12+
313
## Version 1.6.11
414

515
### Bug Fix

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# The Splunk Software Development Kit for Python
55

6-
#### Version 1.6.11
6+
#### Version 1.6.12
77

88
The Splunk Software Development Kit (SDK) for Python contains library code and
99
examples designed to enable developers to build applications using Splunk.
@@ -17,7 +17,7 @@ monitoring of IT machine data, security, compliance and a wide variety of other
1717
scenarios that share a requirement to efficiently index, search, analyze and
1818
generate real-time notifications from large volumes of time series data.
1919

20-
The Splunk developer platform enables developers to take advantage of the same
20+
The Splunk developer platform enables ^Fdevelopers to take advantage of the same
2121
technology used by the Splunk product to build exciting new applications that
2222
are enabled by Splunk's unique capabilities.
2323

examples/searchcommands_app/setup.py

+1-1
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.11',
442+
version='1.6.12',
443443
author='Splunk, Inc.',
444444
author_email='[email protected]',
445445
url='http://github.com/splunk/splunk-sdk-python',

splunklib/__init__.py

+1-1
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, 11)
19+
__version_info__ = (1, 6, 12)
2020
__version__ = ".".join(map(str, __version_info__))

splunklib/binding.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ class Context(object):
450450
:type username: ``string``
451451
:param password: The password for the Splunk account.
452452
:type password: ``string``
453+
:param splunkToken: Splunk authentication token
454+
:type splunkToken: ``string``
453455
:param headers: List of extra HTTP headers to send (optional).
454456
:type headers: ``list`` of 2-tuples.
455457
:param handler: The HTTP request handler (optional).
@@ -481,6 +483,7 @@ def __init__(self, handler=None, **kwargs):
481483
self.username = kwargs.get("username", "")
482484
self.password = kwargs.get("password", "")
483485
self.basic = kwargs.get("basic", False)
486+
self.bearerToken = kwargs.get("splunkToken", "")
484487
self.autologin = kwargs.get("autologin", False)
485488
self.additional_headers = kwargs.get("headers", [])
486489

@@ -521,6 +524,9 @@ def _auth_headers(self):
521524
elif self.basic and (self.username and self.password):
522525
token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii')
523526
return [("Authorization", token)]
527+
elif self.bearerToken:
528+
token = 'Bearer %s' % self.bearerToken
529+
return [("Authorization", token)]
524530
elif self.token is _NoAuthenticationToken:
525531
return []
526532
else:
@@ -863,6 +869,10 @@ def login(self):
863869
# as credentials were passed in.
864870
return
865871

872+
if self.bearerToken:
873+
# Bearer auth mode requested, so this method is a nop as long
874+
# as authentication token was passed in.
875+
return
866876
# Only try to get a token and updated cookie if username & password are specified
867877
try:
868878
response = self.http.post(
@@ -1357,8 +1367,7 @@ def connect(scheme, host, port):
13571367
if key_file is not None: kwargs['key_file'] = key_file
13581368
if cert_file is not None: kwargs['cert_file'] = cert_file
13591369

1360-
# If running Python 2.7.9+, disable SSL certificate validation
1361-
if (sys.version_info >= (2,7,9) and key_file is None and cert_file is None) and not verify:
1370+
if not verify:
13621371
kwargs['context'] = ssl._create_unverified_context()
13631372
return six.moves.http_client.HTTPSConnection(host, port, **kwargs)
13641373
raise ValueError("unsupported scheme: %s" % scheme)
@@ -1369,7 +1378,7 @@ def request(url, message, **kwargs):
13691378
head = {
13701379
"Content-Length": str(len(body)),
13711380
"Host": host,
1372-
"User-Agent": "splunk-sdk-python/1.6.11",
1381+
"User-Agent": "splunk-sdk-python/1.6.12",
13731382
"Accept": "*/*",
13741383
"Connection": "Close",
13751384
} # defaults

splunklib/modularinput/__init__.py

100755100644
File mode changed.

splunklib/modularinput/argument.py

100755100644
File mode changed.

splunklib/modularinput/event.py

100755100644
+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# under the License.
1414

1515
from __future__ import absolute_import
16+
from io import TextIOBase
17+
from splunklib.six import ensure_text
18+
1619
try:
1720
import xml.etree.cElementTree as ET
1821
except ImportError as ie:
@@ -104,5 +107,8 @@ def write_to(self, stream):
104107
if self.done:
105108
ET.SubElement(event, "done")
106109

107-
stream.write(ET.tostring(event))
110+
if isinstance(stream, TextIOBase):
111+
stream.write(ensure_text(ET.tostring(event)))
112+
else:
113+
stream.write(ET.tostring(event))
108114
stream.flush()

splunklib/modularinput/event_writer.py

100755100644
+17-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from __future__ import absolute_import
1616
import sys
1717

18+
from io import TextIOWrapper, TextIOBase
19+
from splunklib.six import ensure_text
1820
from .event import ET
1921

2022
try:
@@ -24,7 +26,6 @@
2426

2527
class EventWriter(object):
2628
"""``EventWriter`` writes events and error messages to Splunk from a modular input.
27-
2829
Its two important methods are ``writeEvent``, which takes an ``Event`` object,
2930
and ``log``, which takes a severity and an error message.
3031
"""
@@ -42,8 +43,15 @@ def __init__(self, output = sys.stdout, error = sys.stderr):
4243
:param output: Where to write the output; defaults to sys.stdout.
4344
:param error: Where to write any errors; defaults to sys.stderr.
4445
"""
45-
self._out = output
46-
self._err = error
46+
if isinstance(output, TextIOBase):
47+
self._out = output
48+
else:
49+
self._out = TextIOWrapper(output)
50+
51+
if isinstance(error, TextIOBase):
52+
self._err = error
53+
else:
54+
self._err = TextIOWrapper(error)
4755

4856
# has the opening <stream> tag been written yet?
4957
self.header_written = False
@@ -55,20 +63,18 @@ def write_event(self, event):
5563
"""
5664

5765
if not self.header_written:
58-
self._out.write(b"<stream>")
66+
self._out.write(ensure_text("<stream>"))
5967
self.header_written = True
6068

6169
event.write_to(self._out)
6270

6371
def log(self, severity, message):
6472
"""Logs messages about the state of this modular input to Splunk.
6573
These messages will show up in Splunk's internal logs.
66-
6774
:param severity: ``string``, severity of message, see severities defined as class constants.
6875
:param message: ``string``, message to log.
6976
"""
70-
71-
self._err.write(("%s %s\n" % (severity, message)).encode('utf-8'))
77+
self._err.write(ensure_text("%s %s\n" % (severity, message)))
7278
self._err.flush()
7379

7480
def write_xml_document(self, document):
@@ -77,9 +83,11 @@ def write_xml_document(self, document):
7783
7884
:param document: An ``ElementTree`` object.
7985
"""
80-
self._out.write(ET.tostring(document))
86+
data = ET.tostring(document)
87+
self._out.write(ensure_text(data))
8188
self._out.flush()
8289

8390
def close(self):
8491
"""Write the closing </stream> tag to make this XML well formed."""
85-
self._out.write(b"</stream>")
92+
self._out.write(ensure_text("</stream>"))
93+
self._out.flush()

splunklib/modularinput/input_definition.py

100755100644
File mode changed.

splunklib/modularinput/scheme.py

100755100644
File mode changed.

splunklib/modularinput/script.py

100755100644
File mode changed.

splunklib/modularinput/utils.py

100755100644
File mode changed.

splunklib/modularinput/validation_definition.py

100755100644
File mode changed.

0 commit comments

Comments
 (0)