@@ -16,6 +16,7 @@ def populate_api():
1616from datetime import datetime
1717import inspect
1818import traceback
19+ import os
1920try:
2021 from .component_interface_override import type_map
2122except (ModuleNotFoundError, ImportError):
@@ -37,13 +38,35 @@ def {method_name}(jwt_payload: dict) -> dict:
3738 except Exception as e:
3839 return traceback.format_exc(), 500
3940"""
41+ route_template_nologin = """
42+
43+ @app.route('{route}', methods=['GET'])
44+ def {method_name}() -> dict:
45+ if request.method in {{'GET'}}:
46+ jwt_payload = dict(
47+ databaseAddress=os.environ["PHARUS_HOST"],
48+ username=os.environ["PHARUS_USER"],
49+ password=os.environ["PHARUS_PASSWORD"],
50+ )
51+ try:
52+ component_instance = type_map['{component_type}'](name='{component_name}',
53+ component_config={component},
54+ static_config={static_config},
55+ jwt_payload=jwt_payload)
56+ return component_instance.{method_name_type}()
57+ except Exception as e:
58+ return traceback.format_exc(), 500
59+ """
4060
4161 pharus_root = f"{ pkg_resources .get_distribution ('pharus' ).module_path } /pharus"
4262 api_path = f"{ pharus_root } /dynamic_api.py"
4363 spec_path = os .environ .get ("PHARUS_SPEC_PATH" )
4464 values_yaml = EnvYAML (Path (spec_path ))
4565 with open (Path (api_path ), "w" ) as f :
4666 f .write (header_template )
67+ active_route_template = (
68+ route_template if values_yaml ["SciViz" ]["auth" ] else route_template_nologin
69+ )
4770 if (
4871 "component_interface" in values_yaml ["SciViz" ]
4972 and "override" in values_yaml ["SciViz" ]["component_interface" ]
@@ -74,10 +97,10 @@ def {method_name}(jwt_payload: dict) -> dict:
7497 for grid in page ["grids" ].values ():
7598 if grid ["type" ] == "dynamic" :
7699 f .write (
77- route_template .format (
100+ ( active_route_template ) .format (
78101 route = grid ["route" ],
79102 method_name = grid ["route" ].replace ("/" , "" ),
80- component_type = "table " ,
103+ component_type = "basicquery " ,
81104 component_name = "dynamicgrid" ,
82105 component = json .dumps (grid ),
83106 static_config = static_config ,
@@ -90,9 +113,12 @@ def {method_name}(jwt_payload: dict) -> dict:
90113 if "component_templates" in grid
91114 else grid ["components" ]
92115 ).items ():
93- if re .match (r"^(table|metadata|plot|file).*$" , comp ["type" ]):
116+ if re .match (
117+ r"^(table|metadata|plot|file|slider|dropdown-query).*$" ,
118+ comp ["type" ],
119+ ):
94120 f .write (
95- route_template .format (
121+ ( active_route_template ) .format (
96122 route = comp ["route" ],
97123 method_name = comp ["route" ].replace ("/" , "" ),
98124 component_type = comp ["type" ],
@@ -107,7 +133,7 @@ def {method_name}(jwt_payload: dict) -> dict:
107133 comp ["type" ]
108134 ].attributes_route_format .format (route = comp ["route" ])
109135 f .write (
110- route_template .format (
136+ ( active_route_template ) .format (
111137 route = attributes_route ,
112138 method_name = attributes_route .replace ("/" , "" ),
113139 component_type = comp ["type" ],
0 commit comments