31 lines
877 B
Python
31 lines
877 B
Python
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)
|