forked from hjacobs/kube-resource-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication-registry.py
executable file
·48 lines (37 loc) · 1.43 KB
/
application-registry.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
#!/usr/bin/env python3
"""
This is an example application registry with test data.
Run this script and use --application-registry=http://localhost:8080
"""
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
DATA = {
"example-app": {"team_id": "example-team", "active": True},
"legacy-service": {"team_id": "example-team", "active": False},
"kube-ops-view": {"team_id": "hjacobs", "active": True},
"kube-resource-report": {"team_id": "hjacobs", "active": True},
"application-registry": {"team_id": "hjacobs", "active": True},
}
class HTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/health":
self.send_response(200)
self.end_headers()
return
elif not self.path.startswith("/apps/"):
self.send_response(404)
self.end_headers()
return
parts = self.path.split("/")
application_id = parts[2]
data = DATA.get(application_id)
self.send_response(200 if data else 404)
self.send_header("Content-type", "application/json")
self.end_headers()
serialized = json.dumps(data)
self.wfile.write(bytes(serialized, "utf-8"))
if __name__ == "__main__":
server_address = ("0.0.0.0", 8080)
httpd = HTTPServer(server_address, HTTPServer_RequestHandler)
print("Listening on {}:{}..".format(*server_address))
httpd.serve_forever()