Skip to content

Commit 17f9894

Browse files
feat(myopencre): gate MyOpenCRE behind deployment capability flag
1 parent f56c2f9 commit 17f9894

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

application/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22

33
basedir = os.path.abspath(os.path.dirname(__file__))
4+
ENABLE_MYOPENCRE = os.getenv("ENABLE_MYOPENCRE", "false").lower() == "true"
45

56

67
class Config:

application/web/web_main.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from google.oauth2 import id_token
4343
from google_auth_oauthlib.flow import Flow
4444
from application.utils.spreadsheet import write_csv
45+
from application.config import ENABLE_MYOPENCRE
4546
import oauthlib
4647
import google.auth.transport.requests
4748

@@ -127,6 +128,11 @@ def neo4j_not_running_rejection():
127128
)
128129

129130

131+
@app.route("/api/capabilities")
132+
def capabilities():
133+
return jsonify({"myopencre": ENABLE_MYOPENCRE})
134+
135+
130136
@app.route("/rest/v1/id/<creid>", methods=["GET"])
131137
@app.route("/rest/v1/name/<crename>", methods=["GET"])
132138
def find_cre(creid: str = None, crename: str = None) -> Any: # refer
@@ -827,22 +833,21 @@ def all_cres() -> Any:
827833

828834
@app.route("/rest/v1/cre_csv", methods=["GET"])
829835
def get_cre_csv() -> Any:
836+
if not ENABLE_MYOPENCRE:
837+
abort(404)
830838
if posthog:
831839
posthog.capture(f"get_cre_csv", "")
832-
833840
database = db.Node_collection()
834841
root_cres = database.get_root_cres()
835842
if root_cres:
836843
docs = sheet_utils.generate_mapping_template_file(
837844
database=database, docs=root_cres
838845
)
839846
csvVal = write_csv(docs=docs).getvalue().encode("utf-8")
840-
841847
# Creating the byteIO object from the StringIO Object
842848
mem = io.BytesIO()
843849
mem.write(csvVal)
844850
mem.seek(0)
845-
846851
return send_file(
847852
mem,
848853
as_attachment=True,
@@ -854,6 +859,9 @@ def get_cre_csv() -> Any:
854859

855860
@app.route("/rest/v1/cre_csv_import", methods=["POST"])
856861
def import_from_cre_csv() -> Any:
862+
if not ENABLE_MYOPENCRE:
863+
abort(404)
864+
857865
if not os.environ.get("CRE_ALLOW_IMPORT"):
858866
abort(
859867
403,

0 commit comments

Comments
 (0)