Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

CG Demo: enabling/disabling certain functionality #556

Draft
wants to merge 41 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
079b64c
CG demo instance
Dec 27, 2021
1bc2609
Demo obfuscation for alerts API
Dec 29, 2021
545f307
Delete package-lock.json
ChartistDev Jan 3, 2022
3a9e6a1
removed unused variable
Jan 3, 2022
ff5918b
resolved merge conflicts
Jan 3, 2022
e1fe3cf
Merge branch 'main' of github.com:chaos-genius/chaos_genius into CG-Demo
Jan 5, 2022
e29be8d
removed is_demo env variable from frontend env
Jan 5, 2022
ee968d9
merge
Jan 5, 2022
502ad21
feat: Add hook to restrict APIs for the demo version
bhargavsk1077 Jan 12, 2022
cf2f5d7
fix: Fix bug in register_hooks function
bhargavsk1077 Jan 12, 2022
9b7fe08
conflicts resolved
Feb 23, 2022
e9fb9e9
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Feb 23, 2022
db972c7
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Feb 24, 2022
d2b91e5
added demo check for report setting time
Feb 24, 2022
9203a61
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Feb 24, 2022
40f8dff
fix:Add get-timecuts-list API to demo whitelist
bhargavsk1077 Feb 24, 2022
f2aa3b1
added restrictions for channel configuration
Feb 24, 2022
6f2755b
Merge branch 'CG-Demo' of github.com:chaos-genius/chaos_genius into C…
Feb 24, 2022
8726496
added GA script
Feb 25, 2022
97d4049
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Mar 17, 2022
2e8311f
added demo obfuscation for retrain model
Mar 17, 2022
4b43a78
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Mar 23, 2022
35ba6c4
added demo obfuscation for deleting alerts
Mar 23, 2022
c9a69bb
fix: Whitelist APIs based on request method
bhargavsk1077 Mar 24, 2022
912f673
refactor: Change return messages in register_hooks
bhargavsk1077 Mar 25, 2022
73e4c9a
refactor: Use _make_bool for REACT_APP_IS_DEMO
bhargavsk1077 Mar 25, 2022
57b60ef
style: Format DEMO_ENDPOINT_WHITELIST
bhargavsk1077 Mar 25, 2022
12a4149
fix: Add REACT_APP_IS_DEMO to all compose files
bhargavsk1077 Mar 25, 2022
1954e9a
style: format register_hooks function in app.py
bhargavsk1077 Mar 25, 2022
c1baf44
updated demo to 0.6.0
Apr 14, 2022
41636a7
added obfuscation for sycnc schema in Demo
Apr 14, 2022
ce27e67
fix: Add download APIs to whitelist
bhargavsk1077 Apr 14, 2022
0d08b4f
resolved duplicate variables issues
Apr 14, 2022
07e3af1
Merge branch 'CG-Demo' of github.com:chaos-genius/chaos_genius into C…
Apr 14, 2022
8f148ac
fix: Add support timezone API to whitelist
bhargavsk1077 Apr 14, 2022
e3c234c
merge conflict resolved
ChartistDev Jun 14, 2022
e6346c0
chore(demo): add new summary endpoints to whitelist
Samyak2 Jun 14, 2022
a973c10
resolved merge conflict
ChartistDev Jul 5, 2022
fb89c2d
fix(demo): update endpoint whitelist
Samyak2 Jul 5, 2022
300ff77
resolved merge conflicts
ChartistDev Aug 29, 2022
13e58dc
fix(demo): use a single level before_request hook
Samyak2 Aug 29, 2022
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
32 changes: 31 additions & 1 deletion chaos_genius/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import sys
import json

from flask import Flask, render_template
from flask import Flask, render_template, request
from flask.json import jsonify
from flask_cors import CORS

from chaos_genius import commands
from chaos_genius.logger import configure_logger
from chaos_genius.settings import REACT_APP_IS_DEMO
from chaos_genius.utils.utils import DEMO_ENDPOINT_WHITELIST
from chaos_genius.views import (
data_source_view,
download_view,
Expand Down Expand Up @@ -47,6 +50,7 @@ def create_app(config_object="chaos_genius.settings"):
app.config.from_object(config_object)
register_extensions(app)
register_blueprints(app)
register_hooks(app)
register_errorhandlers(app)
register_shellcontext(app)
register_commands(app)
Expand Down Expand Up @@ -125,6 +129,32 @@ def shell_context():
app.shell_context_processor(shell_context)


def register_hooks(app):
"""Register hooks for Flask requests."""

@app.before_request
def demo_endpoints_blocker():
"""Hook to allow access to only whitelisted APIs in demo."""
if REACT_APP_IS_DEMO:
if request.endpoint not in DEMO_ENDPOINT_WHITELIST:
return jsonify(
{
"status": "failure",
"message": "Endpoint not accessible in demo version",
}
)
else:
if request.method not in DEMO_ENDPOINT_WHITELIST[request.endpoint]:
return jsonify(
{
"status": "failure",
"message": f"{request.method} method is not allowed for this endpoint in demo version",
}
)
else:
pass


def register_commands(app):
"""Register Click commands."""
app.cli.add_command(commands.test)
Expand Down
1 change: 1 addition & 0 deletions chaos_genius/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def _make_bool(val: Union[str, bool]) -> bool:
"CHAOSGENIUS_ENTERPRISE_EDITION_KEY"
)

REACT_APP_IS_DEMO = _make_bool(os.getenv("REACT_APP_IS_DEMO", default=True))
"""Dynamic Third Party Data Sources"""
SOURCE_GOOGLE_ANALYTICS = _make_bool(
os.getenv("SOURCE_GOOGLE_ANALYTICS", default=True)
Expand Down
69 changes: 69 additions & 0 deletions chaos_genius/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,72 @@ def make_path_safe(s: str) -> str:
Does not replace spaces.
"""
return re.sub(_invalid_chars_reg, "_", s)


DEMO_ENDPOINT_WHITELIST = {
"alert.alert_meta_info": ["GET"],
"alert.get_alert_info_by_id": ["GET"],
"alert.get_used_channels": ["GET"],
"alert.get_used_statuses": ["GET"],
"alert.disable_alert": ["GET"],
"alert.enable_alert": ["GET"],
"alert.list_alert": ["GET"],
"anomaly_data.anomaly_settings_status": ["GET"],
"anomaly_data.kpi_anomaly_data_quality": ["GET"],
"anomaly_data.kpi_anomaly_detection": ["GET"],
"anomaly_data.kpi_anomaly_drilldown": ["GET"],
"anomaly_data.kpi_anomaly_params": ["GET"],
"anomaly_data.kpi_anomaly_params_meta": ["GET"],
"anomaly_data.kpi_subdim_anomaly": ["GET"],
"anomaly_data.list_anomaly_data": ["GET"],
"api_data_source.data_source": ["GET"],
"api_data_source.data_source_meta_info": ["GET"],
"api_data_source.get_data_source_info": ["GET"],
"api_data_source.list_data_source_type": ["GET"],
# "api_data_source.log_data_source",
"api_data_source.metadata_data_source": ["POST"],
"api_data_source.test_data_source_connection": ["GET"],
"api_data_source.check_views_availability": ["POST"],
"api_data_source.get_schema_list": ["POST"],
"api_data_source.get_schema_tables": ["POST"],
"api_data_source.get_table_info": ["POST"],
"api_data_source.used_data_source_types_endpoint": ["GET"],
"api_kpi.kpi": ["GET"],
"api_kpi.get_all_kpis": ["GET"],
"api_kpi.get_kpi_info": ["GET"],
"api_kpi.kpi_get_dimensions": ["GET"],
"api_kpi.get_timecuts_list": ["GET"],
"api_kpi.kpi_meta_info": ["GET"],
"api_rca.kpi_get_aggregation": ["GET"],
"api_rca.kpi_get_line_data": ["GET"],
"api_rca.kpi_rca_analysis": ["GET"],
"api_rca.kpi_rca_hierarchical_data": ["GET"],
"api_summary.kpi_get_aggregation": ["GET"],
"api_summary.kpi_get_line_data": ["GET"],
"config_settings.get_all_config": ["GET"],
"config_settings.get_config": ["POST"],
"config_settings.get_config_meta_data": ["GET"],
"config_settings.get_onboarding_status": ["GET"],
"config_settings.global_config": ["GET"],
# "config_settings.global_settings",
"config_settings.multidim_status": ["GET"],
"dashboard.get_all_dashboard_names": ["GET"],
"dashboard.get_dashboard_list": ["GET"],
"dashboard.get_dashboard": ["GET"],
"digest.task_monitor_view": ["GET"],
"digest.static": ["GET"],
"status.task_monitor_view": ["GET"],
"downloads.download_anomaly_data": ["GET"],
"downloads.download_hierarchical_data": ["GET"],
"downloads.download_multidim_analysis_data": ["GET"],
"downloads.kpi_download_line_data": ["GET"],
# "meta.static",
# "public.api_view",
# "public.home",
# "public.static",
# "static",
# "status.static",
# "status.task_monitor_view",
"meta.support_timezones": ["GET"],
"meta.version_view": ["GET"],
}
2 changes: 2 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- *chaosgenius-version
- IN_DOCKER=True
- AIRBYTE_ENABLED=${AIRBYTE_ENABLED}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
- FLASK_APP=${FLASK_APP}
- FLASK_ENV=${FLASK_ENV}
- FLASK_DEBUG=${FLASK_DEBUG}
Expand Down Expand Up @@ -89,6 +90,7 @@ services:
- REACT_APP_BASE_URL=${REACT_APP_BASE_URL}
- REACT_APP_DISABLE_TELEMETRY=${REACT_APP_DISABLE_TELEMETRY}
- REACT_APP_EVENT_ALERT=${REACT_APP_EVENT_ALERT}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
depends_on:
- chaosgenius-server

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.fluentd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
- *chaosgenius-version
- IN_DOCKER=True
- AIRBYTE_ENABLED=${AIRBYTE_ENABLED}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
- FLASK_APP=${FLASK_APP}
- FLASK_ENV=${FLASK_ENV}
- FLASK_DEBUG=${FLASK_DEBUG}
Expand Down Expand Up @@ -98,6 +99,7 @@ services:
- REACT_APP_BASE_URL=${REACT_APP_BASE_URL}
- REACT_APP_DISABLE_TELEMETRY=${REACT_APP_DISABLE_TELEMETRY}
- REACT_APP_EVENT_ALERT=${REACT_APP_EVENT_ALERT}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
depends_on:
- chaosgenius-server
- chaosgenius-fluentd
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.latest-thirdparty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ services:
- *chaosgenius-version
- IN_DOCKER=True
- AIRBYTE_ENABLED=True
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
- FLASK_APP=${FLASK_APP}
- FLASK_ENV=${FLASK_ENV}
- FLASK_DEBUG=${FLASK_DEBUG}
Expand Down Expand Up @@ -110,6 +111,7 @@ services:
- REACT_APP_BASE_URL=${REACT_APP_BASE_URL}
- REACT_APP_DISABLE_TELEMETRY=${REACT_APP_DISABLE_TELEMETRY}
- REACT_APP_EVENT_ALERT=${REACT_APP_EVENT_ALERT}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
depends_on:
- chaosgenius-server

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
- *chaosgenius-version
- IN_DOCKER=True
- AIRBYTE_ENABLED=${AIRBYTE_ENABLED}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
- FLASK_APP=${FLASK_APP}
- FLASK_ENV=${FLASK_ENV}
- FLASK_DEBUG=${FLASK_DEBUG}
Expand Down Expand Up @@ -83,6 +84,7 @@ services:
- REACT_APP_BASE_URL=${REACT_APP_BASE_URL}
- REACT_APP_DISABLE_TELEMETRY=${REACT_APP_DISABLE_TELEMETRY}
- REACT_APP_EVENT_ALERT=${REACT_APP_EVENT_ALERT}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
depends_on:
- chaosgenius-server

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.thirdparty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ services:
- *chaosgenius-version
- IN_DOCKER=True
- AIRBYTE_ENABLED=True
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
- FLASK_APP=${FLASK_APP}
- FLASK_ENV=${FLASK_ENV}
- FLASK_DEBUG=${FLASK_DEBUG}
Expand Down Expand Up @@ -110,6 +111,7 @@ services:
- REACT_APP_BASE_URL=${REACT_APP_BASE_URL}
- REACT_APP_DISABLE_TELEMETRY=${REACT_APP_DISABLE_TELEMETRY}
- REACT_APP_EVENT_ALERT=${REACT_APP_EVENT_ALERT}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
depends_on:
- chaosgenius-server

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
- *chaosgenius-version
- IN_DOCKER=True
- AIRBYTE_ENABLED=${AIRBYTE_ENABLED}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
- FLASK_APP=${FLASK_APP}
- FLASK_ENV=${FLASK_ENV}
- FLASK_DEBUG=${FLASK_DEBUG}
Expand Down Expand Up @@ -83,6 +84,7 @@ services:
- REACT_APP_BASE_URL=${REACT_APP_BASE_URL}
- REACT_APP_DISABLE_TELEMETRY=${REACT_APP_DISABLE_TELEMETRY}
- REACT_APP_EVENT_ALERT=${REACT_APP_EVENT_ALERT}
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
depends_on:
- chaosgenius-server

Expand Down
13 changes: 13 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-ZTDCWNG9GQ"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-ZTDCWNG9GQ');
</script>
<script src="%PUBLIC_URL%/env.js"></script>
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/AlertTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const AlertTable = ({
alertSearch,
setPgInfo,
pagination,
pgInfo
pgInfo,
customToast
}) => {
const dispatch = useDispatch();

Expand All @@ -59,7 +60,7 @@ const AlertTable = ({

const onDeleteConfirmation = (id) => {
store.dispatch(RESET_DELETE_DATA);
dispatch(kpiAlertDeleteById(id));
dispatch(kpiAlertDeleteById(id, customToast));
setIsOpen(false);
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/AlertsForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ const AlertsForm = () => {
};

const dispatchGetAllAlertEmail = (data) => {
dispatch(getAllAlertEmail(data));
dispatch(getAllAlertEmail(data, customToast));
};

const editableStatus = (type) => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Analystics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ const Analystics = ({ kpi, setAnalystics, onboarding }) => {
if (edit && Object.keys(needForCleanup)?.length) {
setModalOpen(true);
} else {
dispatch(kpiSettingSetup(kpi, data));
dispatch(kpiSettingSetup(kpi, data, customToast));
}
}
};
Expand Down Expand Up @@ -913,7 +913,7 @@ const Analystics = ({ kpi, setAnalystics, onboarding }) => {
const data = {
anomaly_params: { ...editForm }
};
dispatch(kpiSettingSetup(kpi, data));
dispatch(kpiSettingSetup(kpi, data, customToast));
setModalOpen(false);
}}>
<span>Save Changes</span>
Expand Down
Loading