Skip to content

Commit 6a0dd3e

Browse files
feat(myopencre): gate MyOpenCRE behind deployment capability flag
1 parent fb28a95 commit 6a0dd3e

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
@@ -41,6 +41,7 @@
4141
from google.oauth2 import id_token
4242
from google_auth_oauthlib.flow import Flow
4343
from application.utils.spreadsheet import write_csv
44+
from application.config import ENABLE_MYOPENCRE
4445
import oauthlib
4546
import google.auth.transport.requests
4647

@@ -106,6 +107,11 @@ def neo4j_not_running_rejection():
106107
)
107108

108109

110+
@app.route("/api/capabilities")
111+
def capabilities():
112+
return jsonify({"myopencre": ENABLE_MYOPENCRE})
113+
114+
109115
@app.route("/rest/v1/id/<creid>", methods=["GET"])
110116
@app.route("/rest/v1/name/<crename>", methods=["GET"])
111117
def find_cre(creid: str = None, crename: str = None) -> Any: # refer
@@ -764,22 +770,21 @@ def all_cres() -> Any:
764770

765771
@app.route("/rest/v1/cre_csv", methods=["GET"])
766772
def get_cre_csv() -> Any:
773+
if not ENABLE_MYOPENCRE:
774+
abort(404)
767775
if posthog:
768776
posthog.capture(f"get_cre_csv", "")
769-
770777
database = db.Node_collection()
771778
root_cres = database.get_root_cres()
772779
if root_cres:
773780
docs = sheet_utils.generate_mapping_template_file(
774781
database=database, docs=root_cres
775782
)
776783
csvVal = write_csv(docs=docs).getvalue().encode("utf-8")
777-
778784
# Creating the byteIO object from the StringIO Object
779785
mem = io.BytesIO()
780786
mem.write(csvVal)
781787
mem.seek(0)
782-
783788
return send_file(
784789
mem,
785790
as_attachment=True,
@@ -791,6 +796,9 @@ def get_cre_csv() -> Any:
791796

792797
@app.route("/rest/v1/cre_csv_import", methods=["POST"])
793798
def import_from_cre_csv() -> Any:
799+
if not ENABLE_MYOPENCRE:
800+
abort(404)
801+
794802
if not os.environ.get("CRE_ALLOW_IMPORT"):
795803
abort(
796804
403,

0 commit comments

Comments
 (0)