From 079b64c6f7c689d0d3fc1f5a962a25cd7f4a1ead Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Mon, 27 Dec 2021 12:05:25 +0530 Subject: [PATCH 01/25] CG demo instance --- frontend/.env | 3 +- frontend/src/components/Analystics/index.js | 2 +- .../src/components/DashboardForm/index.js | 4 +- .../src/components/Dashboardcards/index.jsx | 2 +- .../src/components/DataSourceForm/index.jsx | 6 +- .../src/components/DataSourceTable/index.jsx | 2 +- frontend/src/components/KPITable/index.jsx | 2 +- .../src/components/KpiExplorerForm/index.jsx | 4 +- frontend/src/redux/actions/DashboardHome.js | 17 ++- frontend/src/redux/actions/DataSources.js | 55 +++++--- frontend/src/redux/actions/KpiEplorer.js | 131 +++++++++++------- frontend/src/redux/actions/setting.js | 47 ++++--- frontend/src/utils/http-helper.js | 52 +++++++ frontend/src/utils/url-helper.js | 19 ++- 14 files changed, 242 insertions(+), 104 deletions(-) diff --git a/frontend/.env b/frontend/.env index 8da19991f..9744a49de 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1 +1,2 @@ -REACT_APP_BASE_URL=http://localhost:5000 +REACT_APP_BASE_URL=https://dev-main.chaosgenius.io +REACT_APP_IS_DEMO=true diff --git a/frontend/src/components/Analystics/index.js b/frontend/src/components/Analystics/index.js index da073a14e..1af899e86 100644 --- a/frontend/src/components/Analystics/index.js +++ b/frontend/src/components/Analystics/index.js @@ -286,7 +286,7 @@ const Analystics = ({ kpi, setAnalystics, onboarding }) => { scheduler_params_time: schedule } }; - dispatch(kpiSettingSetup(kpi, data)); + dispatch(kpiSettingSetup(kpi, data, customToast)); } }; diff --git a/frontend/src/components/DashboardForm/index.js b/frontend/src/components/DashboardForm/index.js index 2bafff205..45c854956 100644 --- a/frontend/src/components/DashboardForm/index.js +++ b/frontend/src/components/DashboardForm/index.js @@ -205,13 +205,13 @@ const DashboardForm = ({ setText, setModal, onboarding }) => { dashboard_name: formData.dashboardname, kpi_list: formData.kpi }; - dispatch(getUpdateDashboard(payload)); + dispatch(getUpdateDashboard(payload, customToast)); } else { const dashboardData = { dashboard_name: formData.dashboardname, kpi_list: formData.kpi }; - dispatch(getCreateDashboard(dashboardData)); + dispatch(getCreateDashboard(dashboardData, customToast)); } } }; diff --git a/frontend/src/components/Dashboardcards/index.jsx b/frontend/src/components/Dashboardcards/index.jsx index 188e93164..5a9c454b5 100644 --- a/frontend/src/components/Dashboardcards/index.jsx +++ b/frontend/src/components/Dashboardcards/index.jsx @@ -40,7 +40,7 @@ const Dashboardcards = ({ dashboarddata, setChange }) => { }; const onDelete = (value) => { - dispatch(getDashboardDelete({ dashboard_id: value.id })); + dispatch(getDashboardDelete({ dashboard_id: value.id }, customToast)); }; const customToast = (data) => { diff --git a/frontend/src/components/DataSourceForm/index.jsx b/frontend/src/components/DataSourceForm/index.jsx index b01778781..9fa9e8e59 100644 --- a/frontend/src/components/DataSourceForm/index.jsx +++ b/frontend/src/components/DataSourceForm/index.jsx @@ -393,7 +393,7 @@ const DataSourceForm = ({ onboarding, setModal, setText }) => { sourceDefinitionId: sourceDefinitionId } }; - dispatch(createDataSource(bingPayload)); + dispatch(createDataSource(bingPayload, customToast)); } else { const payload = { connection_type: selectedDatasource.value, @@ -403,7 +403,7 @@ const DataSourceForm = ({ onboarding, setModal, setText }) => { sourceDefinitionId: sourceDefinitionId } }; - dispatch(createDataSource(payload)); + dispatch(createDataSource(payload, customToast)); } } }; @@ -445,7 +445,7 @@ const DataSourceForm = ({ onboarding, setModal, setText }) => { connectionConfiguration: editedForm } }; - dispatch(updateDatasourceById(dsId, payload)); + dispatch(updateDatasourceById(dsId, payload, customToast)); } }; diff --git a/frontend/src/components/DataSourceTable/index.jsx b/frontend/src/components/DataSourceTable/index.jsx index f6db01197..1bc082219 100644 --- a/frontend/src/components/DataSourceTable/index.jsx +++ b/frontend/src/components/DataSourceTable/index.jsx @@ -70,7 +70,7 @@ const DataSourceTable = ({ tableData, changeData, search }) => { const payload = { data_source_id: datasource.id }; - dispatch(deleteDatasource(payload)); + dispatch(deleteDatasource(payload, customToast)); }; const datasourceIcon = (type) => { diff --git a/frontend/src/components/KPITable/index.jsx b/frontend/src/components/KPITable/index.jsx index b2d0085d7..47e19f45a 100644 --- a/frontend/src/components/KPITable/index.jsx +++ b/frontend/src/components/KPITable/index.jsx @@ -47,7 +47,7 @@ const KPITable = ({ kpiData, kpiLoading, kpiSearch, changeData }) => { }; const onDelete = (kpi) => { - dispatch(kpiDisable(kpi.id)); + dispatch(kpiDisable(kpi.id, customToast)); }; useEffect(() => { diff --git a/frontend/src/components/KpiExplorerForm/index.jsx b/frontend/src/components/KpiExplorerForm/index.jsx index f48f28fcf..e4eb7e82d 100644 --- a/frontend/src/components/KpiExplorerForm/index.jsx +++ b/frontend/src/components/KpiExplorerForm/index.jsx @@ -622,7 +622,7 @@ const KpiExplorerForm = ({ onboarding, setModal, setText }) => { dashboard: formdata.dashboardNameList.map((el) => el.value) }; if (data[2] === 'edit') { - dispatch(getUpdatekpi(kpiId, { name: formdata.kpiname })); + dispatch(getUpdatekpi(kpiId, { name: formdata.kpiname }, customToast)); } else { dispatchgetAllKpiExplorerSubmit(kpiInfo); } @@ -630,7 +630,7 @@ const KpiExplorerForm = ({ onboarding, setModal, setText }) => { }; const dispatchgetAllKpiExplorerSubmit = (kpiInfo) => { - dispatch(getAllKpiExplorerSubmit(kpiInfo)); + dispatch(getAllKpiExplorerSubmit(kpiInfo, customToast)); }; const onTestQuery = () => { diff --git a/frontend/src/redux/actions/DashboardHome.js b/frontend/src/redux/actions/DashboardHome.js index 451a5c7ef..e81b9bbaf 100644 --- a/frontend/src/redux/actions/DashboardHome.js +++ b/frontend/src/redux/actions/DashboardHome.js @@ -1,3 +1,4 @@ +import { env } from '../../env'; import { getRequest, postRequest } from '../../utils/http-helper'; import { DASHBOARD_LIST_URL, @@ -77,12 +78,13 @@ export const getDashboardDeleteFailure = () => { }; }; -export const getDashboardDelete = (params) => { +export const getDashboardDelete = (params, customToast) => { return async (dispatch) => { dispatch(getDashboardDeleteRequest()); const URL = attachParams(DASHBOARD_DELETE_URL, params); const { data, error, status } = await postRequest({ - url: URL + url: URL, + customToast }); if (error) { dispatch(getDashboardDeleteFailure()); @@ -111,12 +113,13 @@ export const getCreateDashboardFailure = () => { }; }; -export const getCreateDashboard = (dashboard) => { +export const getCreateDashboard = (dashboard, customToast) => { return async (dispatch) => { dispatch(getCreateDashboardRequest()); const { data, error, status } = await postRequest({ url: DASHBOARD_CREATE_URL, - data: dashboard + data: dashboard, + customToast }); if (error) { dispatch(getCreateDashboardFailure()); @@ -179,17 +182,17 @@ export const getUpdateDashboardFailure = () => { }; }; -export const getUpdateDashboard = (payload) => { +export const getUpdateDashboard = (payload, customToast) => { return async (dispatch) => { dispatch(getUpdateDashboardRequest()); - //const URL = attachParams(DASHBOARD_UPDATE_URL, params); const { data, error, status } = await postRequest({ url: DASHBOARD_UPDATE_URL, data: JSON.stringify(payload), headers: { 'Content-Type': 'application/json' }, - noAuth: true + noAuth: true, + customToast }); if (error) { dispatch(getUpdateDashboardFailure()); diff --git a/frontend/src/redux/actions/DataSources.js b/frontend/src/redux/actions/DataSources.js index 1f5412f34..865ecb2f2 100644 --- a/frontend/src/redux/actions/DataSources.js +++ b/frontend/src/redux/actions/DataSources.js @@ -33,6 +33,7 @@ import { DELETE_DATASOURCE, TEST_CONNECTION } from '../../utils/url-helper'; +import { env } from '../../env'; import { getRequest, postRequest } from '../../utils/http-helper'; @@ -155,12 +156,13 @@ export const createDatesourceFailure = () => { }; }; -export const createDataSource = (formData) => { +export const createDataSource = (formData, customToast) => { return async (dispatch) => { dispatch(createDatasourceRequested()); const { data, error, status } = await postRequest({ url: CREATE_DATASOURCE, - data: formData + data: formData, + customToast }); if (error) { dispatch(createDatesourceFailure()); @@ -189,12 +191,13 @@ export const deleteDatesourceFailure = () => { }; }; -export const deleteDatasource = (id) => { +export const deleteDatasource = (id, customToast) => { return async (dispatch) => { dispatch(deleteDatasourceRequested()); const { data, error, status } = await postRequest({ url: DELETE_DATASOURCE, - data: id + data: id, + customToast }); if (error) { dispatch(deleteDatesourceFailure()); @@ -286,21 +289,33 @@ export const updateDatasourceByIdFailure = () => { }; }; -export const updateDatasourceById = (id, updateData) => { - return async (dispatch) => { - dispatch(updateDatasourceByIdRequest()); - const { data, error, status } = await postRequest({ - url: `${CONNECTION_URL}/${id}/test-and-update`, - data: JSON.stringify(updateData), - headers: { - 'Content-Type': 'application/json;charset=UTF-8' - }, - noAuth: true - }); - if (error) { - dispatch(updateDatasourceByIdFailure()); - } else if (data && status === 200) { - dispatch(updateDatasourceByIdSuccess(data)); +export const updateDatasourceById = (id, updateData, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(updateDatasourceByIdRequest()); + const { data, error, status } = await postRequest({ + url: `${CONNECTION_URL}/${id}/test-and-update`, + data: JSON.stringify(updateData), + headers: { + 'Content-Type': 'application/json;charset=UTF-8' + }, + noAuth: true + }); + if (error) { + dispatch(updateDatasourceByIdFailure()); + } else if (data && status === 200) { + dispatch(updateDatasourceByIdSuccess(data)); + } + }; + } }; diff --git a/frontend/src/redux/actions/KpiEplorer.js b/frontend/src/redux/actions/KpiEplorer.js index 5f7f9d770..4ee7319f3 100644 --- a/frontend/src/redux/actions/KpiEplorer.js +++ b/frontend/src/redux/actions/KpiEplorer.js @@ -34,6 +34,7 @@ import { KPI_FORM_OPTION_URL, TEST_QUERY_URL } from '../../utils/url-helper'; +import { env } from '../../env'; import { getRequest, postRequest, putRequest } from '../../utils/http-helper'; @@ -156,25 +157,37 @@ export const getAllKpiExplorerSubmitSuccess = (response) => { }; }; -export const getAllKpiExplorerSubmit = (payload) => { - return async (dispatch) => { - dispatch(getAllKpiExplorerSubmitRequested()); - const { data, error, status } = await postRequest({ - url: KPI_URL + '/', - data: JSON.stringify(payload), - headers: { - 'Content-Type': 'application/json;charset=UTF-8', - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Credentials': true - }, - noAuth: true - }); - if (error) { - dispatch(getAllKpiExplorerSubmitFailure()); - } else if (data && status === 200) { - dispatch(getAllKpiExplorerSubmitSuccess(data)); +export const getAllKpiExplorerSubmit = (payload, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(getAllKpiExplorerSubmitRequested()); + const { data, error, status } = await postRequest({ + url: KPI_URL + '/', + data: JSON.stringify(payload), + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Credentials': true + }, + noAuth: true + }); + if (error) { + dispatch(getAllKpiExplorerSubmitFailure()); + } else if (data && status === 200) { + dispatch(getAllKpiExplorerSubmitSuccess(data)); + } + }; + } }; export const getTestQueryRequested = () => { @@ -230,18 +243,30 @@ export const kpiDisableSuccess = (response) => { }; }; -export const kpiDisable = (id) => { - return async (dispatch) => { - dispatch(kpiDisableRequest()); - const { data, error, status } = await getRequest({ - url: `${KPI_URL}/${id}/disable` - }); - if (error) { - dispatch(kpiDisableFailure()); - } else if (data && status === 200) { - dispatch(kpiDisableSuccess(data)); +export const kpiDisable = (id, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(kpiDisableRequest()); + const { data, error, status } = await getRequest({ + url: `${KPI_URL}/${id}/disable` + }); + if (error) { + dispatch(kpiDisableFailure()); + } else if (data && status === 200) { + dispatch(kpiDisableSuccess(data)); + } + }; + } }; export const getEditMetaInfoRequest = () => { @@ -325,23 +350,35 @@ export const getUpdateKpiFailure = () => { }; }; -export const getUpdatekpi = (id, updateData) => { - return async (dispatch) => { - dispatch(getUpdateKpiRequest()); - const { data, error, status } = await putRequest({ - url: `${KPI_URL}/${id}/update`, - data: JSON.stringify(updateData), - headers: { - 'Content-Type': 'application/json;charset=UTF-8', - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Credentials': true - }, - noAuth: true - }); - if (error) { - dispatch(getUpdateKpiFailure()); - } else if (data && status === 200) { - dispatch(getUpdateKpiSuccess(data)); +export const getUpdatekpi = (id, updateData, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(getUpdateKpiRequest()); + const { data, error, status } = await putRequest({ + url: `${KPI_URL}/${id}/update`, + data: JSON.stringify(updateData), + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Credentials': true + }, + noAuth: true + }); + if (error) { + dispatch(getUpdateKpiFailure()); + } else if (data && status === 200) { + dispatch(getUpdateKpiSuccess(data)); + } + }; + } }; diff --git a/frontend/src/redux/actions/setting.js b/frontend/src/redux/actions/setting.js index 13ab71556..21023b3e6 100644 --- a/frontend/src/redux/actions/setting.js +++ b/frontend/src/redux/actions/setting.js @@ -1,3 +1,4 @@ +import { env } from '../../env'; import { getRequest, postRequest } from '../../utils/http-helper'; import { BASE_URL, SETTING_META_INFO_URL } from '../../utils/url-helper'; import { @@ -31,24 +32,36 @@ export const kpiSettingFailure = () => { }; }; -export const kpiSettingSetup = (kpi, kpiData) => { - return async (dispatch) => { - dispatch(kpiSettingRequest()); - const URL = `${BASE_URL}/api/anomaly-data/${kpi}/anomaly-params`; - const { data, error, status } = await postRequest({ - url: URL, - data: kpiData, - headers: { - 'Content-Type': 'application/json' - }, - noAuth: true - }); - if (error) { - dispatch(kpiSettingFailure()); - } else if (data && status === 200) { - dispatch(kpiSettingSuccess(data)); +export const kpiSettingSetup = (kpi, kpiData, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(kpiSettingRequest()); + const URL = `${BASE_URL}/api/anomaly-data/${kpi}/anomaly-params`; + const { data, error, status } = await postRequest({ + url: URL, + data: kpiData, + headers: { + 'Content-Type': 'application/json' + }, + noAuth: true + }); + if (error) { + dispatch(kpiSettingFailure()); + } else if (data && status === 200) { + dispatch(kpiSettingSuccess(data)); + } + }; + } }; export const kpiEditRequest = () => { diff --git a/frontend/src/utils/http-helper.js b/frontend/src/utils/http-helper.js index 91f33e9e1..6bb03c740 100644 --- a/frontend/src/utils/http-helper.js +++ b/frontend/src/utils/http-helper.js @@ -1,7 +1,9 @@ import axios from 'axios'; +import { env } from '../env'; //import { forceLogout } from './user-helper'; import { getCookie } from './cookie-helper'; +import { checkBlackList } from './url-helper'; export const sendRequest = async (args) => { try { @@ -39,6 +41,16 @@ export const sendRequest = async (args) => { }; export const getRequest = async (args) => { + if (env.REACT_APP_IS_DEMO === 'true') { + const isBlackListed = checkBlackList(args?.url); + if (isBlackListed && args.customToast) { + args.customToast({ type: 'failure', header: 'This is demo version' }); + return { + data: null, + error: true + }; + } + } const { data, headers, error, status } = await sendRequest({ ...args, method: 'get' @@ -59,6 +71,16 @@ export const getRequest = async (args) => { }; export const postRequest = async (args) => { + if (env.REACT_APP_IS_DEMO === 'true') { + const isBlackListed = checkBlackList(args?.url); + if (isBlackListed && args.customToast) { + args.customToast({ type: 'failure', header: 'This is demo version' }); + return { + data: null, + error: true + }; + } + } const { data, headers, error, status } = await sendRequest({ ...args, method: 'post' @@ -80,6 +102,16 @@ export const postRequest = async (args) => { }; export const patchRequest = async (args) => { + if (env.REACT_APP_IS_DEMO === 'true') { + const isBlackListed = checkBlackList(args?.url); + if (isBlackListed && args.customToast) { + args.customToast({ type: 'failure', header: 'This is demo version' }); + return { + data: null, + error: true + }; + } + } const { data, headers, error, status } = await sendRequest({ ...args, method: 'patch' @@ -100,6 +132,16 @@ export const patchRequest = async (args) => { }; export const deleteRequest = async (args) => { + if (env.REACT_APP_IS_DEMO === 'true') { + const isBlackListed = checkBlackList(args?.url); + if (isBlackListed && args.customToast) { + args.customToast({ type: 'failure', header: 'This is demo version' }); + return { + data: null, + error: true + }; + } + } const { data, error, status, headers } = await sendRequest({ ...args, method: 'delete' @@ -120,6 +162,16 @@ export const deleteRequest = async (args) => { }; export const putRequest = async (args) => { + if (env.REACT_APP_IS_DEMO === 'true') { + const isBlackListed = checkBlackList(args?.url); + if (isBlackListed && args.customToast) { + args.customToast({ type: 'failure', header: 'This is demo version' }); + return { + data: null, + error: true + }; + } + } const { data, error, status, headers } = await sendRequest({ ...args, method: 'put' diff --git a/frontend/src/utils/url-helper.js b/frontend/src/utils/url-helper.js index 3840e8cdf..c75de6a49 100644 --- a/frontend/src/utils/url-helper.js +++ b/frontend/src/utils/url-helper.js @@ -2,7 +2,6 @@ import { env } from '../env'; export const BASE_URL = env.REACT_APP_BASE_URL || ''; - export const attachParams = (relativeUrl, params) => { let baseUrl = BASE_URL; @@ -48,3 +47,21 @@ export const DASHBOARD_UPDATE_URL = `${BASE_URL}/api/dashboard/edit`; export const ORGANIZATION_UPDATE_URL = `${BASE_URL}/api/config/update`; export const GLOBAL_SETTING_URL = `${BASE_URL}/api/config/global-config`; export const TASK_MANAGER_API_STATUS_URL = `${BASE_URL}/api/status`; + +const urlBlackListForDemo = [ + DASHBOARD_UPDATE_URL, + DASHBOARD_CREATE_URL, + DASHBOARD_DELETE_URL, + CREATE_DATASOURCE, + DELETE_DATASOURCE +]; + +export const checkBlackList = (url) => { + const blackListIndex = urlBlackListForDemo.findIndex((item) => { + return item === url; + }); + if (blackListIndex > -1) { + return true; + } + return false; +}; From 545f3076f735361398c7d12f35c35e244d80a414 Mon Sep 17 00:00:00 2001 From: ChartistDev <50948001+ChartistDev@users.noreply.github.com> Date: Mon, 3 Jan 2022 10:18:22 +0530 Subject: [PATCH 02/25] Delete package-lock.json --- package-lock.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 48e341a09..000000000 --- a/package-lock.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "lockfileVersion": 1 -} From 3a9e6a1ae287ff21401cb900825140eb014ed397 Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Mon, 3 Jan 2022 11:21:43 +0530 Subject: [PATCH 03/25] removed unused variable --- frontend/src/redux/actions/DashboardHome.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/redux/actions/DashboardHome.js b/frontend/src/redux/actions/DashboardHome.js index e81b9bbaf..c1023285d 100644 --- a/frontend/src/redux/actions/DashboardHome.js +++ b/frontend/src/redux/actions/DashboardHome.js @@ -1,4 +1,3 @@ -import { env } from '../../env'; import { getRequest, postRequest } from '../../utils/http-helper'; import { DASHBOARD_LIST_URL, From e29be8de0d0f2f561fe8d2186dc736528505607b Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Wed, 5 Jan 2022 12:11:09 +0530 Subject: [PATCH 04/25] removed is_demo env variable from frontend env --- frontend/.env | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/.env b/frontend/.env index c0ba5ae70..8da19991f 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1,2 +1 @@ REACT_APP_BASE_URL=http://localhost:5000 -REACT_APP_IS_DEMO=true From 502ad21a6179c24ee6dbf00e985e67370d47c15d Mon Sep 17 00:00:00 2001 From: bhargav Date: Wed, 12 Jan 2022 11:58:04 +0530 Subject: [PATCH 05/25] feat: Add hook to restrict APIs for the demo version Added a 'before_request' hook to check if the destination endpoint is present in the whitelisted APIs. If yes allow the request to pass through, else return a message indicating the endpoint is unaccessable in demo version. --- chaos_genius/app.py | 17 ++++++++++++++- chaos_genius/settings.py | 6 ++++++ chaos_genius/utils/utils.py | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/chaos_genius/app.py b/chaos_genius/app.py index 38eb11528..f6f39c2b7 100644 --- a/chaos_genius/app.py +++ b/chaos_genius/app.py @@ -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, kpi_view, @@ -42,6 +45,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) @@ -108,6 +112,17 @@ def shell_context(): app.shell_context_processor(shell_context) +def register_hooks(app): + if REACT_APP_IS_DEMO: + @app.before_request + def before_request(): + if request.endpoint not in DEMO_ENDPOINT_WHITELIST: + return jsonify({"status":"failure", + "message":"Endpoint not accessable in demo version"}) + else: + pass + + def register_commands(app): """Register Click commands.""" app.cli.add_command(commands.test) diff --git a/chaos_genius/settings.py b/chaos_genius/settings.py index 1569bb417..2f3d270b1 100644 --- a/chaos_genius/settings.py +++ b/chaos_genius/settings.py @@ -92,3 +92,9 @@ """ChaosGenius full version string""" CHAOSGENIUS_ENTERPRISE_EDITION_KEY = os.getenv("CHAOSGENIUS_ENTERPRISE_EDITION_KEY") + +REACT_APP_IS_DEMO = os.getenv("REACT_APP_IS_DEMO") +if REACT_APP_IS_DEMO == 'true': + REACT_APP_IS_DEMO = True +else: + REACT_APP_IS_DEMO = False diff --git a/chaos_genius/utils/utils.py b/chaos_genius/utils/utils.py index 46c77a019..ad971be68 100644 --- a/chaos_genius/utils/utils.py +++ b/chaos_genius/utils/utils.py @@ -25,3 +25,45 @@ def latest_git_commit_hash() -> str: ) except (subprocess.CalledProcessError, FileNotFoundError): return "" + +DEMO_ENDPOINT_WHITELIST = ["alert.alert_meta_info", + "alert.get_alert_info_by_id", + "alert.list_alert", + "anomaly_data.anomaly_settings_status", + "anomaly_data.kpi_anomaly_data_quality", + "anomaly_data.kpi_anomaly_detection", + "anomaly_data.kpi_anomaly_drilldown", + "anomaly_data.kpi_anomaly_params_meta", + "anomaly_data.kpi_subdim_anomaly", + "anomaly_data.list_anomaly_data", + "api_data_source.data_source_meta_info", + "api_data_source.get_data_source_info", + "api_data_source.list_data_source_type", + "api_data_source.log_data_source", + "api_data_source.metadata_data_source", + "api_data_source.test_data_source_connection", + "api_kpi.get_all_kpis", + "api_kpi.get_kpi_info", + "api_kpi.kpi_get_aggregation", + "api_kpi.kpi_get_dimensions", + "api_kpi.kpi_get_line_data", + "api_kpi.kpi_meta_info", + "api_kpi.kpi_rca_analysis", + "api_kpi.kpi_rca_hierarchical_data", + "config_settings.get_all_config", + "config_settings.get_config", + "config_settings.get_config_meta_data", + "config_settings.get_onboarding_status", + "config_settings.global_config", + "config_settings.global_settings", + "config_settings.multidim_status", + "dashboard.get_dashboard", + "dashboard.get_dashboard_list", + "meta.static", + "meta.version_view", + "public.api_view", + "public.home", + "public.static", + "static", + "status.static", + "status.task_monitor_view"] From cf2f5d77fc5f51cf220ad915480c5e718f34861b Mon Sep 17 00:00:00 2001 From: bhargav Date: Wed, 12 Jan 2022 17:41:29 +0530 Subject: [PATCH 06/25] fix: Fix bug in register_hooks function Fixed request context bug in register_hooks fucntion. Added REACT_APP_IS_DEMO environment variable in docker-compose. --- chaos_genius/app.py | 19 +++++++++++-------- docker-compose.latest.yml | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/chaos_genius/app.py b/chaos_genius/app.py index f6f39c2b7..6521b3401 100644 --- a/chaos_genius/app.py +++ b/chaos_genius/app.py @@ -113,14 +113,17 @@ def shell_context(): def register_hooks(app): - if REACT_APP_IS_DEMO: - @app.before_request - def before_request(): - if request.endpoint not in DEMO_ENDPOINT_WHITELIST: - return jsonify({"status":"failure", - "message":"Endpoint not accessable in demo version"}) - else: - pass + @app.before_request + def authenticate(): + + if REACT_APP_IS_DEMO: + @app.before_request + def before_request(): + if request.endpoint not in DEMO_ENDPOINT_WHITELIST: + return jsonify({"status":"failure", + "message":"Endpoint not accessable in demo version"}) + else: + pass def register_commands(app): diff --git a/docker-compose.latest.yml b/docker-compose.latest.yml index 6dd070f6b..53b0a69fc 100644 --- a/docker-compose.latest.yml +++ b/docker-compose.latest.yml @@ -47,6 +47,7 @@ services: environment: - *chaosgenius-version - IN_DOCKER=True + - REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO} - FLASK_APP=${FLASK_APP} - FLASK_ENV=${FLASK_ENV} - FLASK_DEBUG=${FLASK_DEBUG} From d2b91e53c63d70f4da4257aa7798c9139b44fc33 Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Thu, 24 Feb 2022 16:14:45 +0530 Subject: [PATCH 07/25] added demo check for report setting time --- .../OrganisationSettings/ReportSetting.jsx | 7 +- frontend/src/redux/actions/Organisation.js | 69 +++++++++++-------- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/frontend/src/containers/OrganisationSettings/ReportSetting.jsx b/frontend/src/containers/OrganisationSettings/ReportSetting.jsx index 66edc3f41..9550a715e 100644 --- a/frontend/src/containers/OrganisationSettings/ReportSetting.jsx +++ b/frontend/src/containers/OrganisationSettings/ReportSetting.jsx @@ -75,7 +75,12 @@ const ReportSettings = () => { }; const onReportSettingsSave = (e) => { - dispatch(saveReportSettingTime(moment(schedule, 'HH:mm')?.format('HH:mm'))); + dispatch( + saveReportSettingTime( + moment(schedule, 'HH:mm')?.format('HH:mm'), + customToast + ) + ); }; return ( diff --git a/frontend/src/redux/actions/Organisation.js b/frontend/src/redux/actions/Organisation.js index 10273d0b8..a0d6b77eb 100644 --- a/frontend/src/redux/actions/Organisation.js +++ b/frontend/src/redux/actions/Organisation.js @@ -17,6 +17,7 @@ import { ALERT_EMAIL_URL, ORGANIZATION_UPDATE_URL } from '../../utils/url-helper'; +import { env } from '../../env'; import { postRequest, putRequest } from '../../utils/http-helper'; // import {getOnboardingStatus } from './Onboarding' @@ -150,35 +151,47 @@ export const onboardOrganisationUpdate = (payload) => { }; }; -export const saveReportSettingTime = (payload) => { - return async (dispatch) => { - dispatch(saveReportSettingTimeRequested()); - const { data, error, status } = await postRequest({ - url: ALERT_EMAIL_URL, - data: { - config_name: 'alert_digest_settings', - config_settings: { - active: true, - daily_digest: true, - weekly_digest: false, - scheduled_time: payload - } - }, - headers: { - 'Content-Type': 'application/json;charset=UTF-8', - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Credentials': true - }, - noAuth: true - }); - if (error) { - dispatch(saveReportSettingTimeFailure({ status: 'failure' })); - } else if (data && status === 200) { - dispatch( - saveReportSettingTimeSuccess({ data: payload, status: data.status }) - ); +export const saveReportSettingTime = (payload, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(saveReportSettingTimeRequested()); + const { data, error, status } = await postRequest({ + url: ALERT_EMAIL_URL, + data: { + config_name: 'alert_digest_settings', + config_settings: { + active: true, + daily_digest: true, + weekly_digest: false, + scheduled_time: payload + } + }, + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Credentials': true + }, + noAuth: true + }); + if (error) { + dispatch(saveReportSettingTimeFailure({ status: 'failure' })); + } else if (data && status === 200) { + dispatch( + saveReportSettingTimeSuccess({ data: payload, status: data.status }) + ); + } + }; + } }; export const getReportSettingTime = () => { From 40f8dff6b8b9c24d58019e079963689b40fa38f4 Mon Sep 17 00:00:00 2001 From: bhargav Date: Thu, 24 Feb 2022 17:46:48 +0530 Subject: [PATCH 08/25] fix:Add get-timecuts-list API to demo whitelist --- chaos_genius/utils/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chaos_genius/utils/utils.py b/chaos_genius/utils/utils.py index ad971be68..448ec43fd 100644 --- a/chaos_genius/utils/utils.py +++ b/chaos_genius/utils/utils.py @@ -66,4 +66,6 @@ def latest_git_commit_hash() -> str: "public.static", "static", "status.static", - "status.task_monitor_view"] + "status.task_monitor_view", + "api_kpi.get_timecuts_list"] + From f2aa3b1946913eb1108e99525c91e47f88570829 Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Thu, 24 Feb 2022 19:01:57 +0530 Subject: [PATCH 09/25] added restrictions for channel configuration --- frontend/src/components/AlertsForm/index.jsx | 2 +- frontend/src/redux/actions/Alert.js | 44 +++++++++++++------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/AlertsForm/index.jsx b/frontend/src/components/AlertsForm/index.jsx index 197be070d..2867d2b3f 100644 --- a/frontend/src/components/AlertsForm/index.jsx +++ b/frontend/src/components/AlertsForm/index.jsx @@ -394,7 +394,7 @@ const AlertsForm = () => { }; const dispatchGetAllAlertEmail = (data) => { - dispatch(getAllAlertEmail(data)); + dispatch(getAllAlertEmail(data, customToast)); }; const editableStatus = (type) => { diff --git a/frontend/src/redux/actions/Alert.js b/frontend/src/redux/actions/Alert.js index 47f9bf081..9605e5c8c 100644 --- a/frontend/src/redux/actions/Alert.js +++ b/frontend/src/redux/actions/Alert.js @@ -76,23 +76,35 @@ export const getAlertEmailSuccess = (response) => { }; }; -export const getAllAlertEmail = (details) => { - return async (dispatch) => { - dispatch(getAlertEmailRequest()); - const { data, error, status } = await postRequest({ - url: ALERT_EMAIL_URL, - headers: { - 'Content-Type': 'application/json' - }, - data: JSON.stringify(details), - noAuth: true - }); - if (error) { - dispatch(getAlertEmailFailure()); - } else if (data && status === 200) { - dispatch(getAlertEmailSuccess(data)); +export const getAllAlertEmail = (details, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(getAlertEmailRequest()); + const { data, error, status } = await postRequest({ + url: ALERT_EMAIL_URL, + headers: { + 'Content-Type': 'application/json' + }, + data: JSON.stringify(details), + noAuth: true + }); + if (error) { + dispatch(getAlertEmailFailure()); + } else if (data && status === 200) { + dispatch(getAlertEmailSuccess(data)); + } + }; + } }; export const getChannelStatusRequest = () => { From 8726496b6c9ae79297f4e2e9262a67b72620579a Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Fri, 25 Feb 2022 13:53:38 +0530 Subject: [PATCH 10/25] added GA script --- frontend/public/index.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frontend/public/index.html b/frontend/public/index.html index f9b604fe0..78984e57d 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -2,6 +2,19 @@ + + + From 2e8311f10dd9687a7f3c2969f71d4a9890a17277 Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Thu, 17 Mar 2022 13:24:58 +0530 Subject: [PATCH 11/25] added demo obfuscation for retrain model --- frontend/src/components/Anomaly/index.jsx | 32 ++++++++++++++++++- frontend/src/redux/actions/Anomaly.js | 38 +++++++++++++++-------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/Anomaly/index.jsx b/frontend/src/components/Anomaly/index.jsx index cc5d219fd..b1aef6280 100644 --- a/frontend/src/components/Anomaly/index.jsx +++ b/frontend/src/components/Anomaly/index.jsx @@ -14,6 +14,8 @@ import AnomalyEmptyState from '../AnomalyEmptyState'; import EmptyAnomalyDrilldown from '../EmptyDrillDown'; import { formatDateTime, getTimezone } from '../../utils/date-helper'; import { HRNumbers } from '../../utils/Formatting/Numbers/humanReadableNumberFormatter'; +import { useToast } from 'react-toast-wnm'; +import { CustomContent, CustomActions } from '../../utils/toast-helper'; import './anomaly.scss'; import { @@ -42,6 +44,34 @@ const RESET = { }; const Anomaly = ({ kpi, anomalystatus, dashboard }) => { + const toast = useToast(); + const customToast = (data) => { + const { type, header, description } = data; + toast({ + autoDismiss: true, + enableAnimation: true, + delay: type === 'success' ? '5000' : '30000', + backgroundColor: type === 'success' ? '#effaf5' : '#FEF6F5', + borderRadius: '6px', + color: '#222222', + position: 'bottom-right', + minWidth: '240px', + width: 'auto', + boxShadow: '4px 6px 32px -2px rgba(226, 226, 234, 0.24)', + padding: '17px 14px', + height: 'auto', + border: type === 'success' ? '1px solid #60ca9a' : '1px solid #FEF6F5', + type: type, + actions: , + content: ( + + ) + }); + }; const dispatch = useDispatch(); const history = useHistory(); const [chartData, setChartData] = useState([]); @@ -411,7 +441,7 @@ const Anomaly = ({ kpi, anomalystatus, dashboard }) => { }; const handleRetrain = () => { - dispatch(setRetrain(kpi)); + dispatch(setRetrain(kpi, customToast)); }; return ( diff --git a/frontend/src/redux/actions/Anomaly.js b/frontend/src/redux/actions/Anomaly.js index 660126e67..89268799f 100644 --- a/frontend/src/redux/actions/Anomaly.js +++ b/frontend/src/redux/actions/Anomaly.js @@ -1,5 +1,5 @@ import { attachParams, BASE_URL } from '../../utils/url-helper'; - +import { env } from '../../env'; import { getRequest } from '../../utils/http-helper'; import { ANOMALYDATAQUALITYFAILURE, @@ -86,19 +86,31 @@ export const retrainFailure = () => { }; }; -export const setRetrain = (kpi) => { - return async (dispatch) => { - dispatch(retrainRequested()); - - const { data, error, status } = await getRequest({ - url: `${BASE_URL}/api/anomaly-data/${kpi}/retrain` - }); - if (error) { - dispatch(retrainFailure()); - } else if (data && status === 200) { - dispatch(retrainSuccess(data)); +export const setRetrain = (kpi, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(retrainRequested()); + + const { data, error, status } = await getRequest({ + url: `${BASE_URL}/api/anomaly-data/${kpi}/retrain` + }); + if (error) { + dispatch(retrainFailure()); + } else if (data && status === 200) { + dispatch(retrainSuccess(data)); + } + }; + } }; export const anomalyQualityDataRequest = () => { From 35ba6c4f89acbdafe81bdfe2778c9b304da22e9e Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Wed, 23 Mar 2022 12:34:33 +0530 Subject: [PATCH 12/25] added demo obfuscation for deleting alerts --- frontend/src/components/AlertTable/index.jsx | 4 +-- frontend/src/containers/Alerts/index.jsx | 6 +++- frontend/src/redux/actions/Alert.js | 34 +++++++++++++------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/AlertTable/index.jsx b/frontend/src/components/AlertTable/index.jsx index 476ce7cbe..4635a34a1 100644 --- a/frontend/src/components/AlertTable/index.jsx +++ b/frontend/src/components/AlertTable/index.jsx @@ -34,7 +34,7 @@ const RESET_DELETE_DATA = { type: 'RESET_DELETE_DATA' }; -const AlertTable = ({ alertData, alertSearch }) => { +const AlertTable = ({ alertData, alertSearch, customToast }) => { const dispatch = useDispatch(); const [isOpen, setIsOpen] = useState(false); @@ -51,7 +51,7 @@ const AlertTable = ({ alertData, alertSearch }) => { const onDeleteConfirmation = (id) => { store.dispatch(RESET_DELETE_DATA); - dispatch(kpiAlertDeleteById(id)); + dispatch(kpiAlertDeleteById(id, customToast)); setIsOpen(false); }; diff --git a/frontend/src/containers/Alerts/index.jsx b/frontend/src/containers/Alerts/index.jsx index 8c95c3fdd..b3d1bdf38 100644 --- a/frontend/src/containers/Alerts/index.jsx +++ b/frontend/src/containers/Alerts/index.jsx @@ -288,7 +288,11 @@ const Alerts = () => { {/* table section */}
- +
) : ( diff --git a/frontend/src/redux/actions/Alert.js b/frontend/src/redux/actions/Alert.js index 9605e5c8c..a745d0359 100644 --- a/frontend/src/redux/actions/Alert.js +++ b/frontend/src/redux/actions/Alert.js @@ -517,16 +517,28 @@ export const kpiAlertDeleteSuccess = (response) => { }; }; -export const kpiAlertDeleteById = (id) => { - return async (dispatch) => { - dispatch(kpiAlertDeleteRequest()); - const { data, error, status } = await getRequest({ - url: `${BASE_URL}/api/alert/${id}/delete` - }); - if (error) { - dispatch(kpiAlertDeleteFailure()); - } else if (data && status === 200) { - dispatch(kpiAlertDeleteSuccess(data)); +export const kpiAlertDeleteById = (id, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(kpiAlertDeleteRequest()); + const { data, error, status } = await getRequest({ + url: `${BASE_URL}/api/alert/${id}/delete` + }); + if (error) { + dispatch(kpiAlertDeleteFailure()); + } else if (data && status === 200) { + dispatch(kpiAlertDeleteSuccess(data)); + } + }; + } }; From c9a69bb81ff6986324ee6a563b0c51cf4e6ac8ec Mon Sep 17 00:00:00 2001 From: bhargav Date: Thu, 24 Mar 2022 12:28:45 +0530 Subject: [PATCH 13/25] fix: Whitelist APIs based on request method --- chaos_genius/app.py | 6 ++- chaos_genius/utils/utils.py | 95 +++++++++++++++++++++---------------- 2 files changed, 58 insertions(+), 43 deletions(-) diff --git a/chaos_genius/app.py b/chaos_genius/app.py index fd9278773..3551f21b2 100644 --- a/chaos_genius/app.py +++ b/chaos_genius/app.py @@ -129,7 +129,11 @@ def before_request(): return jsonify({"status":"failure", "message":"Endpoint not accessable in demo version"}) else: - pass + if request.method not in DEMO_ENDPOINT_WHITELIST[request.endpoint]: + return jsonify({"status":"failure", + "message":"Method not allowed in demo version"}) + else: + pass def register_commands(app): diff --git a/chaos_genius/utils/utils.py b/chaos_genius/utils/utils.py index 448ec43fd..801238602 100644 --- a/chaos_genius/utils/utils.py +++ b/chaos_genius/utils/utils.py @@ -26,46 +26,57 @@ def latest_git_commit_hash() -> str: except (subprocess.CalledProcessError, FileNotFoundError): return "" -DEMO_ENDPOINT_WHITELIST = ["alert.alert_meta_info", - "alert.get_alert_info_by_id", - "alert.list_alert", - "anomaly_data.anomaly_settings_status", - "anomaly_data.kpi_anomaly_data_quality", - "anomaly_data.kpi_anomaly_detection", - "anomaly_data.kpi_anomaly_drilldown", - "anomaly_data.kpi_anomaly_params_meta", - "anomaly_data.kpi_subdim_anomaly", - "anomaly_data.list_anomaly_data", - "api_data_source.data_source_meta_info", - "api_data_source.get_data_source_info", - "api_data_source.list_data_source_type", - "api_data_source.log_data_source", - "api_data_source.metadata_data_source", - "api_data_source.test_data_source_connection", - "api_kpi.get_all_kpis", - "api_kpi.get_kpi_info", - "api_kpi.kpi_get_aggregation", - "api_kpi.kpi_get_dimensions", - "api_kpi.kpi_get_line_data", - "api_kpi.kpi_meta_info", - "api_kpi.kpi_rca_analysis", - "api_kpi.kpi_rca_hierarchical_data", - "config_settings.get_all_config", - "config_settings.get_config", - "config_settings.get_config_meta_data", - "config_settings.get_onboarding_status", - "config_settings.global_config", - "config_settings.global_settings", - "config_settings.multidim_status", - "dashboard.get_dashboard", - "dashboard.get_dashboard_list", - "meta.static", - "meta.version_view", - "public.api_view", - "public.home", - "public.static", - "static", - "status.static", - "status.task_monitor_view", - "api_kpi.get_timecuts_list"] +DEMO_ENDPOINT_WHITELIST = {"alert.alert_meta_info":["GET"], + "alert.get_alert_info_by_id":["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_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"], + "config_settings.get_all_config":["GET"], + "config_settings.get_config":["POST"], + "config_settings.set_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"], + "config_settings.edit_config_setting":["PUT"], + "dashboard.get_dashboard_list":["GET"], + "dashboard.get_dashboard":["GET"], + # "meta.static", + # "public.api_view", + # "public.home", + # "public.static", + # "static", + # "status.static", + # "status.task_monitor_view", + "meta.version_view":["GET"]} From 912f673eb2aadc5cb825f8202d73ee0433af51e7 Mon Sep 17 00:00:00 2001 From: bhargav Date: Fri, 25 Mar 2022 14:06:45 +0530 Subject: [PATCH 14/25] refactor: Change return messages in register_hooks --- chaos_genius/app.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/chaos_genius/app.py b/chaos_genius/app.py index 3551f21b2..826d7d61f 100644 --- a/chaos_genius/app.py +++ b/chaos_genius/app.py @@ -119,19 +119,20 @@ def shell_context(): def register_hooks(app): + """Register hooks for Flask requests.""" @app.before_request - def authenticate(): - + def demo_endpoints_blocker(): + """Hook to allow access to only whitelisted APIs in demo.""" if REACT_APP_IS_DEMO: @app.before_request def before_request(): if request.endpoint not in DEMO_ENDPOINT_WHITELIST: - return jsonify({"status":"failure", - "message":"Endpoint not accessable in demo version"}) + 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":"Method not allowed in demo version"}) + return jsonify({"status": "failure", + "message": f"{request.method} method is not allowed for this endpoint in demo version"}) else: pass From 73e4c9a97e068d113f420d6265cb46e1a7c03644 Mon Sep 17 00:00:00 2001 From: bhargav Date: Fri, 25 Mar 2022 14:11:56 +0530 Subject: [PATCH 15/25] refactor: Use _make_bool for REACT_APP_IS_DEMO --- chaos_genius/settings.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/chaos_genius/settings.py b/chaos_genius/settings.py index 844177b39..fa55a6424 100644 --- a/chaos_genius/settings.py +++ b/chaos_genius/settings.py @@ -107,11 +107,7 @@ def _make_bool(val: Union[str, bool]) -> bool: CHAOSGENIUS_ENTERPRISE_EDITION_KEY = os.getenv("CHAOSGENIUS_ENTERPRISE_EDITION_KEY") -REACT_APP_IS_DEMO = os.getenv("REACT_APP_IS_DEMO") -if REACT_APP_IS_DEMO == 'true': - REACT_APP_IS_DEMO = True -else: - REACT_APP_IS_DEMO = False +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)) SOURCE_GOOGLE_SHEETS = _make_bool(os.getenv("SOURCE_GOOGLE_SHEETS", default=True)) From 57b60eff11f94aa3a6e335d2172620e3eb3a095a Mon Sep 17 00:00:00 2001 From: bhargav Date: Fri, 25 Mar 2022 14:13:12 +0530 Subject: [PATCH 16/25] style: Format DEMO_ENDPOINT_WHITELIST --- chaos_genius/utils/utils.py | 108 ++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/chaos_genius/utils/utils.py b/chaos_genius/utils/utils.py index 801238602..b9fb06bb7 100644 --- a/chaos_genius/utils/utils.py +++ b/chaos_genius/utils/utils.py @@ -26,57 +26,59 @@ def latest_git_commit_hash() -> str: except (subprocess.CalledProcessError, FileNotFoundError): return "" -DEMO_ENDPOINT_WHITELIST = {"alert.alert_meta_info":["GET"], - "alert.get_alert_info_by_id":["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_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"], - "config_settings.get_all_config":["GET"], - "config_settings.get_config":["POST"], - "config_settings.set_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"], - "config_settings.edit_config_setting":["PUT"], - "dashboard.get_dashboard_list":["GET"], - "dashboard.get_dashboard":["GET"], - # "meta.static", - # "public.api_view", - # "public.home", - # "public.static", - # "static", - # "status.static", - # "status.task_monitor_view", - "meta.version_view":["GET"]} +DEMO_ENDPOINT_WHITELIST = { + "alert.alert_meta_info": ["GET"], + "alert.get_alert_info_by_id": ["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_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"], + "config_settings.get_all_config": ["GET"], + "config_settings.get_config": ["POST"], + "config_settings.set_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"], + "config_settings.edit_config_setting": ["PUT"], + "dashboard.get_dashboard_list": ["GET"], + "dashboard.get_dashboard": ["GET"], + # "meta.static", + # "public.api_view", + # "public.home", + # "public.static", + # "static", + # "status.static", + # "status.task_monitor_view", + "meta.version_view": ["GET"], +} From 12a4149b93042b83695a2564d1bdcdb7c8cc93ed Mon Sep 17 00:00:00 2001 From: bhargav Date: Fri, 25 Mar 2022 17:59:21 +0530 Subject: [PATCH 17/25] fix: Add REACT_APP_IS_DEMO to all compose files --- docker-compose.dev.yml | 2 ++ docker-compose.fluentd.yml | 2 ++ docker-compose.latest-thirdparty.yml | 2 ++ docker-compose.latest.yml | 3 ++- docker-compose.thirdparty.yml | 2 ++ docker-compose.yml | 2 ++ 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index da7e693f4..08efe1aa3 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -22,6 +22,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} @@ -81,6 +82,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 diff --git a/docker-compose.fluentd.yml b/docker-compose.fluentd.yml index cbd98d0e4..3f7c7e58f 100644 --- a/docker-compose.fluentd.yml +++ b/docker-compose.fluentd.yml @@ -35,6 +35,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} @@ -93,6 +94,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 diff --git a/docker-compose.latest-thirdparty.yml b/docker-compose.latest-thirdparty.yml index d1e6fbdad..0f1067777 100644 --- a/docker-compose.latest-thirdparty.yml +++ b/docker-compose.latest-thirdparty.yml @@ -48,6 +48,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} @@ -105,6 +106,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 diff --git a/docker-compose.latest.yml b/docker-compose.latest.yml index b861b5646..27bc6a4a3 100644 --- a/docker-compose.latest.yml +++ b/docker-compose.latest.yml @@ -21,8 +21,8 @@ services: environment: - *chaosgenius-version - IN_DOCKER=True - - REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO} - AIRBYTE_ENABLED=${AIRBYTE_ENABLED} + - REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO} - FLASK_APP=${FLASK_APP} - FLASK_ENV=${FLASK_ENV} - FLASK_DEBUG=${FLASK_DEBUG} @@ -80,6 +80,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 diff --git a/docker-compose.thirdparty.yml b/docker-compose.thirdparty.yml index eada6ee03..1104573f1 100644 --- a/docker-compose.thirdparty.yml +++ b/docker-compose.thirdparty.yml @@ -48,6 +48,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} @@ -105,6 +106,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 diff --git a/docker-compose.yml b/docker-compose.yml index 6da54b017..e64cf510d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,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} @@ -79,6 +80,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 From 1954e9aabfa66126ed20ecf33511f720bb5683f2 Mon Sep 17 00:00:00 2001 From: bhargav Date: Fri, 25 Mar 2022 18:06:24 +0530 Subject: [PATCH 18/25] style: format register_hooks function in app.py --- chaos_genius/app.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/chaos_genius/app.py b/chaos_genius/app.py index 826d7d61f..1abf2e1a5 100644 --- a/chaos_genius/app.py +++ b/chaos_genius/app.py @@ -120,19 +120,29 @@ def 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: + @app.before_request def before_request(): if request.endpoint not in DEMO_ENDPOINT_WHITELIST: - return jsonify({"status": "failure", - "message": "Endpoint not accessible in demo version"}) + 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"}) + return jsonify( + { + "status": "failure", + "message": f"{request.method} method is not allowed for this endpoint in demo version", + } + ) else: pass From 41636a7d8fdfedac0d2113441f6711a60fa8d0d9 Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Thu, 14 Apr 2022 10:15:08 +0530 Subject: [PATCH 19/25] added obfuscation for sycnc schema in Demo --- .../src/components/DataSourceTable/index.jsx | 2 +- frontend/src/redux/actions/DataSources.js | 38 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/DataSourceTable/index.jsx b/frontend/src/components/DataSourceTable/index.jsx index ca1cf028e..24c144c87 100644 --- a/frontend/src/components/DataSourceTable/index.jsx +++ b/frontend/src/components/DataSourceTable/index.jsx @@ -95,7 +95,7 @@ const DataSourceTable = ({ tableData, changeData, search }) => { }; const handleSync = (datasource) => { - dispatch(setSyncSchema(datasource)); + dispatch(setSyncSchema(datasource, customToast)); }; const customToast = (data) => { diff --git a/frontend/src/redux/actions/DataSources.js b/frontend/src/redux/actions/DataSources.js index af69a7ba8..95635e828 100644 --- a/frontend/src/redux/actions/DataSources.js +++ b/frontend/src/redux/actions/DataSources.js @@ -234,19 +234,33 @@ export const deleteDatasource = (id, customToast) => { }; }; -export const setSyncSchema = (datasource) => { - return async (dispatch) => { - dispatch(syncSchemaRequested()); - const { data, error, status } = await postRequest({ - url: METADATA_PREFETCH_URL, - data: { data_source_id: datasource?.id } - }); - if (error) { - dispatch(syncSchemaFailure()); - } else if (data && status === 200) { - dispatch(syncSchemaSuccess({ ...data, data_source_id: datasource?.id })); +export const setSyncSchema = (datasource, customToast) => { + if (env.REACT_APP_IS_DEMO === 'true') { + if (customToast) { + customToast({ + type: 'error', + header: 'This is a demo version' + }); } - }; + return { + type: 'default' + }; + } else { + return async (dispatch) => { + dispatch(syncSchemaRequested()); + const { data, error, status } = await postRequest({ + url: METADATA_PREFETCH_URL, + data: { data_source_id: datasource?.id } + }); + if (error) { + dispatch(syncSchemaFailure()); + } else if (data && status === 200) { + dispatch( + syncSchemaSuccess({ ...data, data_source_id: datasource?.id }) + ); + } + }; + } }; export const getDatasourceMetaInfoRequest = () => { From ce27e67bf6e87370b1d2b997b800886ea81aff86 Mon Sep 17 00:00:00 2001 From: bhargav Date: Thu, 14 Apr 2022 10:57:11 +0530 Subject: [PATCH 20/25] fix: Add download APIs to whitelist --- chaos_genius/utils/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/chaos_genius/utils/utils.py b/chaos_genius/utils/utils.py index 2fd5492e0..29923d014 100644 --- a/chaos_genius/utils/utils.py +++ b/chaos_genius/utils/utils.py @@ -84,6 +84,7 @@ def jsonable_encoder(obj): return jsonable_encoder(obj_dict) return pydantic_encoder(obj) + DEMO_ENDPOINT_WHITELIST = { "alert.alert_meta_info": ["GET"], "alert.get_alert_info_by_id": ["GET"], @@ -130,6 +131,10 @@ def jsonable_encoder(obj): "config_settings.edit_config_setting": ["PUT"], "dashboard.get_dashboard_list": ["GET"], "dashboard.get_dashboard": ["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", From 0d08b4f4f009c373a2bf7adbede50f59adf0a176 Mon Sep 17 00:00:00 2001 From: Debanjan Dey Date: Thu, 14 Apr 2022 11:17:03 +0530 Subject: [PATCH 21/25] resolved duplicate variables issues --- frontend/src/components/Anomaly/index.jsx | 31 ----------------------- 1 file changed, 31 deletions(-) diff --git a/frontend/src/components/Anomaly/index.jsx b/frontend/src/components/Anomaly/index.jsx index e55611524..b9df3b8ed 100644 --- a/frontend/src/components/Anomaly/index.jsx +++ b/frontend/src/components/Anomaly/index.jsx @@ -29,8 +29,6 @@ import store from '../../redux/store'; import SubdimensionEmpty from '../SubdimensionEmpty'; import EmptyDataQualityAnomaly from '../EmptyDataQualityAnomaly'; -import { useToast } from 'react-toast-wnm'; -import { CustomContent, CustomActions } from '../../utils/toast-helper'; import { downloadCsv } from '../../utils/download-helper'; import { anomalyDownloadCsv } from '../../redux/actions/Anomaly'; @@ -84,7 +82,6 @@ const Anomaly = ({ kpi, anomalystatus, dashboard }) => { }; const dispatch = useDispatch(); const history = useHistory(); - const toast = useToast(); const [chartData, setChartData] = useState([]); const [subDimLoading, setSubDimloading] = useState(true); const [retrainOn, setRetrainOn] = useState(false); @@ -484,34 +481,6 @@ const Anomaly = ({ kpi, anomalystatus, dashboard }) => { dispatch(anomalyDownloadCsv(kpi)); }; - const customToast = (data) => { - const { type, header, description } = data; - toast({ - autoDismiss: true, - enableAnimation: true, - delay: type === 'success' ? '5000' : '30000', - backgroundColor: type === 'success' ? '#effaf5' : '#FEF6F5', - borderRadius: '6px', - color: '#222222', - position: 'bottom-right', - minWidth: '240px', - width: 'auto', - boxShadow: '4px 6px 32px -2px rgba(226, 226, 234, 0.24)', - padding: '17px 14px', - height: 'auto', - border: type === 'success' ? '1px solid #60ca9a' : '1px solid #FEF6F5', - type: type, - actions: , - content: ( - - ) - }); - }; - return ( <> {retrainOn === true || anomalStatusInfo === true ? ( From 8f148ac4ae4adf0157dd787dceff48c7db84aa14 Mon Sep 17 00:00:00 2001 From: bhargav Date: Thu, 14 Apr 2022 12:08:38 +0530 Subject: [PATCH 22/25] fix: Add support timezone API to whitelist --- chaos_genius/utils/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/chaos_genius/utils/utils.py b/chaos_genius/utils/utils.py index 29923d014..45a1ed169 100644 --- a/chaos_genius/utils/utils.py +++ b/chaos_genius/utils/utils.py @@ -142,5 +142,6 @@ def jsonable_encoder(obj): # "static", # "status.static", # "status.task_monitor_view", + "meta.support_timezones": ["GET"], "meta.version_view": ["GET"], } From e6346c064d723aa8263b9aef2fcc40290a8b2134 Mon Sep 17 00:00:00 2001 From: Samyak S Sarnayak Date: Tue, 14 Jun 2022 17:56:31 +0530 Subject: [PATCH 23/25] chore(demo): add new summary endpoints to whitelist --- chaos_genius/utils/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chaos_genius/utils/utils.py b/chaos_genius/utils/utils.py index 45a1ed169..03f194408 100644 --- a/chaos_genius/utils/utils.py +++ b/chaos_genius/utils/utils.py @@ -120,6 +120,8 @@ def jsonable_encoder(obj): "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.set_config": ["POST"], From fb89c2d3ae56e80fd708cbbe15696bbb193bef49 Mon Sep 17 00:00:00 2001 From: Samyak S Sarnayak Date: Tue, 5 Jul 2022 17:22:04 +0530 Subject: [PATCH 24/25] fix(demo): update endpoint whitelist Disallowed: - Edit config - anonymous reporting and alert report time Allowed: - Alerts dashboard - Task monitor - Listing endpoints: - The checkboxes in the filter for KPI and alert screen were broken because of this --- chaos_genius/utils/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/chaos_genius/utils/utils.py b/chaos_genius/utils/utils.py index 03f194408..0934988a2 100644 --- a/chaos_genius/utils/utils.py +++ b/chaos_genius/utils/utils.py @@ -88,6 +88,8 @@ def jsonable_encoder(obj): 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"], @@ -110,6 +112,7 @@ def jsonable_encoder(obj): "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"], @@ -124,15 +127,17 @@ def jsonable_encoder(obj): "api_summary.kpi_get_line_data": ["GET"], "config_settings.get_all_config": ["GET"], "config_settings.get_config": ["POST"], - "config_settings.set_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"], - "config_settings.edit_config_setting": ["PUT"], + "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"], From 13e58dc3675c1a6244d2b15e07bac708b855a57d Mon Sep 17 00:00:00 2001 From: Samyak S Sarnayak Date: Mon, 29 Aug 2022 16:36:19 +0530 Subject: [PATCH 25/25] fix(demo): use a single level before_request hook Multi-level/nested was unnecessary and gave an error in debug mode: https://stackoverflow.com/questions/66190958/python-flask-framework-assertionerror-a-setup-function-was-called-after-the-fi --- chaos_genius/app.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/chaos_genius/app.py b/chaos_genius/app.py index 1deadcae3..22ef5db73 100644 --- a/chaos_genius/app.py +++ b/chaos_genius/app.py @@ -136,26 +136,23 @@ def register_hooks(app): def demo_endpoints_blocker(): """Hook to allow access to only whitelisted APIs in demo.""" if REACT_APP_IS_DEMO: - - @app.before_request - def before_request(): - if request.endpoint not in DEMO_ENDPOINT_WHITELIST: + 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": "Endpoint not accessible in demo version", + "message": f"{request.method} method is not allowed for this endpoint 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 + pass def register_commands(app):