Skip to content

Commit

Permalink
Merge pull request #44 from brianwalborn/develop
Browse files Browse the repository at this point in the history
Release v1.0
  • Loading branch information
brianwalborn authored Mar 13, 2022
2 parents 53ce13e + 74cbb30 commit bb0515c
Show file tree
Hide file tree
Showing 58 changed files with 500 additions and 454 deletions.
15 changes: 8 additions & 7 deletions cloud_browser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from cloud_browser.blueprints import autoscaling, ec2, elb, elbv2, home, settings, ssm
from cloud_browser.blueprints import autoscaling, base, ec2, elb, elbv2, settings, ssm
from cloud_browser.database import database
from flask import Flask

Expand All @@ -18,26 +18,27 @@ def create_app(test_config = None):
except OSError: pass

app.register_blueprint(autoscaling.bp)
app.add_url_rule('/autoscaling', endpoint = 'index')
app.add_url_rule('/autoscaling/<string:task>', endpoint = '')

app.register_blueprint(ec2.bp)
app.add_url_rule('/ec2', endpoint = 'index')
app.add_url_rule('/ec2/<string:task>', endpoint = '')

app.register_blueprint(elb.bp)
app.add_url_rule('/elb', endpoint = 'index')
app.add_url_rule('/elb/<string:task>', endpoint = '')

app.register_blueprint(elbv2.bp)
app.add_url_rule('/elbv2', endpoint = 'index')
app.add_url_rule('/elbv2/<string:task>', endpoint = '')

app.register_blueprint(home.bp)
app.register_blueprint(base.bp)
app.add_url_rule('/', endpoint = 'index')

app.register_blueprint(settings.bp)
app.add_url_rule('/settings', endpoint = 'index')

app.register_blueprint(ssm.bp)
app.add_url_rule('/ssm', endpoint = 'index')
app.add_url_rule('/ssm/<string:task>', endpoint = '')

database.init_app(app)

return app

35 changes: 17 additions & 18 deletions cloud_browser/blueprints/autoscaling.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import json
import os
from cloud_browser.services.custom.check_auto_scaling_groups import Scanner
from flask import current_app as app
from flask import Blueprint, flash, render_template
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.tasks.get_auto_scaling_groups import GetAutoScalingGroups
from flask import Blueprint, flash, render_template, request

bp = Blueprint('autoscaling', __name__)

@bp.route('/autoscaling')
def index():
f = open(os.path.join(app.static_folder, 'data', 'services.json'))
services = json.load(f)
actions = []
@bp.route('/autoscaling/get_life_cycle_hooks')
def get_life_cycle_hooks():
auto_scaling_groups = []

for service in services:
if service['name'] == 'autoscaling': actions = service['actions']
try:
auto_scaling_groups.extend(GetAutoScalingGroups().get_auto_scaling_groups())

if not auto_scaling_groups: flash('No results returned. Please review settings.', 'warning')
except Exception as e:
flash(e, 'error')

return render_template('actions.html', service = 'autoscaling', actions = actions)
return render_template('autoscaling/life_cycle_hooks.html', auto_scaling_groups = auto_scaling_groups, breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), service = 'get_life_cycle_hooks')

@bp.route('/autoscaling/check_auto_scaling_groups')
def check_auto_scaling_groups():
@bp.route('/autoscaling/get_suspended_processes')
def get_suspended_processes():
auto_scaling_groups = []

try:
scanner = Scanner()
auto_scaling_groups.extend(scanner.get_auto_scaling_groups())
auto_scaling_groups.extend(GetAutoScalingGroups().get_auto_scaling_groups())

if not auto_scaling_groups: flash('No results returned. Please review settings.', 'warning')
except Exception as e:
flash(e, 'error')

return render_template('autoscaling/check_auto_scaling_groups.html', auto_scaling_groups = auto_scaling_groups, service = 'check_auto_scaling_groups')
return render_template('autoscaling/suspended_processes.html', auto_scaling_groups = auto_scaling_groups, breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), service = 'get_suspended_processes')
25 changes: 25 additions & 0 deletions cloud_browser/blueprints/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import json
import os
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from flask import current_app as app
from flask import Blueprint, render_template, request

bp = Blueprint('base', __name__)

@bp.route('/')
def index():
f = open(os.path.join(app.static_folder, 'data', 'services.json'))
services = json.load(f)

return render_template('base.html', services = services)

@bp.route('/<string:service>')
def load_tasks(service):
f = open(os.path.join(app.static_folder, 'data', 'services.json'))
services = json.load(f)
tasks = []

for aws_service in services:
if aws_service['name'] == service: tasks = aws_service['tasks']

return render_template('tasks.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), service = service, tasks = tasks)
24 changes: 5 additions & 19 deletions cloud_browser/blueprints/ec2.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import json
import os
from cloud_browser.services.custom.generate_conf_cons import Generator
from flask import current_app as app
from flask import Blueprint, flash, render_template
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.tasks.generate_conf_cons import GenerateConfCons
from flask import Blueprint, flash, render_template, request

bp = Blueprint('ec2', __name__)

@bp.route('/ec2')
def index():
f = open(os.path.join(app.static_folder, 'data', 'services.json'))
services = json.load(f)
actions = []

for service in services:
if service['name'] == 'ec2': actions = service['actions']

return render_template('actions.html', service = 'ec2', actions = actions)

@bp.route('/ec2/generate_conf_cons')
def generate_conf_cons():
xml = ''

try:
generator = Generator()
xml = generator.run()
xml = GenerateConfCons().generate()
except Exception as e:
flash(e, 'error')

return render_template('ec2/generate_conf_cons.html', service = 'generate_conf_cons', xml = xml)
return render_template('ec2/generate_conf_cons.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), service = 'generate_conf_cons', xml = xml)
28 changes: 7 additions & 21 deletions cloud_browser/blueprints/elb.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import json
import os
from cloud_browser.services.custom.check_load_balancer_health import Check
from flask import current_app as app
from flask import Blueprint, flash, render_template
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.tasks.load_balancer_health import LoadBalancerHealth
from flask import Blueprint, flash, render_template, request

bp = Blueprint('elb', __name__)

@bp.route('/elb')
def index():
f = open(os.path.join(app.static_folder, 'data', 'services.json'))
services = json.load(f)
actions = []

for service in services:
if service['name'] == 'elb': actions = service['actions']

return render_template('actions.html', service = 'elb', actions = actions)

@bp.route('/elb/check_load_balancer_health')
def check_load_balancer_health():
@bp.route('/elb/get_load_balancer_health')
def get_load_balancer_health():
load_balancers = []

try:
check = Check()
load_balancers.extend(check.get_load_balancer_instance_health())
load_balancers.extend(LoadBalancerHealth().get_load_balancer_health())

if not load_balancers: flash('No results returned. Please review settings.', 'warning')
except Exception as e:
flash(e, 'error')

return render_template('elb/check_load_balancer_health.html', load_balancers = load_balancers, service = 'check_load_balancer_health')
return render_template('elb/load_balancer_health.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), load_balancers = load_balancers, service = 'get_load_balancer_health')
27 changes: 7 additions & 20 deletions cloud_browser/blueprints/elbv2.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import cloud_browser.services.custom.check_target_group_health as health
import json
import os
from flask import current_app as app
from flask import Blueprint, flash, render_template
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.tasks.target_group_health import TargetGroupHealth
from flask import Blueprint, flash, render_template, request

bp = Blueprint('elbv2', __name__)

@bp.route('/elbv2')
def index():
f = open(os.path.join(app.static_folder, 'data', 'services.json'))
services = json.load(f)
actions = []

for service in services:
if service['name'] == 'elbv2': actions = service['actions']

return render_template('actions.html', service = 'elbv2', actions = actions)

@bp.route('/elbv2/check_target_group_health')
def check_target_group_health():
@bp.route('/elbv2/get_target_group_health')
def get_target_group_health():
results = []

try:
results = health.check_target_group_health()
results = TargetGroupHealth().get_target_group_health()
except Exception as e:
flash(e, 'error')

return render_template('elbv2/check_target_group_health.html', target_groups = results, service = 'check_target_group_health')
return render_template('elbv2/target_group_health.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), target_groups = results, service = 'get_target_group_health')
13 changes: 0 additions & 13 deletions cloud_browser/blueprints/home.py

This file was deleted.

4 changes: 2 additions & 2 deletions cloud_browser/blueprints/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.blueprints.utils.validator import Validator
from cloud_browser.database.database import get_database
from flask import current_app as app
from flask import Blueprint, flash, render_template, request

bp = Blueprint('settings', __name__)
Expand Down Expand Up @@ -41,4 +41,4 @@ def index():
tags = database.execute('SELECT * FROM settings_query_tags').fetchall()
tags_to_exclude = database.execute('SELECT * FROM settings_exclude_tags').fetchall()

return render_template('settings.html', invalid_fields = validator.invalid_fields, putty_sessions = putty_sessions, regions = regions, service = 'settings', tags = tags, tags_to_exclude = tags_to_exclude)
return render_template('settings.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), invalid_fields = validator.invalid_fields, putty_sessions = putty_sessions, regions = regions, service = 'settings', tags = tags, tags_to_exclude = tags_to_exclude)
37 changes: 11 additions & 26 deletions cloud_browser/blueprints/ssm.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import flask
import json
import os
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.blueprints.utils.validator import Validator
from cloud_browser.models.aws.ec2.instance import Instance
from cloud_browser.services.custom.send_ssm_command import Orchestrator
from flask import current_app as app
from cloud_browser.tasks.send_ssm_command import SendSsmCommand
from flask import Blueprint, flash, render_template, request

class Context:
Expand All @@ -30,12 +28,12 @@ def command_input():
try:
if request.method == 'POST' and validator.validate_required_fields(request.form):
if ('linux_command' in request.form or 'windows_command' in request.form):
orchestrator = Orchestrator()
task = SendSsmCommand()

if 'linux_command' in request.form: orchestrator.linux_command = request.form['linux_command']
if 'windows_command' in request.form: orchestrator.windows_command = request.form['windows_command']
if 'linux_command' in request.form: task.linux_command = request.form['linux_command']
if 'windows_command' in request.form: task.windows_command = request.form['windows_command']

context.sent_commands = orchestrator.send(context.selected_instances)
context.sent_commands = task.send_commands(context.selected_instances)

return flask.redirect('/ssm/send_ssm_command/command_results')
else:
Expand All @@ -47,15 +45,14 @@ def command_input():
except Exception as e:
flash(e, 'error')

return render_template('ssm/send_ssm_command/command_input.html', instances = context.selected_instances, invalid_fields = validator.invalid_fields, operating_systems = operating_systems, service = 'send_ssm_command')
return render_template('ssm/send_ssm_command/command_input.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), instances = context.selected_instances, invalid_fields = validator.invalid_fields, operating_systems = operating_systems, service = 'send_ssm_command')

@bp.route('/ssm/send_ssm_command/command_results')
def command_results():
results = []

try:
orchestrator = Orchestrator()
results = orchestrator.get_command_results(context.sent_commands)
results = SendSsmCommand().get_command_results(context.sent_commands)

for result in results:
for instance in context.selected_instances:
Expand All @@ -67,18 +64,7 @@ def command_results():

context.clear()

return render_template('ssm/send_ssm_command/command_results.html', results = results, service = 'send_ssm_command')

@bp.route('/ssm')
def index():
f = open(os.path.join(app.static_folder, 'data', 'services.json'))
services = json.load(f)
actions = []

for service in services:
if service['name'] == 'ssm': actions = service['actions']

return render_template('actions.html', service = 'ssm', actions = actions)
return render_template('ssm/send_ssm_command/command_results.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), results = results, service = 'send_ssm_command')

@bp.route('/ssm/send_ssm_command')
def redirect():
Expand All @@ -97,11 +83,10 @@ def select_instances():
return flask.redirect('/ssm/send_ssm_command/command_input')
else:
context.clear()
orchestrator = Orchestrator()
context.all_instances = orchestrator.fetch_instances()
context.all_instances = SendSsmCommand().get_instances()

if not context.all_instances: flash('No results returned. Please review settings.', 'warning')
except Exception as e:
flash(e, 'error')

return render_template('ssm/send_ssm_command/select_instances.html', instances = context.all_instances, service = 'send_ssm_command')
return render_template('ssm/send_ssm_command/select_instances.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), instances = context.all_instances, service = 'send_ssm_command')
19 changes: 19 additions & 0 deletions cloud_browser/blueprints/utils/breadcrumb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Breadcrumb:
def get_breadcrumbs(path: str) -> list[str]:
breadcrumbs: list[Crumb] = []
crumbs: list[str] = path.split('/')

for crumb in crumbs:
if not breadcrumbs:
breadcrumbs.append(Crumb('home', True, '/'))
continue

breadcrumbs.append(Crumb(crumb, crumbs.index(crumb) < len(crumbs) - 1, f'{path.split(crumb)[0]}/{crumb}'.replace('//', '/')))

return breadcrumbs

class Crumb:
def __init__(self, display, enabled, path):
self.display: str = display
self.enabled: bool = enabled
self.path: str = path
2 changes: 1 addition & 1 deletion cloud_browser/models/aws/autoscaling/auto_scaling_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cloud_browser.models.aws.autoscaling.instance import Instance
from cloud_browser.models.aws.autoscaling.suspended_process import SuspendedProcess
from cloud_browser.models.base import BaseAwsResource
from cloud_browser.models.aws.base import BaseAwsResource

class AutoScalingGroup(BaseAwsResource):
def __init__(self, auto_scaling_group_json) -> None:
Expand Down
2 changes: 1 addition & 1 deletion cloud_browser/models/aws/autoscaling/instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cloud_browser.models.base import BaseAwsResource
from cloud_browser.models.aws.base import BaseAwsResource

class Instance(BaseAwsResource):
def __init__(self, auto_scaling_group_instance_json):
Expand Down
2 changes: 1 addition & 1 deletion cloud_browser/models/aws/autoscaling/lifecycle_hook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cloud_browser.models.base import BaseAwsResource
from cloud_browser.models.aws.base import BaseAwsResource

class LifecycleHook(BaseAwsResource):
def __init__(self, lifecycle_hook_json):
Expand Down
2 changes: 1 addition & 1 deletion cloud_browser/models/aws/autoscaling/suspended_process.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cloud_browser.models.base import BaseAwsResource
from cloud_browser.models.aws.base import BaseAwsResource

class SuspendedProcess(BaseAwsResource):
def __init__(self, suspended_process_json):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cloud_browser/models/aws/ec2/image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cloud_browser.models.base import BaseAwsResource
from cloud_browser.models.aws.base import BaseAwsResource

class Image(BaseAwsResource):
def __init__(self, describe_image_json):
Expand Down
2 changes: 1 addition & 1 deletion cloud_browser/models/aws/ec2/instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cloud_browser.models.base import BaseAwsResource
from cloud_browser.models.aws.base import BaseAwsResource

class Instance(BaseAwsResource):
def __init__(self, describe_instance_json):
Expand Down
Loading

0 comments on commit bb0515c

Please sign in to comment.