Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/style-checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Python Code Style Check

on: [push]

jobs:
style-check:
runs-on: ubuntu-latest
container: python:latest
steps:
- uses: actions/checkout@v2
- run: |
pip install black
black --check --exclude "deps" ./
name: Install and run black style checker
68 changes: 40 additions & 28 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
Expand All @@ -17,19 +16,19 @@
import sys
import sphinx_rtd_theme

sys.path.insert(0, os.path.abspath('../pytest_splunk_addon'))
sys.path.insert(0, os.path.abspath("../pytest_splunk_addon"))


# -- Project information -----------------------------------------------------

project = u'pytest-splunk-addon'
copyright = u'2020, Splunk, Inc.'
author = u'Splunk, Inc.'
project = u"pytest-splunk-addon"
copyright = u"2020, Splunk, Inc."
author = u"Splunk, Inc."

# The short X.Y version
version = u''
version = u""
# The full version, including alpha/beta/rc tags
release = u''
release = u""


# -- General configuration ---------------------------------------------------
Expand All @@ -38,12 +37,12 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx_panels'
"sphinx.ext.autodoc",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx_panels",
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -54,10 +53,10 @@
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -72,15 +71,15 @@
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -108,7 +107,7 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'pytest-splunk-addondoc'
htmlhelp_basename = "pytest-splunk-addondoc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -117,15 +116,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -135,8 +131,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pytest-splunk-addon.tex', u'pytest-splunk-addon Documentation',
u'Splunk, Inc.', 'manual'),
(
master_doc,
"pytest-splunk-addon.tex",
u"pytest-splunk-addon Documentation",
u"Splunk, Inc.",
"manual",
),
]


Expand All @@ -145,8 +146,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pytest-splunk-addon', u'pytest-splunk-addon Documentation',
[author], 1)
(
master_doc,
"pytest-splunk-addon",
u"pytest-splunk-addon Documentation",
[author],
1,
)
]


Expand All @@ -156,9 +162,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pytest-splunk-addon', u'pytest-splunk-addon Documentation',
author, 'pytest-splunk-addon', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"pytest-splunk-addon",
u"pytest-splunk-addon Documentation",
author,
"pytest-splunk-addon",
"One line description of project.",
"Miscellaneous",
),
]


Expand Down
1 change: 0 additions & 1 deletion pytest_splunk_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
__author__ = """Splunk Inc."""
__email__ = "[email protected]"
__version__ = "0.0.0"

1 change: 1 addition & 0 deletions pytest_splunk_addon/helmut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
@since: 2011-11-23
"""
from . import log

log.setup_logger(debug=True)
45 changes: 25 additions & 20 deletions pytest_splunk_addon/helmut/connector/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import time
import six


class RESTConnector(Connector):
"""
This represents workaround to access REST thru HTTP client library httplib2
Expand Down Expand Up @@ -45,26 +46,30 @@ class RESTConnector(Connector):

def __init__(self, splunk, username=None, password=None, app=None, owner=None):
"""
Creates a new REST connector.
Creates a new REST connector.

The connector will logged in when created with default values
The connector will logged in when created with default values

@param splunk: The Splunk instance
@type splunk: L{..splunk.Splunk}
@param username: The username to use. If None (default)
L{Connector.DEFAULT_USERNAME} is used.
@type username: str
@param password: The password to use. If None (default)
L{Connector.DEFAULT_PASSWORD} is used.
@type password: str
@param app: The app to use.This will construct namespace <ownerr>:<app>
@type app: str
@param app: The owner to use.This will construct namespace <ownerr>:<app>
@type app: str
@param splunk: The Splunk instance
@type splunk: L{..splunk.Splunk}
@param username: The username to use. If None (default)
L{Connector.DEFAULT_USERNAME} is used.
@type username: str
@param password: The password to use. If None (default)
L{Connector.DEFAULT_PASSWORD} is used.
@type password: str
@param app: The app to use.This will construct namespace <ownerr>:<app>
@type app: str
@param app: The owner to use.This will construct namespace <ownerr>:<app>
@type app: str

"""
super(RESTConnector, self).__init__(
splunk, username=username, password=password, owner=owner, app=app,
splunk,
username=username,
password=password,
owner=owner,
app=app,
)
self.uri_base = splunk.uri_base()
self._timeout = 60
Expand Down Expand Up @@ -260,9 +265,9 @@ def _recreate_service(self):

def login(self):
"""
Logs the connector in.
Logs the connector in.

Just hits the auth endpoint and retreives and sets the sessionkey.
Just hits the auth endpoint and retreives and sets the sessionkey.

"""
body = urllib.parse.urlencode(
Expand All @@ -286,10 +291,10 @@ def login(self):

def _clone_existing_service(self):
"""
clones the existing service
clones the existing service

@return: The newly created service (httplib) http object
@rtype: http object
@return: The newly created service (httplib) http object
@rtype: http object
"""
http = httplib2.Http(
timeout=self._timeout,
Expand Down
5 changes: 3 additions & 2 deletions pytest_splunk_addon/helmut/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
_DATE_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
_FILE_NAME = "helmut.log"


def setup_logger(debug=False):
"""
Setups up the logging library

@param debug: If debug log messages are to be outputted
@type debug: bool
"""
logger = logging.getLogger('')
logger = logging.getLogger("")
handler = FileHandler(filename=_FILE_NAME, mode="w")
handler.setFormatter(HelmutFormatter(_LOG_FORMAT))
level = logging.INFO
if debug:
level = logging.DEBUG
logger.addHandler(handler)
logger.setLevel(level)
logger.debug('Logger: DEBUG logging is enabled')
logger.debug("Logger: DEBUG logging is enabled")


class HelmutFormatter(Formatter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class RESTConfsWrapper(Confs):
"""
The Confs subclass that is associated with the RESTConnector.
The Confs subclass that is associated with the RESTConnector.
"""

@property
Expand Down
12 changes: 8 additions & 4 deletions pytest_splunk_addon/helmut/manager/confs/rest/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

class RESTConfWrapper(Conf):
"""
The L{Conf} object corresponding to a Conf object in the Splunk REST API.
It holds a set of L{RESTStanza}s.
The L{Conf} object corresponding to a Conf object in the Splunk REST API.
It holds a set of L{RESTStanza}s.
"""

def __init__(self, rest_connector, rest_conf):
Expand All @@ -42,7 +42,9 @@ def __getitem__(self, stanza_name):
return stanza
raise StanzaNotFound(self.name, stanza_name)

def stanzas_list(self,):
def stanzas_list(
self,
):
stanza_list = []
url = PATH_PERFIX + self._raw_rest_conf.path + COUNT_OFFSET
req_args = {"output_mode": "json"}
Expand Down Expand Up @@ -164,7 +166,9 @@ def update(self, **values):
)
assert response["status"] == "200"

def refresh(self,):
def refresh(
self,
):
name = urllib.parse.quote_plus(self._name)
url = (
PATH_PERFIX + self.rest_conf.path + "{stanza_name}".format(stanza_name=name)
Expand Down
4 changes: 2 additions & 2 deletions pytest_splunk_addon/helmut/manager/confs/rest/stanza.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class RESTStanzaWrapper(Stanza):
"""
This class is the associated subclass of Stanza to the L{RESTConnector}.
This represents and wraps a Stanza object using the Splunk REST API.
This class is the associated subclass of Stanza to the L{RESTConnector}.
This represents and wraps a Stanza object using the Splunk REST API.
"""

def __init__(self, rest_conf, rest_stanza):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ def delete(self, **kwargs):
response, content = self.connector.make_request("DELETE", url)
assert response["status"] == "200"

def roll_hot_buckets(self,):
def roll_hot_buckets(
self,
):
name = self.encode_name()
url = PATH_PERFIX + name + ROLL_HOT_BUCKETS
req_args = {"output_mode": "json"}
Expand Down
16 changes: 8 additions & 8 deletions pytest_splunk_addon/helmut/manager/users/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

class User(ItemFromManager):
"""
A User is the means by which you login to Splunk via.
This class represents a User object and the different
functions you have to manipulate that User object.
A User is the means by which you login to Splunk via.
This class represents a User object and the different
functions you have to manipulate that User object.
"""

def __init__(self, username, connector):
"""
The constructor of the User class.
The constructor of the User class.

@param username: The username of the Splunk User
@type username: String
@param connector: The connector which talks to Splunk.
@type connector: _Connector
@param username: The username of the Splunk User
@type username: String
@param connector: The connector which talks to Splunk.
@type connector: _Connector
"""
self._name = username
super(User, self).__init__(connector)
Expand Down
Loading