Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
PEP8 Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Tervala authored and Justin Tervala committed May 15, 2017
1 parent 3372d9e commit 9ab258c
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 35 deletions.
1 change: 1 addition & 0 deletions core/arguments.py
Expand Up @@ -5,6 +5,7 @@

logger = logging.getLogger(__name__)


class Argument(object):
def __init__(self, key=None, value=None, format='str'):
"""Initializes a new Argument object.
Expand Down
1 change: 1 addition & 0 deletions core/controller.py
Expand Up @@ -27,6 +27,7 @@

logger = logging.getLogger(__name__)


def initialize_threading():
"""Initializes the threadpool.
"""
Expand Down
3 changes: 1 addition & 2 deletions core/filter.py
Expand Up @@ -77,7 +77,6 @@ def validate_args(self):
def __call__(self, output=None):
if self.validate_args():
try:
#result = getattr(module, "main")(args=self.args, value=output)
result = execute_filter(self.action, args=self.args, value=output)
callbacks.FilterSuccess.send(self)
return result
Expand Down Expand Up @@ -129,4 +128,4 @@ def get_children(self, ancestry):
Returns:
Empty dictionary {}
"""
return {}
return {}
3 changes: 2 additions & 1 deletion core/filters/length.py
Expand Up @@ -7,7 +7,8 @@ def execute(args, value):
""" Gets the length of the value provided to it.
Returns:
If the value is a collection, it calls len() on it. If it is an int, it simply returns the value passed in"""
If the value is a collection, it calls len() on it.
If it is an int, it simply returns the value passed in"""
try:
if isinstance(value, int):
return value
Expand Down
1 change: 0 additions & 1 deletion core/widgetsignals.py
Expand Up @@ -30,4 +30,3 @@ def get_widget_signal(app_name, widget_name):
if key not in _widget_signals:
_widget_signals[key] = signal(create_widget_signal_name(app_name, widget_name))
return _widget_signals[key]

2 changes: 1 addition & 1 deletion core/workflow.py
Expand Up @@ -278,7 +278,7 @@ def __get_child_step_generator(self, tiered_step_str):
child_name, child_start, child_next = params[0].lstrip('@'), params[1], params[2]
child_name = construct_workflow_name_key(self.playbook_name, child_name)
if (child_name in self.options.children
and type(self.options.children[child_name]).__name__ == 'Workflow'):
and type(self.options.children[child_name]).__name__ == 'Workflow'):
logger.debug('Executing child workflow {0} of workflow {1}'.format(child_name, self.ancestry))
callbacks.WorkflowExecutionStart.send(self.options.children[child_name])
child_step_generator = self.options.children[child_name].__steps(start=child_start)
Expand Down
28 changes: 15 additions & 13 deletions server/app.py
@@ -1,4 +1,5 @@
import os, logging
import os
import logging

from jinja2 import Environment, FileSystemLoader
from core import helpers
Expand All @@ -15,7 +16,7 @@


def read_and_indent(filename, indent):
indent = ' '*indent
indent = ' ' * indent
with open(filename, 'r') as file_open:
return ['{0}{1}'.format(indent, line) for line in file_open]

Expand Down Expand Up @@ -47,23 +48,24 @@ def create_app():
_app.jinja_loader = FileSystemLoader(['server/templates'])

_app.config.update(
# CHANGE SECRET KEY AND SECURITY PASSWORD SALT!!!
SECRET_KEY = "SHORTSTOPKEYTEST",
SQLALCHEMY_DATABASE_URI=format_db_path(core.config.config.walkoff_db_type, os.path.abspath(paths.db_path)),
SECURITY_PASSWORD_HASH = 'pbkdf2_sha512',
SECURITY_TRACKABLE = False,
SECURITY_PASSWORD_SALT = 'something_super_secret_change_in_production',
SECURITY_POST_LOGIN_VIEW = '/',
WTF_CSRF_ENABLED = False,
STATIC_FOLDER=os.path.abspath('server/static')
)
# CHANGE SECRET KEY AND SECURITY PASSWORD SALT!!!
SECRET_KEY="SHORTSTOPKEYTEST",
SQLALCHEMY_DATABASE_URI=format_db_path(core.config.config.walkoff_db_type, os.path.abspath(paths.db_path)),
SECURITY_PASSWORD_HASH='pbkdf2_sha512',
SECURITY_TRACKABLE=False,
SECURITY_PASSWORD_SALT='something_super_secret_change_in_production',
SECURITY_POST_LOGIN_VIEW='/',
WTF_CSRF_ENABLED=False,
STATIC_FOLDER=os.path.abspath('server/static')
)

_app.config["SECURITY_LOGIN_USER_TEMPLATE"] = "login_user.html"
_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

connexion_app.add_api('composed_api.yaml')
return _app


# Template Loader
env = Environment(loader=FileSystemLoader("apps"))
app = create_app()
Expand Down Expand Up @@ -96,4 +98,4 @@ def create_user():

running_context.CaseSubscription.sync_to_subscriptions()

app.logger.handlers = logging.getLogger('server').handlers
app.logger.handlers = logging.getLogger('server').handlers
6 changes: 3 additions & 3 deletions server/appdevice.py
Expand Up @@ -31,7 +31,7 @@ def __init__(self, app=None, devices=None):
Args:
app (str, optional): The name of the app. Defaults to None.
device (list[str], optional): The list of device names to be associated with the App object. There is a
devices (list[str], optional): The list of device names to be associated with the App object. There is a
one to many mapping from Apps to Devices.
"""
self.name = app
Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(self, name="", username="", password="", ip="0.0.0.0", port=0, extr
password (str, optional): The password for the Device object. Defaults to an empty string.
ip (str, optional): The IP address for for the Device object. Defaults to "0.0.0.0".
port (int, optional): The port for the Device object. Defaults to 0.
exra_fields (str, optional): The string representation of a dictionary that holds various custom
extra_fields (str, optional): The string representation of a dictionary that holds various custom
extra fields for the Device object. Defaults to an empty string.
app_id (str, optional): The ID of the App object to which this Device is associated. Defaults to an
empty string.
Expand All @@ -116,7 +116,7 @@ def add_device(name, username, password, ip, port, extra_fields, app_server):
password (str, optional): The password for the Device object. Defaults to an empty string.
ip (str, optional): The IP address for for the Device object. Defaults to "0.0.0.0".
port (int, optional): The port for the Device object. Defaults to 0.
exra_fields (str, optional): The string representation of a dictionary that holds various custom
extra_fields (str, optional): The string representation of a dictionary that holds various custom
extra fields for the Device object. Defaults to an empty string.
app_server (str, optional): The ID of the App object to which this Device is associated. Defaults to an
empty string.
Expand Down
1 change: 1 addition & 0 deletions server/blueprints/app.py
Expand Up @@ -41,6 +41,7 @@ def list_app_actions():
else:
return json.dumps({'status': 'error: app name not found'})


#TODO: DELETE
@app_page.route('/display', methods=['POST'])
@auth_token_required
Expand Down
2 changes: 1 addition & 1 deletion server/blueprints/events.py
Expand Up @@ -41,4 +41,4 @@ def setup_case_stream():
@auth_token_required
@roles_accepted(*running_context.user_roles['/cases'])
def stream_case_events():
return Response(__case_event_stream(), mimetype='text/event-stream')
return Response(__case_event_stream(), mimetype='text/event-stream')
2 changes: 1 addition & 1 deletion server/blueprints/widget.py
Expand Up @@ -43,4 +43,4 @@ def load_module(app_name, widget_name):
def load_widget(app_name, widget_name, keys, values):
module = load_module(app_name, widget_name)
args = dict(zip(keys, values))
return getattr(module, 'load')(args) if module else {}
return getattr(module, 'load')(args) if module else {}
2 changes: 1 addition & 1 deletion server/blueprints/widgets.py
Expand Up @@ -43,4 +43,4 @@ def load_module(app_name, widget_name):
def load_widget(app_name, widget_name, keys, values):
module = load_module(app_name, widget_name)
args = dict(zip(keys, values))
return getattr(module, 'load')(args) if module else {}
return getattr(module, 'load')(args) if module else {}
1 change: 0 additions & 1 deletion server/casesubscription.py
Expand Up @@ -71,4 +71,3 @@ def sync_to_subscriptions():
subscriptions = {case.name: core.case.subscription.CaseSubscriptions.from_json(json.loads(case.subscription))
for case in CaseSubscription.query.all()}
core.case.subscription.set_subscriptions(subscriptions)

2 changes: 1 addition & 1 deletion server/endpoints/cases.py
Expand Up @@ -73,7 +73,7 @@ def __func():
if form.note.data:
case_database.case_db.edit_case_note(form.name.data, form.note.data)
current_app.logger.debug('Case name changed from {0} to {1}'.format(case, form.name.data))
#TODO: YAML says that name AND note are required...is this second branch necessary?
# TODO: YAML says that name AND note are required...is this second branch necessary?
elif form.note.data:
case_database.case_db.edit_case_note(case, form.note.data)
return case_database.case_db.cases_as_json()
Expand Down
2 changes: 1 addition & 1 deletion server/endpoints/events.py
Expand Up @@ -30,4 +30,4 @@ def __func():
return case_database.case_db.event_as_json(event_id)
else:
return {"status": "invalid event"}
return __func()
return __func()
4 changes: 2 additions & 2 deletions server/endpoints/playbooks.py
Expand Up @@ -399,8 +399,8 @@ def __func():
current_app.logger.info('Paused workflow {0}-{1}'.format(playbook_name, workflow_name))
return {"uuid": uuid}
else:
current_app.logger.error('Cannot pause workflow {0}-{1}. Does not exist in controller'.format(playbook_name,
workflow_name))
current_app.logger.error('Cannot pause workflow '
'{0}-{1}. Does not exist in controller'.format(playbook_name, workflow_name))
status = 'error: invalid playbook and/or workflow name'
return {"status": status}

Expand Down
12 changes: 8 additions & 4 deletions server/endpoints/roles.py
Expand Up @@ -15,6 +15,7 @@ def __func():
else:
current_app.logger.error('Cannot display roles. No roles exist.')
return {"status": "roles do not exist"}

return __func()


Expand All @@ -40,12 +41,13 @@ def __func():

running_context.db.session.commit()
current_app.logger.info('Role added: {0}'.format({"name": role_name,
"description": description,
"urls": default_urls}))
"description": description,
"urls": default_urls}))
return {"status": "role added " + role_name}
else:
current_app.logger.warning('Cannot add role {0}. Role already exists'.format(role_name))
return {"status": "role exists"}

return __func()


Expand All @@ -60,6 +62,7 @@ def __func():
else:
current_app.logger.error('Cannot display role {0}. Role does not exist.'.format(role_name))
return {"status": "role does not exist"}

return __func()


Expand All @@ -78,10 +81,11 @@ def __func():
add_to_user_roles(role_name, form.pages)
current_app.logger.info('Edited role {0} to {1}'.format(role_name,
{"name": role_name,
"description": form.description.data,
"urls": form.pages.data}))
"description": form.description.data,
"urls": form.pages.data}))
return role.display()
else:
current_app.logger.error('Cannot edit role {0}. Role does not exist.'.format(role_name))
return {"status": "role does not exist"}

return __func()
2 changes: 1 addition & 1 deletion server/interface.py
Expand Up @@ -14,7 +14,7 @@ def settings():
choices = [(obj.email, str(obj.email)) for obj in running_context.User.query.all()]
user_form.username.choices = choices
add_user_form = forms.AddUserForm()
roles = [(x.name,str(x.name)) for x in running_context.Role.query.all()]
roles = [(x.name, str(x.name)) for x in running_context.Role.query.all()]
add_user_form.roles.choices = roles
return {"systemForm": forms.SettingsForm(), "userForm": user_form, "addUserForm": add_user_form }

Expand Down
2 changes: 1 addition & 1 deletion server/triggers.py
Expand Up @@ -77,7 +77,7 @@ def execute(data_in, input_in):
Args:
data_in (str): Data to be used to match against the conditionals
intput_in (str): The input to teh first step of the workflow
input_in (str): The input to the first step of the workflow
Returns:
Dictionary of {"status": <status string>}
Expand Down

0 comments on commit 9ab258c

Please sign in to comment.