Add lab-02-security-as-a-system
This commit is contained in:
1 parent
dcf58ecf2a
commit
3213ab1435
10 files changed
+652
No files matched your search
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
from service_common import record_event
|
||||
|
||||
|
||||
HOST = os.environ["MINICORP_SERVICE_HOST"]
|
||||
PORT = int(os.environ["MINICORP_SERVICE_PORT"])
|
||||
|
||||
SERVICE_ID = os.environ["MINICORP_SERVICE_ID"]
|
||||
SERVICE_TOKEN = os.environ["MINICORP_SERVICE_TOKEN"]
|
||||
|
||||
EVIDENCE_LOG = os.environ["MINICORP_EVIDENCE_LOG"]
|
||||
|
||||
|
||||
class AdminHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
if self.path != "/":
|
||||
self.send_error(404)
|
||||
return
|
||||
|
||||
source = self.client_address[0]
|
||||
|
||||
record_event(
|
||||
EVIDENCE_LOG,
|
||||
service="admin",
|
||||
service_token=SERVICE_TOKEN,
|
||||
source=source,
|
||||
port=PORT,
|
||||
)
|
||||
|
||||
body = (
|
||||
"MiniCorp Administration Service\n"
|
||||
f"service_id: {SERVICE_ID}\n"
|
||||
"environment: production\n"
|
||||
"debug: enabled\n"
|
||||
"backend: inventory-api\n"
|
||||
).encode("utf-8")
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header(
|
||||
"Content-Type",
|
||||
"text/plain; charset=utf-8",
|
||||
)
|
||||
self.send_header(
|
||||
"Content-Length",
|
||||
str(len(body)),
|
||||
)
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, format, *args):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
server = ThreadingHTTPServer(
|
||||
(HOST, PORT),
|
||||
AdminHandler,
|
||||
)
|
||||
|
||||
print(
|
||||
f"MiniCorp admin service listening on {HOST}:{PORT}"
|
||||
)
|
||||
|
||||
server.serve_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user