Skip to content
Merged
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
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] missing document start "---" (document-start)

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
10 changes: 10 additions & 0 deletions .stickler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
linters:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] missing document start "---" (document-start)

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__']
135 changes: 134 additions & 1 deletion piaplib/pku/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
try:
import utils as utils
except Exception:
raise ImportError("Error Importing config")
raise ImportError("Error Importing utils for config")


try:
Expand Down Expand Up @@ -166,6 +166,139 @@ def writeYamlFile(somefile, data):
return did_write


# branch mark start


try:
import configparser as configparser
except Exception:
try:
import ConfigParser as configparser
except Exception:
raise ImportError("Error Importing ConfigParser utils for config")


@remediation.error_handling
def getDefaultMainConfigFile():
import os
default_config = dict({
'PiAP-logging': dict({
'mode': str("stdout"),
'dir': str("/var/log"),
'keyfile': repr(None),
'encryptlogs': repr(False)
}),
'PiAP-logging-outputs': dict({
'splunk': repr(False),
'syslog': repr(False),
'file': repr(False),
'stdout': repr(True)
}),
'PiAP-rand': dict({
'keyfile': repr(None),
'entropy_function': repr(os.urandom),
'char_upper': repr(99),
'char_lower': repr(1),
'char_range': repr(tuple(('${PiAP-rand:char_lower}', '${PiAP-rand:char_upper}'))),
'passphrase_length': repr(16),
'passphrase_encoding': str("utf-8"),
'SSID_length': repr(20)
}),
'PiAP-network-lan': dict({
'keyfile': repr(None),
'network_ipv4_on': repr(True),
'network_ipv4': repr(tuple(("10.0.40", 0))),
'ipv4_dhcp_reserved': repr({}),
'network_ipv6_on': repr(False),
'network_ipv6': repr(None),
'ipv6_dhcp_reserved': repr(None)
})
})
return default_config


@remediation.error_handling
def writeDefaultMainConfigFile(confFile='/var/opt/PiAP/PiAP.conf'):
try:
config = configparser.ConfigParser()
default_config = getDefaultMainConfigFile()
# config.add_section('PiAP-logging')
# config['PIAP-logging'] = {}
# logging['timefmt'] = str("""%a %b %d %H:%M:%S %Z %Y""")
for someSection in default_config.keys():
config.add_section(someSection)
for someOption in default_config[someSection].keys():
config[someSection][someOption] = dict(default_config[someSection])[someOption]
with utils.open_func(confFile, 'w') as configfile:
config.write(configfile)
except Exception as err:
print(str(err))
print(str(type(err)))
print(str((err.args)))
return False
return True


@remediation.error_handling
def writeMainConfigFile(confFile='/var/opt/PiAP/PiAP.conf', config_data=None):
try:
config = configparser.ConfigParser()
default_config = loadMainConfigFile(confFile)
# config.add_section('PiAP-logging')
# config['PIAP-logging'] = {}
# logging['timefmt'] = str("""%a %b %d %H:%M:%S %Z %Y""")
for someSection in config_data.keys():
config.add_section(someSection)
for someOption in config_data[someSection].keys():
config[someSection][someOption] = dict(config_data[someSection])[someOption]
for someSection in default_config.keys():
if not config.has_section(someSection):
config.add_section(someSection)
for someOption in default_config[someSection].keys():
if not config.has_option(someSection, someOption):
config[someSection][someOption] = dict(default_config[someSection])[someOption]
with utils.open_func(confFile, 'w') as configfile:
config.write(configfile)
except Exception as err:
print(str(err))
print(str(type(err)))
print(str((err.args)))
return False
return True


@remediation.error_handling
def loadMainConfigFile(confFile='/var/opt/PiAP/PiAP.conf'):
try:
config = configparser.ConfigParser()
# config.add_section('PiAP-logging')
# config['PIAP-logging'] = {}
# logging['timefmt'] = str("""%a %b %d %H:%M:%S %Z %Y""")
result_config = getDefaultMainConfigFile()
with utils.open_func(confFile, 'r') as configfile:
config.read(configfile)
for someSection in config.sections():
if str(someSection) in result_config.keys():
for someOption in config.options(someSection):
if str(someOption) in result_config[someSection].keys():
continue
else:
result_config[someSection][someOption] = config[someSection][someOption]
else:
result_config[someSection] = dict({})
for someOption in config.options(someSection):
result_config[someSection][someOption] = config[someSection][someOption]
except Exception as err:
print(str(err))
print(str(type(err)))
print(str((err.args)))
return getDefaultMainConfigFile()
return result_config


# branch mark end


if __name__ in u'__main__':
raise NotImplementedError("ERROR: Can not run config as main. Yet?")

6 changes: 0 additions & 6 deletions tests/test_enc.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,11 @@ def test_case_clearify_read_write(self):
str("./.weak_test_key_{}").format(rand.randInt(1, 10, 99))
)
self.assertIsNotNone(theteststore)
if (theteststore is not None):
print(" ... Wrote key file ... ")
test_write = clearify.packToFile(
sometestfile,
str("This is a test Message"),
theteststore
)
if (test_write is True):
print(" ... Wrote enc file ... ")
self.assertTrue(test_write)
if (test_write is True):
test_read = clearify.unpackFromFile(sometestfile, theteststore)
Expand All @@ -361,8 +357,6 @@ def test_case_clearify_read_write(self):
theResult = False
else:
raise unittest.SkipTest("BETA. Experemental feature not ready yet.")
else:
theResult = False
except Exception as err:
print(str(""))
print(str(type(err)))
Expand Down