-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathspecial_component.py
48 lines (40 loc) · 1.56 KB
/
special_component.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import falcon
import falcon.asgi
import features
import middleware.auth
@middleware.auth.noauth
class CurrentDependencies():
required_features = (features.FeatureSpecialComponents,)
def __init__(
self,
special_component_callback,
github_api_lookup,
):
self.special_component_callback = special_component_callback
self.github_api_lookup = github_api_lookup
def on_get(self, req: falcon.asgi.Request, resp: falcon.asgi.Response):
component_name = req.get_param('component_name', True)
component_cfg = self.special_component_callback(component_name=component_name)
if not component_cfg:
resp.media = {}
return
resolved_dependencies = []
for dependency in component_cfg.dependencies or []:
resolved_dependency = {
'name': dependency.name,
'displayName': dependency.displayName,
}
if (dependency.currentVersion):
resolved_dependency['version'] = dependency.currentVersion.retrieve(
github_api_lookup=self.github_api_lookup,
)
resolved_dependencies.append(resolved_dependency)
resp_media = {
'displayName': component_cfg.displayName,
'component_dependencies': resolved_dependencies
}
if component_cfg.currentVersion:
resp_media['version'] = component_cfg.currentVersion.retrieve(
github_api_lookup=self.github_api_lookup,
)
resp.media = resp_media