Rename app.py to config.py
Browse files
app.py
DELETED
|
@@ -1,63 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import boto3
|
| 3 |
-
from flask import Flask, jsonify
|
| 4 |
-
|
| 5 |
-
# Load environment variables (from mounted secrets or defaults)
|
| 6 |
-
API_KEY = os.getenv("API_KEY")
|
| 7 |
-
S3_ENDPOINT_URL = os.getenv("S3_ENDPOINT_URL")
|
| 8 |
-
S3_ACCESS_KEY = os.getenv("S3_ACCESS_KEY")
|
| 9 |
-
S3_SECRET_KEY = os.getenv("S3_SECRET_KEY")
|
| 10 |
-
S3_BUCKET_NAME = os.getenv("S3_BUCKET_NAME")
|
| 11 |
-
S3_REGION = os.getenv("S3_REGION")
|
| 12 |
-
|
| 13 |
-
# Ensure required environment variables are present
|
| 14 |
-
if not API_KEY:
|
| 15 |
-
raise ValueError("API_KEY environment variable is not set")
|
| 16 |
-
if not S3_ENDPOINT_URL or not S3_ACCESS_KEY or not S3_SECRET_KEY or not S3_BUCKET_NAME or not S3_REGION:
|
| 17 |
-
raise ValueError("S3 environment variables are not fully set")
|
| 18 |
-
|
| 19 |
-
app = Flask(__name__)
|
| 20 |
-
|
| 21 |
-
# Setup S3 client
|
| 22 |
-
s3 = boto3.client(
|
| 23 |
-
"s3",
|
| 24 |
-
endpoint_url=S3_ENDPOINT_URL,
|
| 25 |
-
aws_access_key_id=S3_ACCESS_KEY,
|
| 26 |
-
aws_secret_access_key=S3_SECRET_KEY,
|
| 27 |
-
region_name=S3_REGION,
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
@app.route("/")
|
| 31 |
-
def home():
|
| 32 |
-
return jsonify({"message": "Welcome to No-Code Architect's Toolkit"})
|
| 33 |
-
|
| 34 |
-
@app.route("/list-files")
|
| 35 |
-
def list_files():
|
| 36 |
-
try:
|
| 37 |
-
response = s3.list_objects_v2(Bucket=S3_BUCKET_NAME)
|
| 38 |
-
contents = response.get("Contents", [])
|
| 39 |
-
filenames = [obj["Key"] for obj in contents]
|
| 40 |
-
return jsonify({"files": filenames})
|
| 41 |
-
except Exception as e:
|
| 42 |
-
return jsonify({"error": str(e)}), 500
|
| 43 |
-
|
| 44 |
-
@app.route("/v1/toolkit/test", methods=["GET"])
|
| 45 |
-
def test_toolkit():
|
| 46 |
-
return jsonify({"message": "Test route for toolkit"})
|
| 47 |
-
|
| 48 |
-
@app.route("/authenticate", methods=["GET"])
|
| 49 |
-
def authenticate():
|
| 50 |
-
return jsonify({"message": "Authentication endpoint"})
|
| 51 |
-
|
| 52 |
-
@app.route("/v1/ffmpeg/compose", methods=["POST"])
|
| 53 |
-
def ffmpeg_compose():
|
| 54 |
-
# Placeholder for your FFmpeg logic
|
| 55 |
-
return jsonify({"message": "FFmpeg compose endpoint"})
|
| 56 |
-
|
| 57 |
-
# List all available routes (for debugging purposes)
|
| 58 |
-
@app.route("/routes", methods=["GET"])
|
| 59 |
-
def list_routes():
|
| 60 |
-
return jsonify({"routes": [str(rule) for rule in app.url_map.iter_rules()]})
|
| 61 |
-
|
| 62 |
-
if __name__ == "__main__":
|
| 63 |
-
app.run(host="0.0.0.0", port=8080)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
def get_env_var(name: str, required=True, default=None):
|
| 4 |
+
value = os.getenv(name, default)
|
| 5 |
+
if required and not value:
|
| 6 |
+
raise EnvironmentError(f"Missing required environment variable: {name}")
|
| 7 |
+
return value
|
| 8 |
+
|
| 9 |
+
API_KEY = get_env_var("API_KEY")
|
| 10 |
+
S3_ENDPOINT_URL = get_env_var("S3_ENDPOINT_URL")
|
| 11 |
+
S3_ACCESS_KEY = get_env_var("S3_ACCESS_KEY")
|
| 12 |
+
S3_SECRET_KEY = get_env_var("S3_SECRET_KEY")
|
| 13 |
+
S3_BUCKET_NAME = get_env_var("S3_BUCKET_NAME")
|
| 14 |
+
S3_REGION = get_env_var("S3_REGION")
|