Skip to content

Commit

Permalink
Release 1.6.12
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
Parul Upadhyaya committed Feb 13, 2020
2 parents b4d50ab + f46bb46 commit 51bd6b8
Show file tree
Hide file tree
Showing 20 changed files with 197 additions and 54 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ before_install:
env:
- SPLUNK_VERSION=7.0-sdk
- SPLUNK_VERSION=7.2-sdk
- SPLUNK_VERSION=8.0-sdk

language: python

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Splunk SDK for Python Changelog

## Version 1.6.12

### New features and APIs
* Added Bearer token support using Splunk Token in v7.3
* Made modinput text consistent

### Bug fixes
* Changed permissions from 755 to 644 for python files to pass appinspect checks
* Removed version check on ssl verify toggle

## Version 1.6.11

### Bug Fix
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# The Splunk Software Development Kit for Python

#### Version 1.6.11
#### Version 1.6.12

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/searchcommands_app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def run(self):
setup(
description='Custom Search Command examples',
name=os.path.basename(project_dir),
version='1.6.11',
version='1.6.12',
author='Splunk, Inc.',
author_email='devinfo@splunk.com',
url='http://github.com/splunk/splunk-sdk-python',
Expand Down
2 changes: 1 addition & 1 deletion splunklib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

from __future__ import absolute_import
from splunklib.six.moves import map
__version_info__ = (1, 6, 11)
__version_info__ = (1, 6, 12)
__version__ = ".".join(map(str, __version_info__))
15 changes: 12 additions & 3 deletions splunklib/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ class Context(object):
:type username: ``string``
:param password: The password for the Splunk account.
:type password: ``string``
:param splunkToken: Splunk authentication token
:type splunkToken: ``string``
:param headers: List of extra HTTP headers to send (optional).
:type headers: ``list`` of 2-tuples.
:param handler: The HTTP request handler (optional).
Expand Down Expand Up @@ -481,6 +483,7 @@ def __init__(self, handler=None, **kwargs):
self.username = kwargs.get("username", "")
self.password = kwargs.get("password", "")
self.basic = kwargs.get("basic", False)
self.bearerToken = kwargs.get("splunkToken", "")
self.autologin = kwargs.get("autologin", False)
self.additional_headers = kwargs.get("headers", [])

Expand Down Expand Up @@ -521,6 +524,9 @@ def _auth_headers(self):
elif self.basic and (self.username and self.password):
token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii')
return [("Authorization", token)]
elif self.bearerToken:
token = 'Bearer %s' % self.bearerToken
return [("Authorization", token)]
elif self.token is _NoAuthenticationToken:
return []
else:
Expand Down Expand Up @@ -863,6 +869,10 @@ def login(self):
# as credentials were passed in.
return

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

# If running Python 2.7.9+, disable SSL certificate validation
if (sys.version_info >= (2,7,9) and key_file is None and cert_file is None) and not verify:
if not verify:
kwargs['context'] = ssl._create_unverified_context()
return six.moves.http_client.HTTPSConnection(host, port, **kwargs)
raise ValueError("unsupported scheme: %s" % scheme)
Expand All @@ -1369,7 +1378,7 @@ def request(url, message, **kwargs):
head = {
"Content-Length": str(len(body)),
"Host": host,
"User-Agent": "splunk-sdk-python/1.6.11",
"User-Agent": "splunk-sdk-python/1.6.12",
"Accept": "*/*",
"Connection": "Close",
} # defaults
Expand Down
Empty file modified splunklib/modularinput/__init__.py
100755 → 100644
Empty file.
Empty file modified splunklib/modularinput/argument.py
100755 → 100644
Empty file.
8 changes: 7 additions & 1 deletion splunklib/modularinput/event.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# under the License.

from __future__ import absolute_import
from io import TextIOBase
from splunklib.six import ensure_text

try:
import xml.etree.cElementTree as ET
except ImportError as ie:
Expand Down Expand Up @@ -104,5 +107,8 @@ def write_to(self, stream):
if self.done:
ET.SubElement(event, "done")

stream.write(ET.tostring(event))
if isinstance(stream, TextIOBase):
stream.write(ensure_text(ET.tostring(event)))
else:
stream.write(ET.tostring(event))
stream.flush()
26 changes: 17 additions & 9 deletions splunklib/modularinput/event_writer.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from __future__ import absolute_import
import sys

from io import TextIOWrapper, TextIOBase
from splunklib.six import ensure_text
from .event import ET

try:
Expand All @@ -24,7 +26,6 @@

class EventWriter(object):
"""``EventWriter`` writes events and error messages to Splunk from a modular input.
Its two important methods are ``writeEvent``, which takes an ``Event`` object,
and ``log``, which takes a severity and an error message.
"""
Expand All @@ -42,8 +43,15 @@ def __init__(self, output = sys.stdout, error = sys.stderr):
:param output: Where to write the output; defaults to sys.stdout.
:param error: Where to write any errors; defaults to sys.stderr.
"""
self._out = output
self._err = error
if isinstance(output, TextIOBase):
self._out = output
else:
self._out = TextIOWrapper(output)

if isinstance(error, TextIOBase):
self._err = error
else:
self._err = TextIOWrapper(error)

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

if not self.header_written:
self._out.write(b"<stream>")
self._out.write(ensure_text("<stream>"))
self.header_written = True

event.write_to(self._out)

def log(self, severity, message):
"""Logs messages about the state of this modular input to Splunk.
These messages will show up in Splunk's internal logs.
:param severity: ``string``, severity of message, see severities defined as class constants.
:param message: ``string``, message to log.
"""

self._err.write(("%s %s\n" % (severity, message)).encode('utf-8'))
self._err.write(ensure_text("%s %s\n" % (severity, message)))
self._err.flush()

def write_xml_document(self, document):
Expand All @@ -77,9 +83,11 @@ def write_xml_document(self, document):
:param document: An ``ElementTree`` object.
"""
self._out.write(ET.tostring(document))
data = ET.tostring(document)
self._out.write(ensure_text(data))
self._out.flush()

def close(self):
"""Write the closing </stream> tag to make this XML well formed."""
self._out.write(b"</stream>")
self._out.write(ensure_text("</stream>"))
self._out.flush()
Empty file modified splunklib/modularinput/input_definition.py
100755 → 100644
Empty file.
Empty file modified splunklib/modularinput/scheme.py
100755 → 100644
Empty file.
Empty file modified splunklib/modularinput/script.py
100755 → 100644
Empty file.
Empty file modified splunklib/modularinput/utils.py
100755 → 100644
Empty file.
Empty file modified splunklib/modularinput/validation_definition.py
100755 → 100644
Empty file.

0 comments on commit 51bd6b8

Please sign in to comment.