1
1
import re
2
- from flask . globals import current_app
2
+ from logging import Logger
3
3
4
+ from flask .globals import current_app
4
5
from flask_restful import Resource , abort
5
6
from flask import request , jsonify
6
7
from urllib .parse import urljoin
7
8
9
+ from pbench .server import PbenchServerConfig
8
10
from pbench .server .api .resources .query_apis import get_index_prefix
9
11
10
12
@@ -15,17 +17,17 @@ class EndpointConfig(Resource):
15
17
config file.
16
18
"""
17
19
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 +>" )
21
23
22
- def __init__ (self , config , logger ):
24
+ def __init__ (self , config : PbenchServerConfig , logger : Logger ):
23
25
"""
24
26
__init__ Construct the API resource
25
27
26
28
Args:
27
- config (PbenchServerConfig) : server config values
28
- logger (Logger) : message logging
29
+ : config: server config values
30
+ : logger: message logging
29
31
30
32
Report the server configuration to a web client. By default, the Pbench
31
33
server ansible script sets up a local Apache reverse proxy routing
@@ -46,8 +48,9 @@ def get(self):
46
48
Return server configuration information required by web clients
47
49
including the Pbench dashboard UI. This includes:
48
50
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.)
51
54
result_index: The "root" index name for Pbench result data,
52
55
qualified by the current index version and prefix. In the
53
56
current ES schema, this is "v5.result-data-sample."
@@ -59,6 +62,7 @@ def get(self):
59
62
schema, this is "v6.run-data."
60
63
run_toc_index: The Elasticsearch V7 index for run TOC data. In
61
64
the current ES schema, this is "v6.run-toc."
65
+ identification: The Pbench server name and version
62
66
api: A dict of the server APIs supported; we give a name, which
63
67
identifies the service, and the full URI relative to the
64
68
configured host name and port (local or remote reverse proxy).
@@ -95,7 +99,7 @@ def get(self):
95
99
if not origin :
96
100
header = request .headers .get ("X-Forwarded-Host" )
97
101
if header :
98
- m = self .x_forward_pattern .search (header )
102
+ m = self .x_forward_pattern .match (header )
99
103
if m :
100
104
origin = m .group ("host" )
101
105
host_source = "X-Forwarded-Host"
@@ -137,9 +141,7 @@ def get(self):
137
141
# which we're not currently using anywhere; but it'll require
138
142
# adjustment later if we add any. (E.g., something like
139
143
# "/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 )
143
145
path = url [len (self .uri_prefix ) + 1 :]
144
146
if path .endswith ("/" ):
145
147
path = path [:- 1 ]
0 commit comments