11import re
2- from flask . globals import current_app
2+ from logging import Logger
33
4+ from flask .globals import current_app
45from flask_restful import Resource , abort
56from flask import request , jsonify
67from urllib .parse import urljoin
78
9+ from pbench .server import PbenchServerConfig
810from pbench .server .api .resources .query_apis import get_index_prefix
911
1012
@@ -15,17 +17,17 @@ class EndpointConfig(Resource):
1517 config file.
1618 """
1719
18- forward_pattern = re .compile (r";\s*host\s*=\s*(?P<host>[^;\s]* )" )
19- x_forward_pattern = re .compile (r"^ \s*(?P<host>[^;\s,]* )" )
20- param_template = re .compile (r"<[\w_\d]+:[\d_\w] +>" )
20+ forward_pattern = re .compile (r";\s*host\s*=\s*(?P<host>[^;\s]+ )" )
21+ x_forward_pattern = re .compile (r"\s*(?P<host>[^;\s,]+ )" )
22+ param_template = re .compile (r"<\w+:\w +>" )
2123
22- def __init__ (self , config , logger ):
24+ def __init__ (self , config : PbenchServerConfig , logger : Logger ):
2325 """
2426 __init__ Construct the API resource
2527
2628 Args:
27- config (PbenchServerConfig) : server config values
28- logger (Logger) : message logging
29+ : config: server config values
30+ : logger: message logging
2931
3032 Report the server configuration to a web client. By default, the Pbench
3133 server ansible script sets up a local Apache reverse proxy routing
@@ -46,8 +48,9 @@ def get(self):
4648 Return server configuration information required by web clients
4749 including the Pbench dashboard UI. This includes:
4850
49- metadata: Information about the server configuration
50- identification: The Pbench server name and version
51+ indices: Information about the server's ES indices. (NOTE: once
52+ we've removed all direct Elasticsearch queries from the
53+ dashboard, these won't be necessary.)
5154 result_index: The "root" index name for Pbench result data,
5255 qualified by the current index version and prefix. In the
5356 current ES schema, this is "v5.result-data-sample."
@@ -59,6 +62,7 @@ def get(self):
5962 schema, this is "v6.run-data."
6063 run_toc_index: The Elasticsearch V7 index for run TOC data. In
6164 the current ES schema, this is "v6.run-toc."
65+ identification: The Pbench server name and version
6266 api: A dict of the server APIs supported; we give a name, which
6367 identifies the service, and the full URI relative to the
6468 configured host name and port (local or remote reverse proxy).
@@ -95,7 +99,7 @@ def get(self):
9599 if not origin :
96100 header = request .headers .get ("X-Forwarded-Host" )
97101 if header :
98- m = self .x_forward_pattern .search (header )
102+ m = self .x_forward_pattern .match (header )
99103 if m :
100104 origin = m .group ("host" )
101105 host_source = "X-Forwarded-Host"
@@ -137,9 +141,7 @@ def get(self):
137141 # which we're not currently using anywhere; but it'll require
138142 # adjustment later if we add any. (E.g., something like
139143 # "/api/v1/foo/<string:name>/detail/<string:param>")
140- m = re .search (self .param_template , url )
141- if m :
142- url = re .sub (self .param_template , "" , url )
144+ url = self .param_template .sub ("" , url )
143145 path = url [len (self .uri_prefix ) + 1 :]
144146 if path .endswith ("/" ):
145147 path = path [:- 1 ]
0 commit comments