From 3adde72a2d7207f31994b3e15acb3f72c7985ca9 Mon Sep 17 00:00:00 2001
From: rohit sohlot <5600987+rsohlot@users.noreply.github.com>
Date: Wed, 2 Mar 2022 08:21:19 +0530
Subject: [PATCH 1/5] feature: configure CORS

---
 .env                                 |  2 +-
 .gitignore                           |  4 ++++
 .vscode/launch.json                  | 25 +++++++++++++++++++++++++
 chaos_genius/app.py                  |  9 ++++++++-
 chaos_genius/settings.py             |  1 +
 docker-compose.dev.yml               |  1 +
 docker-compose.fluentd.yml           |  1 +
 docker-compose.latest-thirdparty.yml |  1 +
 docker-compose.latest.yml            |  1 +
 docker-compose.thirdparty.yml        |  1 +
 docker-compose.yml                   |  1 +
 11 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 .vscode/launch.json

diff --git a/.env b/.env
index ca622a308..dd4d3643c 100644
--- a/.env
+++ b/.env
@@ -26,7 +26,7 @@ INTEGRATION_DATABASE=chaosgenius_data
 CELERY_RESULT_BACKEND=redis://chaosgenius-redis:6379/1
 CELERY_BROKER_URL=redis://chaosgenius-redis:6379/1
 CHAOSGENIUS_WEBAPP_URL=http://localhost:8080/
-
+CORS_ENABLED=False
 # Alert configuration
 ## to enable event alerts
 REACT_APP_EVENT_ALERT=false
diff --git a/.gitignore b/.gitignore
index 678db6de1..c114f4c2a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -345,3 +345,7 @@ docs/yarn-error.log*
 ########### Third Party Integrations ##########
 .integrations.json
 .connectors
+
+# IDE configuration
+.idea/* # IntelliJ IDEA
+.vscode/* # Visual Studio Code
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 000000000..713cff930
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,25 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Python: Flask",
+            "type": "python",
+            "request": "launch",
+            "module": "flask",
+            "env": {
+                "FLASK_APP": "${workspaceFolder}/chaos_genius/app.py",
+                "FLASK_ENV": "development"
+            },
+            "args": [
+                "run",
+                "--no-debugger",
+                "--port",
+                "3000"
+            ],
+            "jinja": true
+        }
+    ]
+}
\ No newline at end of file
diff --git a/chaos_genius/app.py b/chaos_genius/app.py
index b4142c5e5..179349e6a 100644
--- a/chaos_genius/app.py
+++ b/chaos_genius/app.py
@@ -49,10 +49,17 @@ def create_app(config_object="chaos_genius.settings"):
     register_shellcontext(app)
     register_commands(app)
     configure_logger(app)
-    CORS(app) # TODO: Remove the CORS in v1 release
+    configure_cross_origin_request(app)
     return app
 
 
+def configure_cross_origin_request(app):
+    """Configure cross origin request."""
+    if app.config['CORS_ENABLED']:
+        CORS(app)
+    return None
+
+
 def register_extensions(app):
     """Register Flask extensions."""
     bcrypt.init_app(app)
diff --git a/chaos_genius/settings.py b/chaos_genius/settings.py
index d8b0b5f39..8419c50b5 100644
--- a/chaos_genius/settings.py
+++ b/chaos_genius/settings.py
@@ -48,6 +48,7 @@ def _make_bool(val: Union[str, bool]) -> bool:
 CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND')
 CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL')
 CHAOSGENIUS_WEBAPP_URL = os.getenv("CHAOSGENIUS_WEBAPP_URL")
+CORS_ENABLED = _make_bool(os.getenv("CORS_ENABLED", default=False))
 
 EMAIL_HOST = os.getenv('EMAIL_HOST')
 EMAIL_HOST_PORT = os.getenv('EMAIL_HOST_PORT', default=587)
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 779a1baef..6819f8fa0 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -63,6 +63,7 @@ services:
       - SENTRY_DSN=${SENTRY_DSN}
       - CHAOSGENIUS_ENTERPRISE_EDITION_KEY=${CHAOSGENIUS_ENTERPRISE_EDITION_KEY}
       - CHAOSGENIUS_WEBAPP_URL=${CHAOSGENIUS_WEBAPP_URL}
+      - CORS_ENABLED=${CORS_ENABLED}
 
   chaosgenius-webapp:
     container_name: chaosgenius-webapp
diff --git a/docker-compose.fluentd.yml b/docker-compose.fluentd.yml
index 84c13ed08..3c7a209c5 100644
--- a/docker-compose.fluentd.yml
+++ b/docker-compose.fluentd.yml
@@ -76,6 +76,7 @@ services:
       - SENTRY_DSN=${SENTRY_DSN}
       - CHAOSGENIUS_ENTERPRISE_EDITION_KEY=${CHAOSGENIUS_ENTERPRISE_EDITION_KEY}
       - CHAOSGENIUS_WEBAPP_URL=${CHAOSGENIUS_WEBAPP_URL}
+      - CORS_ENABLED=${CORS_ENABLED}
     logging: *default-logging
 
   chaosgenius-webapp:
diff --git a/docker-compose.latest-thirdparty.yml b/docker-compose.latest-thirdparty.yml
index 1fe937fc5..c55e6d65f 100644
--- a/docker-compose.latest-thirdparty.yml
+++ b/docker-compose.latest-thirdparty.yml
@@ -89,6 +89,7 @@ services:
       - SENTRY_DSN=${SENTRY_DSN}
       - CHAOSGENIUS_ENTERPRISE_EDITION_KEY=${CHAOSGENIUS_ENTERPRISE_EDITION_KEY}
       - CHAOSGENIUS_WEBAPP_URL=${CHAOSGENIUS_WEBAPP_URL}
+      - CORS_ENABLED=${CORS_ENABLED}
 
   chaosgenius-webapp:
     container_name: chaosgenius-webapp
diff --git a/docker-compose.latest.yml b/docker-compose.latest.yml
index b5049e384..d3e750810 100644
--- a/docker-compose.latest.yml
+++ b/docker-compose.latest.yml
@@ -63,6 +63,7 @@ services:
       - SENTRY_DSN=${SENTRY_DSN}
       - CHAOSGENIUS_ENTERPRISE_EDITION_KEY=${CHAOSGENIUS_ENTERPRISE_EDITION_KEY}
       - CHAOSGENIUS_WEBAPP_URL=${CHAOSGENIUS_WEBAPP_URL}
+      - CORS_ENABLED=${CORS_ENABLED}
 
   chaosgenius-webapp:
     container_name: chaosgenius-webapp
diff --git a/docker-compose.thirdparty.yml b/docker-compose.thirdparty.yml
index 0453150db..d9dc34831 100644
--- a/docker-compose.thirdparty.yml
+++ b/docker-compose.thirdparty.yml
@@ -89,6 +89,7 @@ services:
       - SENTRY_DSN=${SENTRY_DSN}
       - CHAOSGENIUS_ENTERPRISE_EDITION_KEY=${CHAOSGENIUS_ENTERPRISE_EDITION_KEY}
       - CHAOSGENIUS_WEBAPP_URL=${CHAOSGENIUS_WEBAPP_URL}
+      - CORS_ENABLED=${CORS_ENABLED}
 
   chaosgenius-webapp:
     container_name: chaosgenius-webapp
diff --git a/docker-compose.yml b/docker-compose.yml
index 6606503fe..14a2fe8c1 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -63,6 +63,7 @@ services:
       - SENTRY_DSN=${SENTRY_DSN}
       - CHAOSGENIUS_ENTERPRISE_EDITION_KEY=${CHAOSGENIUS_ENTERPRISE_EDITION_KEY}
       - CHAOSGENIUS_WEBAPP_URL=${CHAOSGENIUS_WEBAPP_URL}
+      - CORS_ENABLED=${CORS_ENABLED}
 
   chaosgenius-webapp:
     container_name: chaosgenius-webapp

From 51d299cffc1490ada84ed127997f25d22697ce0c Mon Sep 17 00:00:00 2001
From: rohit sohlot <5600987+rsohlot@users.noreply.github.com>
Date: Sat, 30 Apr 2022 19:22:24 +0530
Subject: [PATCH 2/5] removing launch.json

---
 .gitignore          |  2 +-
 .vscode/launch.json | 25 -------------------------
 2 files changed, 1 insertion(+), 26 deletions(-)
 delete mode 100644 .vscode/launch.json

diff --git a/.gitignore b/.gitignore
index 8b7adb80e..2a04000dd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -348,4 +348,4 @@ docs/yarn-error.log*
 
 ########### Gitpod #########################
 
-dump.rdb
+dump.rdb
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
deleted file mode 100644
index 713cff930..000000000
--- a/.vscode/launch.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
-    // Use IntelliSense to learn about possible attributes.
-    // Hover to view descriptions of existing attributes.
-    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
-    "version": "0.2.0",
-    "configurations": [
-        {
-            "name": "Python: Flask",
-            "type": "python",
-            "request": "launch",
-            "module": "flask",
-            "env": {
-                "FLASK_APP": "${workspaceFolder}/chaos_genius/app.py",
-                "FLASK_ENV": "development"
-            },
-            "args": [
-                "run",
-                "--no-debugger",
-                "--port",
-                "3000"
-            ],
-            "jinja": true
-        }
-    ]
-}
\ No newline at end of file

From 173f147220f545405c7a3c530399d6c86b159f17 Mon Sep 17 00:00:00 2001
From: rohit sohlot <5600987+rsohlot@users.noreply.github.com>
Date: Sat, 30 Apr 2022 19:24:51 +0530
Subject: [PATCH 3/5] added cors flag to dev-thirdparty-docker

---
 docker-compose.dev-thirdparty.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docker-compose.dev-thirdparty.yml b/docker-compose.dev-thirdparty.yml
index 513e35d56..f5bdcf24d 100644
--- a/docker-compose.dev-thirdparty.yml
+++ b/docker-compose.dev-thirdparty.yml
@@ -94,6 +94,7 @@ services:
       - SENTRY_DSN=${SENTRY_DSN}
       - CHAOSGENIUS_ENTERPRISE_EDITION_KEY=${CHAOSGENIUS_ENTERPRISE_EDITION_KEY}
       - CHAOSGENIUS_WEBAPP_URL=${CHAOSGENIUS_WEBAPP_URL}
+      - CORS_ENABLED=${CORS_ENABLED}
 
   chaosgenius-webapp:
     container_name: chaosgenius-webapp

From c4b8fab1c02ad271de98ab0d415d332f852df136 Mon Sep 17 00:00:00 2001
From: rohit sohlot <5600987+rsohlot@users.noreply.github.com>
Date: Sat, 30 Apr 2022 19:27:08 +0530
Subject: [PATCH 4/5] rename cors config fn name

---
 chaos_genius/app.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/chaos_genius/app.py b/chaos_genius/app.py
index 5f20cedb0..49f0627c5 100644
--- a/chaos_genius/app.py
+++ b/chaos_genius/app.py
@@ -50,12 +50,12 @@ def create_app(config_object="chaos_genius.settings"):
     register_shellcontext(app)
     register_commands(app)
     configure_logger(app)
-    configure_cross_origin_request(app)
+    configure_cors(app)
     return app
 
 
-def configure_cross_origin_request(app):
-    """Configure cross origin request."""
+def configure_cors(app):
+    """Configure cross origin request sharing."""
     if app.config['CORS_ENABLED']:
         CORS(app)
     return None

From e7cf3d9c51e8dc4ba36755163d367742e2837931 Mon Sep 17 00:00:00 2001
From: rohit sohlot <5600987+rsohlot@users.noreply.github.com>
Date: Sat, 30 Apr 2022 19:28:22 +0530
Subject: [PATCH 5/5] change quote

---
 chaos_genius/app.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/chaos_genius/app.py b/chaos_genius/app.py
index 49f0627c5..93f8cd31a 100644
--- a/chaos_genius/app.py
+++ b/chaos_genius/app.py
@@ -56,7 +56,7 @@ def create_app(config_object="chaos_genius.settings"):
 
 def configure_cors(app):
     """Configure cross origin request sharing."""
-    if app.config['CORS_ENABLED']:
+    if app.config["CORS_ENABLED"]:
         CORS(app)
     return None