feat: Add Dockerfile and app.py for iac-ssh-authorized-keys service
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# Use the official Python image from the Docker Hub
|
||||
FROM python:3.9-slim
|
||||
|
||||
# Set environment variable for Python
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Install Flask
|
||||
RUN pip install flask
|
||||
|
||||
# Create a directory for the app
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the app files
|
||||
COPY . /app
|
||||
|
||||
# Expose port 8080
|
||||
EXPOSE 8080
|
||||
|
||||
# Run the application
|
||||
CMD ["python", "app.py"]
|
||||
@@ -0,0 +1,30 @@
|
||||
from flask import Flask, request, jsonify
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
API_KEY = os.getenv("API_KEY")
|
||||
AUTHORIZED_KEYS_PATH = "/authorized_keys"
|
||||
|
||||
|
||||
@app.route("/", methods=["POST"])
|
||||
def root():
|
||||
data = request.get_json()
|
||||
api_key = data.get("API_KEY")
|
||||
file_contents = data.get("FILE_CONTENTS")
|
||||
|
||||
if api_key == API_KEY:
|
||||
try:
|
||||
with open(AUTHORIZED_KEYS_PATH, "w") as f:
|
||||
f.write(file_contents + "\n")
|
||||
return jsonify({"message": "File contents overwritten successfully"}), 200
|
||||
except Exception as e:
|
||||
return jsonify({"message": f"Failed to write to file: {str(e)}"}), 500
|
||||
else:
|
||||
return jsonify({"message": "Unauthorized"}), 401
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if API_KEY is None:
|
||||
raise ValueError("API_KEY environment variable is not set")
|
||||
app.run(host="0.0.0.0", port=8080)
|
||||
@@ -16,7 +16,9 @@ wifi:
|
||||
dns1: 1.1.1.1
|
||||
dns2: 8.8.8.8
|
||||
power_save_mode: none
|
||||
|
||||
ap:
|
||||
ssid: "Slaapkamer Fallback Hotspot"
|
||||
password: !secret hotspot_password
|
||||
captive_portal:
|
||||
|
||||
logger:
|
||||
|
||||
Reference in New Issue
Block a user