Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
326913a
- adjusted the coverage exceptions to skip a few more defensive asser…
reactive-firewall Jul 22, 2017
dc21d5b
- added fix for file io cross-python regression bug
reactive-firewall Jul 23, 2017
7c71390
- added stickler CI configuration file as part of #32
reactive-firewall Jul 23, 2017
789f212
Merge branch 'master' into encryption-feature-#20 as part of #35
reactive-firewall Jul 23, 2017
4b4d042
Merge branch 'encryption-feature-#20'
reactive-firewall Jul 23, 2017
114156d
- adjusted the coverage exceptions to skip a few more defensive asser…
reactive-firewall Jul 22, 2017
68ecb3e
- added fix for file io cross-python regression bug
reactive-firewall Jul 23, 2017
a5ce3f5
added config fopr yaml lint
reactive-firewall Jul 23, 2017
0fa491a
debugging yamllint more for pr #36
reactive-firewall Jul 23, 2017
6489f1b
debugging yamllint more for pr #36
reactive-firewall Jul 23, 2017
58ef2a6
debugging stickler CI config for pr #36
reactive-firewall Jul 23, 2017
c41f660
debugging stickler CI config for pr #36
reactive-firewall Jul 23, 2017
f8829cb
more style debugging stickler CI config for pr #36
reactive-firewall Jul 24, 2017
a61eb1f
more style debugging stickler CI config for pr #36
reactive-firewall Jul 24, 2017
bcb25f1
revert .stickler.yml
reactive-firewall Jul 24, 2017
a164d0d
added test circleci
reactive-firewall Jul 24, 2017
0272d83
fix for style pep8
reactive-firewall Jul 24, 2017
8e3e0af
Merge branch 'master' into config-feature-#28
reactive-firewall Jul 24, 2017
e595e14
fix for style lint to ignore otherwise working yaml
reactive-firewall Jul 24, 2017
87af121
Merge branch 'config-feature-#28' of https://github.com/reactive-fire…
reactive-firewall Jul 24, 2017
5f5320f
Merge branch 'config-feature-#28' for PR #37
reactive-firewall Jul 24, 2017
74f76dd
part of #28 config start point
reactive-firewall Jul 29, 2017
dffb309
awsome bug fix, not really, part of #28
reactive-firewall Jul 31, 2017
89b0d63
Fix for #38 bump version to 0.2.7
reactive-firewall Jul 31, 2017
9e0b3e4
fix for regression on code-style in config.py as part of PR #39 and #32
reactive-firewall Aug 2, 2017
8d24a56
style fixes as part of #32
reactive-firewall Aug 2, 2017
aae3f4d
added file name redaction functions
reactive-firewall Aug 2, 2017
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
21 changes: 21 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
jobs:
build:
working_directory: ~/PiAP-python-tools
docker:
- image: circleci/python:3.6.1
environment:
CI: cicleci
POSTGRES_DB: circle_test
steps:
- checkout
- run:
command: |
make clean
- run:
command: |
make test
- run:
command: |
make clean
destination: tr1
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ exclude_lines =
pragma: no cover

except Exception
except BaseException:
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
raise ImportError
except unittest.SkipTest as skiperr
except unittest.SkipTest
except IOError
except OSError

Expand Down
10 changes: 10 additions & 0 deletions .stickler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
linters:
shellcheck:
shell: bash
flake8:
max-line-length: 100
max-complexity: 10
ignore: 'W191,W391'
exclude: ['.git', '__pycache__', 'docs', '.tox', 'build']
files:
ignore: ['*/*.pyc', '*.pyc', '*~', '.git', '__pycache__']
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test-tox: cleanup
$(QUIET)$(ECHO) "$@: Done."

test-style: cleanup
$(QUIET)flake8 --ignore=W191,W391 --max-line-length=100 --verbose --count
$(QUIET)flake8 --ignore=W191,W391 --max-line-length=100 --verbose --count --config=.flake8.ini
$(QUIET)$(ECHO) "$@: Done."

cleanup:
Expand Down Expand Up @@ -133,6 +133,9 @@ cleanup:
$(QUIET)rm -f ./the_test_file*.json 2>/dev/null || true
$(QUIET)rm -f ./the_test_file*.yml 2>/dev/null || true
$(QUIET)rm -f ./the_test_file*.yaml 2>/dev/null || true
$(QUIET)rm -f ./the_test_file*.enc 2>/dev/null || true
$(QUIET)rm -f ./.weak_test_key_* || true
$(QUIET)rm -f ./test.secret || true
$(QUIET)rm -f ./the_test_url_file*.txt 2>/dev/null || true
$(QUIET)rm -f /tmp/.beta_PiAP_weak_key 2>/dev/null || true

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
master_doc = 'index'

# General information about the project.
project = u'restart_service_handler'
project = u'Pocket_PiAP_Python_tools'
copyright = u'2017, reactive-firewall'

# The version info for the project you're documenting, acts as replacement for
Expand All @@ -51,7 +51,7 @@
# The short X.Y version.
version = 'v0.2'
# The full version, including alpha/beta/rc tags.
release = 'v0.2.4'
release = 'v0.2.7'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion piaplib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = """0.2.5"""
__version__ = """0.2.7"""

try:
import sys
Expand Down
47 changes: 47 additions & 0 deletions piaplib/keyring/clearify.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
except Exception:
import pku.remediation as remediation

try:
from remediation import PiAPError as PiAPError
except Exception:
try:
from piaplib.pku.remediation import PiAPError as PiAPError
except Exception:
raise ImportError("Error Importing PiAPError")

try:
from ..pku import utils as utils
Expand Down Expand Up @@ -242,6 +249,46 @@ def unpackFromRest(ciphertext=None, keyStore=None):
raise NotImplementedError("No Implemented Backend - BUG")


@remediation.error_handling
def unpackFromFile(somefile, keyStore=None):
"""Reads the raw encrypted file and decrypts it."""
read_data = None
try:
someFilePath = utils.addExtension(somefile, str('enc'))
with utils.open_func(someFilePath, mode=u'r', encoding=u'utf-8') as enc_data_file:
read_enc_data = enc_data_file.read()
read_data = unpackFromRest(read_enc_data, keyStore)
except Exception as clearerr:
read_data = None
baton = PiAPError(clearerr, str("Failed to load or deycrypt file."))
clearerr = None
del clearerr
raise baton
return read_data


@remediation.error_handling
def packToFile(somefile, data, keyStore=None):
"""Writes the raw encrypted file."""
if data is None:
return False
if somefile is None:
return False
did_write = False
try:
someFilePath = utils.literal_code(utils.addExtension(str(somefile), str("enc")))
if someFilePath is not None:
encData = packForRest(data, keyStore)
with utils.open_func(file=someFilePath, mode=u'wb+') as enc_data_file:
utils.write_func(enc_data_file, utils.literal_str(encData).encode("utf-8"))
del(encData)
did_write = True
except Exception as clearerr:
raise remediation.PiAPError(clearerr, str("Failed to write or encrypt file."))
did_write = False
return did_write


WEAK_ACTIONS = {u'pack': packForRest, u'unpack': unpackFromRest}
""" The Pocket bag Unit actions.
pack - save/pack/pickle functions.
Expand Down
46 changes: 25 additions & 21 deletions piaplib/lint/clients_check_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ def get_client_list(lan_interface=None):
return theResult


@remediation.error_handling
def get_client_status(client=None, use_html=False, lan_interface=None):
@remediation.error_handling # noqa C901
def get_client_status(client=None, use_html=False, lan_interface=None): # noqa C901
"""Generate the status"""
theResult = None
try:
Expand Down Expand Up @@ -456,6 +456,23 @@ def get_client_ip(client=None, use_html=False, lan_interface=None):
return theResult


@remediation.error_handling
def showAllClients(verbose_mode, output_html, client_interface):
"""Used by main to show all. Not intended to be called directly"""
if output_html:
print(
"<table class=\"table table-striped\">" +
"<thead><th>Client</th><th>MAC</th><th>IP</th><th>Status</th></thead><tbody>"
)
client_list = get_client_list(client_interface)
if client_list is None:
client_list = []
for client_name in client_list:
print(show_client(str(client_name), verbose_mode, output_html, client_interface))
if output_html:
print("</tbody></table>")


@remediation.bug_handling
def main(argv=None):
"""The main function."""
Expand All @@ -470,30 +487,17 @@ def main(argv=None):
if args.interface is not None:
client_interface = args.interface
if args.show_all is True:
if output_html:
print(str(
u'<table class=\"table table-striped\">' +
u'<thead><th>Client</th><th>MAC</th><th>IP</th><th>Status</th></thead><tbody>'
))
showAllClients(verbose, output_html, client_interface)
elif args.list is True:
client_list = get_client_list(client_interface)
if client_list is None:
client_list = []
for client_name in client_list:
print(show_client(str(client_name), verbose, output_html, client_interface))
if output_html:
print("</tbody></table>")
print(str(client_name))
else:
if args.list is True:
client_list = get_client_list(client_interface)
if client_list is None:
client_list = []
for client_name in client_list:
print(str(client_name))
else:
ip = args.ip
print(show_client(ip, verbose, output_html, client_interface))
return 0
return 0
ip = args.ip
print(show_client(ip, verbose, output_html, client_interface))
return 0
except Exception as main_err:
print(str("client_check_status: REALLY BAD ERROR: ACTION will not be compleated! ABORT!"))
print(str(main_err))
Expand Down
30 changes: 17 additions & 13 deletions piaplib/lint/html_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,16 @@ def gen_html_ul(somelist=None, id=None, name=None):
items = [gen_html_li(x) for x in somelist]
theresult = None
if id is not None and has_special_html_chars(id) is not True:
if name is not None and has_special_html_chars(name) is not True:
theresult = str(u'<ul name=\"{}\" id=\"{}\">').format(str(name), str(id))
for item in items:
theresult = str(theresult + item)
else:
theresult = str(u'<ul id=\"{}\">').format(str(id))
for item in items:
theresult = str(theresult + item)
if name is None or has_special_html_chars(name) is True:
name = utils.literal_str(id)
theresult = str(u'<ul name=\"{}\" id=\"{}\">').format(
utils.literal_str(name),
utils.literal_str(id)
)
for item in items:
theresult = str(theresult + item)
elif name is not None and has_special_html_chars(name) is not True:
theresult = str(u'<ul name=\"{}\">').format(str(name))
theresult = str(u'<ul name=\"{}\">').format(utils.literal_str(name))
for item in items:
theresult = str(theresult + item)
else:
Expand All @@ -184,13 +184,17 @@ def gen_html_li(item=None, id=None, name=None):
"""
if id is not None and has_special_html_chars(id) is not True:
if name is not None and has_special_html_chars(name) is not True:
return str(u'<li name=\"{}\" id=\"{}\">{}</li>').format(str(name), str(id), str(item))
return str(u'<li name=\"{}\" id=\"{}\">{}</li>').format(
utils.literal_str(name),
utils.literal_str(id),
utils.literal_str(item)
)
else:
return str(u'<li id=\"{}\">{}</li>').format(id, str(item))
return str(u'<li id=\"{}\">{}</li>').format(id, utils.literal_str(item))
elif name is not None and has_special_html_chars(name) is not True:
return str(u'<li name=\"{}\">{}</li>').format(id, str(item))
return str(u'<li name=\"{}\">{}</li>').format(id, utils.literal_str(item))
else:
return str(u'<li>{}</li>').format(str(item))
return str(u'<li>{}</li>').format(utils.literal_str(item))


def gen_html_label(content=None, role=HTML_LABEL_ROLES[0], id=None, name=None):
Expand Down
41 changes: 23 additions & 18 deletions piaplib/lint/iface_check_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parseargs(arguments=None):
)
parser.add_argument(
'-i', '--interface',
default=interfaces.INTERFACE_CHOICES[1], choices=interfaces.INTERFACE_CHOICES,
default=interfaces.INTERFACE_CHOICES[0], choices=interfaces.INTERFACE_CHOICES,
help='The interface to show.'
)
parser.add_argument(
Expand Down Expand Up @@ -213,7 +213,7 @@ def get_iface_list():
if x in interfaces.INTERFACE_CHOICES:
theResult.append(x)
theResult = utils.compactList([x for x in theResult])
"""while '[aehltw]{3}[n]?[0-9]+' would probably work well here, best to whitelist. """
"""while regex would probably work well here, best to whitelist. """
return theResult


Expand Down Expand Up @@ -305,34 +305,39 @@ def get_iface_ip_list(iface=u'lo', use_html=False):
return theResult


@remediation.error_handling
def showAlliFace(verbose_mode, output_html):
"""Used by main to show all. Not intended to be called directly"""
if output_html:
print(
"<table class=\"table table-striped\">" +
"<thead><th>Interface</th><th>MAC</th><th>IP</th><th>State</th></thead><tbody>"
)
for iface_name in get_iface_list():
print(show_iface(iface_name, verbose_mode, output_html))
if output_html:
print("</tbody></table>")


def main(argv=None):
"""The main function."""
args = parseargs(argv)
try:
verbose = False
output_html = False
if args.verbose_mode is not None:
verbose = args.verbose_mode
if args.output_html is not None:
output_html = args.output_html
if args.show_all is True:
if output_html:
print(
"<table class=\"table table-striped\">" +
"<thead><th>Interface</th><th>MAC</th><th>IP</th><th>State</th></thead><tbody>"
)
showAlliFace(verbose, output_html)
elif args.list is True:
for iface_name in get_iface_list():
print(show_iface(iface_name, verbose, output_html))
if output_html:
print("</tbody></table>")
print(str(iface_name))
else:
if args.list is True:
for iface_name in get_iface_list():
print(str(iface_name))
else:
interface = args.interface
print(show_iface(interface, verbose, output_html))
return 0
return 0
interface = args.interface
print(show_iface(interface, verbose, output_html))
return 0
except Exception as main_err:
logs.log(
str("iface_check_status: REALLY BAD ERROR: ACTION will not be compleated! ABORT!"),
Expand Down
4 changes: 2 additions & 2 deletions piaplib/lint/users_check_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def get_user_list():
return theResult


def get_user_status(user_name=None, use_html=False):
def get_user_status(user_name=None, use_html=False): # noqa C901
"""Generate the status"""
theResult = None
try:
Expand Down Expand Up @@ -560,7 +560,7 @@ def get_user_ip(user=None, use_html=False):
return theResult


def main(argv=None):
def main(argv=None): # noqa C901
"""The main function."""
args = parseargs(argv)
try:
Expand Down
Loading