Skip to content

Commit

Permalink
Fix Issue #35
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhemmarchand committed Mar 11, 2021
1 parent b64a74e commit 79ecf36
Show file tree
Hide file tree
Showing 566 changed files with 2,255 additions and 137,177 deletions.
2 changes: 1 addition & 1 deletion TA-ms-teams-alert-action/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": {
"group": null,
"name": "TA-ms-teams-alert-action",
"version": "1.0.18"
"version": "1.0.19"
},
"author": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Python library for Splunk."""

__version_info__ = (1, 6, 0)
from __future__ import absolute_import
from splunklib.six.moves import map
__version_info__ = (1, 6, 15)
__version__ = ".".join(map(str, __version_info__))

2 changes: 1 addition & 1 deletion TA-ms-teams-alert-action/bin/ta_ms_teams_alert_action/aob_py2/splunklib/__init__.py
100755 → 100644
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, 6)
__version_info__ = (1, 6, 15)
__version__ = ".".join(map(str, __version_info__))
25 changes: 21 additions & 4 deletions TA-ms-teams-alert-action/bin/ta_ms_teams_alert_action/aob_py2/splunklib/binding.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def _parse_cookies(cookie_str, dictionary):
then updates the the dictionary with any key-value pairs found.
**Example**::
dictionary = {}
_parse_cookies('my=value', dictionary)
# Now the following is True
Expand Down Expand Up @@ -449,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 @@ -480,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 @@ -520,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 @@ -717,7 +724,12 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, *
:type headers: ``list`` of 2-tuples.
:param query: All other keyword arguments, which are used as query
parameters.
:type query: ``string``
:param body: Parameters to be used in the post body. If specified,
any parameters in the query will be applied to the URL instead of
the body. If a dict is supplied, the key-value pairs will be form
encoded. If a string is supplied, the body will be passed through
in the request unchanged.
:type body: ``dict`` or ``str``
:return: The response from the server.
:rtype: ``dict`` with keys ``body``, ``headers``, ``reason``,
and ``status``
Expand Down Expand Up @@ -862,6 +874,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 @@ -1212,6 +1228,8 @@ def post(self, url, headers=None, **kwargs):
headers.append(("Content-Type", "application/x-www-form-urlencoded"))

body = kwargs.pop('body')
if isinstance(body, dict):
body = _encode(**body).encode('utf-8')
if len(kwargs) > 0:
url = url + UrlEncoded('?' + _encode(**kwargs), skip_encode=True)
else:
Expand Down Expand Up @@ -1356,8 +1374,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 @@ -1368,7 +1385,7 @@ def request(url, message, **kwargs):
head = {
"Content-Length": str(len(body)),
"Host": host,
"User-Agent": "splunk-sdk-python/1.6.6",
"User-Agent": "splunk-sdk-python/1.6.15",
"Accept": "*/*",
"Connection": "Close",
} # defaults
Expand Down
17 changes: 12 additions & 5 deletions TA-ms-teams-alert-action/bin/ta_ms_teams_alert_action/aob_py2/splunklib/client.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,13 @@ def info(self):
response = self.get("/services/server/info")
return _filter_content(_load_atom(response, MATCH_ENTRY_CONTENT))

def input(self, path, kind=None):
"""Retrieves an input by path, and optionally kind.
:return: A :class:`Input` object.
"""
return Input(self, path, kind=kind).refresh()

@property
def inputs(self):
"""Returns the collection of inputs configured on this Splunk instance.
Expand Down Expand Up @@ -1200,7 +1207,7 @@ def __getitem__(self, key):
:raises ValueError: Raised if no namespace is specified and *key*
does not refer to a unique name.
*Example*::
**Example**::
s = client.connect(...)
saved_searches = s.saved_searches
Expand Down Expand Up @@ -1636,9 +1643,9 @@ def get(self, name="", owner=None, app=None, sharing=None, **query):
:rtype: ``dict`` with keys ``body``, ``headers``, ``reason``,
and ``status``
Example:
**Example**::
import splunklib.client
import splunklib.client
s = client.service(...)
saved_searches = s.saved_searches
saved_searches.get("my/saved/search") == \\
Expand Down Expand Up @@ -1865,7 +1872,7 @@ def delete(self, username, realm=None):
name = UrlEncoded(realm, encode_slash=True) + ":" + UrlEncoded(username, encode_slash=True)

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

Expand Down Expand Up @@ -3569,7 +3576,7 @@ class KVStoreCollection(Entity):
def data(self):
"""Returns data object for this Collection.
:rtype: :class:`KVStoreData`
:rtype: :class:`KVStoreCollectionData`
"""
return KVStoreCollectionData(self)

Expand Down
18 changes: 13 additions & 5 deletions ...action/solnlib/packages/splunklib/data.py → ..._alert_action/aob_py2/splunklib/data 2.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
format, which is the format used by most of the REST API.
"""

from __future__ import absolute_import
import sys
from xml.etree.ElementTree import XML
from splunklib import six

__all__ = ["load"]

Expand Down Expand Up @@ -74,6 +77,11 @@ def load(text, match=None):
'namespaces': [],
'names': {}
}

# Convert to unicode encoding in only python 2 for xml parser
if(sys.version_info < (3, 0, 0) and isinstance(text, unicode)):
text = text.encode('utf-8')

root = XML(text)
items = [root] if match is None else root.findall(match)
count = len(items)
Expand All @@ -88,7 +96,7 @@ def load(text, match=None):
def load_attrs(element):
if not hasattrs(element): return None
attrs = record()
for key, value in element.attrib.iteritems():
for key, value in six.iteritems(element.attrib):
attrs[key] = value
return attrs

Expand All @@ -110,12 +118,12 @@ def load_elem(element, nametable=None):
if attrs is None: return name, value
if value is None: return name, attrs
# If value is simple, merge into attrs dict using special key
if isinstance(value, str):
if isinstance(value, six.string_types):
attrs["$text"] = value
return name, attrs
# Both attrs & value are complex, so merge the two dicts, resolving collisions.
collision_keys = []
for key, val in attrs.iteritems():
for key, val in six.iteritems(attrs):
if key in value and key in collision_keys:
value[key].append(val)
elif key in value and key not in collision_keys:
Expand Down Expand Up @@ -169,7 +177,7 @@ def load_value(element, nametable=None):
for child in children:
name, item = load_elem(child, nametable)
# If we have seen this name before, promote the value to a list
if value.has_key(name):
if name in value:
current = value[name]
if not isinstance(current, list):
value[name] = [current]
Expand Down Expand Up @@ -227,7 +235,7 @@ def __getitem__(self, key):
return dict.__getitem__(self, key)
key += self.sep
result = record()
for k,v in self.iteritems():
for k,v in six.iteritems(self):
if not k.startswith(key):
continue
suffix = k[len(key):]
Expand Down
Empty file.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import absolute_import
try:
import xml.etree.ElementTree as ET
except ImportError:
Expand Down Expand Up @@ -53,9 +54,9 @@ def __init__(self, name, description=None, validation=None,
:param name: ``string``, identifier for this argument in Splunk.
:param description: ``string``, human-readable description of the argument.
:param validation: ``string`` specifying how the argument should be validated, if using internal validation.
If using external validation, this will be ignored.
If using external validation, this will be ignored.
:param data_type: ``string``, data type of this field; use the class constants.
"data_type_boolean", "data_type_number", or "data_type_string".
"data_type_boolean", "data_type_number", or "data_type_string".
:param required_on_edit: ``Boolean``, whether this arg is required when editing an existing modular input of this kind.
:param required_on_create: ``Boolean``, whether this arg is required when creating a modular input of this kind.
:param title: ``String``, a human-readable title for the argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def __init__(self, name, description=None, validation=None,
:param name: ``string``, identifier for this argument in Splunk.
:param description: ``string``, human-readable description of the argument.
:param validation: ``string`` specifying how the argument should be validated, if using internal validation.
If using external validation, this will be ignored.
If using external validation, this will be ignored.
:param data_type: ``string``, data type of this field; use the class constants.
"data_type_boolean", "data_type_number", or "data_type_string".
"data_type_boolean", "data_type_number", or "data_type_string".
:param required_on_edit: ``Boolean``, whether this arg is required when editing an existing modular input of this kind.
:param required_on_create: ``Boolean``, whether this arg is required when creating a modular input of this kind.
:param title: ``String``, a human-readable title for the argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# License for the specific language governing permissions and limitations
# 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 @@ -103,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()
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()
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import absolute_import
import sys

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

try:
from cStringIO import StringIO
from splunklib.six.moves import cStringIO as StringIO
except ImportError:
from StringIO import StringIO
from splunklib.six import StringIO

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 Down Expand Up @@ -76,9 +78,10 @@ def write_xml_document(self, document):
:param document: An ``ElementTree`` object.
"""
self._out.write(ET.tostring(document))
self._out.write(ensure_str(ET.tostring(document)))
self._out.flush()

def close(self):
"""Write the closing </stream> tag to make this XML well formed."""
self._out.write("</stream>")
self._out.write("</stream>")
self._out.flush()
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_str
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 Down Expand Up @@ -55,7 +56,7 @@ def write_event(self, event):
"""

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

event.write_to(self._out)
Expand All @@ -68,7 +69,7 @@ def log(self, severity, message):
:param message: ``string``, message to log.
"""

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

def write_xml_document(self, document):
Expand All @@ -77,9 +78,10 @@ def write_xml_document(self, document):
:param document: An ``ElementTree`` object.
"""
self._out.write(ET.tostring(document))
self._out.write(ensure_str(ET.tostring(document)))
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("</stream>")
self._out.flush()
Loading

0 comments on commit 79ecf36

Please sign in to comment.