Skip to content

Commit

Permalink
Merge pull request #21 from mbrg/split_logic_flows
Browse files Browse the repository at this point in the history
split logic flows
  • Loading branch information
lanasalameh1 authored Jul 30, 2023
2 parents 105e144 + 1b7d376 commit 28b8454
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,5 @@ cov.xml
.DS_Store

tokens.json
*.zip
*.zip
.dump
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def collect(self, session: requests.Session, environment_id: str) -> Generator[C
entity_type=ResourceType.canvas_app,
)
logger.info(
f"Found {total_widely_shared_canvas_apps} widely shared canvas apps out of {total_canvas_apps} canvas apps in environment {environment_id}"
f"Found {total_widely_shared_canvas_apps} widely shared applications out of {total_canvas_apps} canvas apps in environment {environment_id}"
)

def resource_type(self) -> ResourceType:
Expand Down
6 changes: 4 additions & 2 deletions src/powerpwn/powerdump/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
full_canvasapps_table_wrapper,
full_connection_table_wrapper,
full_connectors_table_wrapper,
full_logic_flows_table_wrapper,
full_resources_table_wrapper,
register_specs,
)
Expand All @@ -26,8 +27,9 @@ def run(self, cache_path: str) -> None:
app = Flask(__name__, template_folder=self.__get_template_full_path())
register_specs(app=app, cache_path=cache_path)
app.route("/")(full_resources_table_wrapper(cache_path=cache_path))
app.route("/connection")(full_connection_table_wrapper(cache_path=cache_path))
app.route("/canvas_app/")(full_canvasapps_table_wrapper(cache_path))
app.route("/credentials")(full_connection_table_wrapper(cache_path=cache_path))
app.route("/automation")(full_logic_flows_table_wrapper(cache_path=cache_path))
app.route("/app/")(full_canvasapps_table_wrapper(cache_path))
app.route("/connector/")(full_connectors_table_wrapper(cache_path))
app.route("/<connector_id>/")(flt_connection_table_wrapper(cache_path=cache_path))
app.route("/<resource_type>/<env_id>/<resource_id>")(flt_resource_wrapper(cache_path=cache_path))
Expand Down
31 changes: 17 additions & 14 deletions src/powerpwn/powerdump/gui/prep.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import json
import os
import pathlib
from typing import Optional

from flask import Flask, render_template
from swagger_ui import flask_api_doc

from powerpwn.cli.const import TOOL_NAME
from powerpwn.powerdump.collect.models.resource_entity_base import ResourceEntityBase
from powerpwn.powerdump.collect.resources_collectors.enums.resource_type import ResourceType
from powerpwn.powerdump.utils.model_loaders import (
get_canvasapp,
get_connection,
get_connector,
load_canvasapps,
load_connections,
load_connectors,
load_logic_flows,
load_resources,
map_connector_id_and_env_id_to_connection_ids,
)
Expand Down Expand Up @@ -55,13 +53,22 @@ def full_resources_table():

def full_connection_table_wrapper(cache_path: str):
def full_connection_table():
connections = list(load_connections(cache_path=cache_path))
connections = list(load_connections(cache_path=cache_path, with_logic_flows=False))

return render_template("connections_table.html", title=f"{TOOL_NAME} - Connections", resources=connections)
return render_template("connections_table.html", title=f"{TOOL_NAME} - Credentials", resources=connections)

return full_connection_table


def full_logic_flows_table_wrapper(cache_path: str):
def full_logic_flows_table():
connections = list(load_logic_flows(cache_path=cache_path))

return render_template("logic_flows_table.html", title=f"{TOOL_NAME} - Automations", resources=connections)

return full_logic_flows_table


def flt_connection_table_wrapper(cache_path: str):
def flt_connection_table(connector_id: str):
connections = [conn for conn in load_connections(cache_path=cache_path) if conn.connector_id == connector_id]
Expand All @@ -75,7 +82,7 @@ def full_canvasapps_table_wrapper(cache_path: str):
def full_canvasapp_table():
apps = list(load_canvasapps(cache_path=cache_path))

return render_template("canvasapps_table.html", title=f"{TOOL_NAME} - Canvas Apps", resources=apps)
return render_template("canvasapps_table.html", title=f"{TOOL_NAME} - Applications", resources=apps)

return full_canvasapp_table

Expand All @@ -90,13 +97,13 @@ def full_connector_table():


def flt_resource_wrapper(cache_path: str):
def get_resource_page(resource_type: ResourceType, env_id: str, resource_id: str):
def get_resource_page(resource_type: str, env_id: str, resource_id: str):
resource: Optional[ResourceEntityBase] = None
if resource_type == ResourceType.canvas_app:
if resource_type == "app":
resource = get_canvasapp(cache_path, env_id, resource_id)
elif resource_type == ResourceType.connection:
elif resource_type in ("credentials", "automation"):
resource = get_connection(cache_path, env_id, resource_id)
elif resource_type == ResourceType.connector:
elif resource_type == "connector":
resource = get_connector(cache_path, env_id, resource_id)

if resource:
Expand All @@ -105,7 +112,3 @@ def get_resource_page(resource_type: ResourceType, env_id: str, resource_id: str
)

return get_resource_page


def __get_template_full_path(template_name: str) -> str:
return os.path.join(pathlib.Path(__file__).parent.resolve(), "templates", template_name)
5 changes: 3 additions & 2 deletions src/powerpwn/powerdump/gui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ <h1>{{ title }}</h1>
<div class="menu">
<ul>
<li><a href="/">All Resources</a></li>
<li><a href="/connection">Connections</a></li>
<li><a href="/canvas_app">Canvas Apps</a></li>
<li><a href="/credentials">Credentials</a></li>
<li><a href="/automation">Automations</a></li>
<li><a href="/app">Applications</a></li>
<li><a href="/connector">Connectors</a></li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/powerpwn/powerdump/gui/templates/canvasapps_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<td>{{ canvasapp.created_at }}</td>
<td>{{ canvasapp.last_modified_at }}</td>
<td><a href="{{ canvasapp.run_url }}" target="_blank">Run</a> </td>
<td><a href="/{{ canvasapp.entity_type}}/{{ canvasapp.environment_id }}/{{ canvasapp.entity_id }}">Raw</a> </td>
<td><a href="/app/{{ canvasapp.environment_id }}/{{ canvasapp.entity_id }}">Raw</a> </td>
</tr>
{% endfor %}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<td>{{ connection.created_by.email }}</td>
<td>{{ connection.shareable }}</td>
<td><a href="/api/{{ connection.connector_id }}/{{ connection.connection_id }}">Playground</a></td>
<td><a href="/{{ connection.entity_type }}/{{ connection.environment_id }}/{{ connection.entity_id }}">Raw</a> </td>
<td><a href="/credentials/{{ connection.environment_id }}/{{ connection.entity_id }}">Raw</a> </td>
<td><a href="http://127.0.0.1:8080/browse/data/{{ connection.environment_id }}/connections/{{connection.connector_id}}/{{connection.entity_id}}" target="_blank">Dump</a> </td>
</tr>
{% endfor %}
Expand Down
46 changes: 46 additions & 0 deletions src/powerpwn/powerdump/gui/templates/logic_flows_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends "base.html" %}

{% block content %}
<table id="data" class="table table-striped">
<thead>
<tr>
<th></th>
<th>Connector</th>
<th>Connection</th>
<th>Environment </th>
<th>Is valid</th>
<th>Last modified at</th>
<th>Expires at</th>
<th>Created by</th>
<th>Shareable</th>
</tr>
</thead>
<tbody>
{% for connection in resources %}
<tr>
<td><img src="{{ connection.icon_uri }}" class="img-thumbnail" alt="{{ connection.connection_id }}" width="25"></td>
<td><a href="/{{ connection.connector_id }}">{{ connection.connector_id }}</a></td>
<td>{{ connection.display_name }}</td>
<td>{{ connection.environment_id }}</td>
<td>{{ connection.is_valid }}</td>
<td>{{ connection.last_modified_at }}</td>
<td>{{ connection.expiration_time }}</td>
<td>{{ connection.created_by.email }}</td>
<td>{{ connection.shareable }}</td>
<td><a href="/api/{{ connection.connector_id }}/{{ connection.connection_id }}">Playground</a></td>
<td><a href="/automation/{{ connection.environment_id }}/{{ connection.entity_id }}">Raw</a> </td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

{% block scripts %}
<script>
$(document).ready(function () {
$('#data').DataTable({
scrollX: true
});
});
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion src/powerpwn/powerdump/gui/templates/resources_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<td>{{ resource.created_by.email }}</td>
<td>{{ resource.created_at }}</td>
<td>{{ resource.last_modified_at }}</td>
<td><a href="/{{ resource.entity_type }}/{{ resource.environment_id }}/{{ resource.entity_id }}">Raw</a> </td>
<td><a href="/connector/{{ resource.environment_id }}/{{ resource.entity_id }}">Raw</a> </td>
</tr>
{% endfor %}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion src/powerpwn/powerdump/utils/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CACHE_PATH = ".cache"
CACHE_PATH = ".dump"
DATA_MODEL_FILE_EXTENSION = ".json"
SPEC_JWT_NAME = "ApiHubBearerAuth"
DATA_MODEL_VERSION = "0.0.1"
Expand Down
20 changes: 19 additions & 1 deletion src/powerpwn/powerdump/utils/model_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def load_resources(cache_path: str, env_id: Optional[str] = None) -> Generator[R
yield from load_connectors(cache_path, env_id)


def load_connections(cache_path: str, env_id: Optional[str] = None) -> Generator[Connection, None, None]:
def load_connections(cache_path: str, env_id: Optional[str] = None, with_logic_flows: bool = True) -> Generator[Connection, None, None]:
cache = pathlib.Path(entities_path(cache_path))
if env_id:
connections = cache.glob(f"{env_id}/{ResourceType.connection}/*.json")
Expand All @@ -28,6 +28,24 @@ def load_connections(cache_path: str, env_id: Optional[str] = None) -> Generator
with open(connection_path, "r") as fp:
raw_connection = json.load(fp)
parsed_connection = Connection.parse_obj(raw_connection)
if parsed_connection.connector_id == "shared_logicflows" and not with_logic_flows:
continue
yield parsed_connection


def load_logic_flows(cache_path: str, env_id: Optional[str] = None) -> Generator[Connection, None, None]:
cache = pathlib.Path(entities_path(cache_path))
if env_id:
connections = cache.glob(f"{env_id}/{ResourceType.connection}/*.json")
else:
connections = cache.glob(f"*/{ResourceType.connection}/*.json")
for connection in connections:
connection_path = "/".join(list(connection.parts))
with open(connection_path, "r") as fp:
raw_connection = json.load(fp)
parsed_connection = Connection.parse_obj(raw_connection)
if not parsed_connection.connector_id == "shared_logicflows":
continue
yield parsed_connection


Expand Down

0 comments on commit 28b8454

Please sign in to comment.