Add swagger
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
dvirlabs 2026-04-23 12:04:26 +03:00
parent 73dcb60583
commit 68255eb274
2 changed files with 114 additions and 6 deletions

119
app.py
View File

@ -9,8 +9,10 @@ import json
import logging
from flask import Flask, request, jsonify
from datetime import datetime
from flasgger import Swagger
app = Flask(__name__)
swagger = Swagger(app)
# Configuration from environment
STATUS_FILE = os.environ.get('STATUS_FILE', '/data/status.json')
@ -65,7 +67,39 @@ def save_status(status):
@app.route('/status.json', methods=['GET'])
def get_status():
"""GET /status.json - Retrieve current status"""
"""
GET /status.json - Retrieve current status
---
responses:
200:
description: Current GitOps status
schema:
type: object
properties:
repo:
type: string
example: "rsyslog"
server:
type: string
example: "rsyslog-lab"
sync_status:
type: string
enum: ["SYNCED", "OUT_OF_SYNC", "UNKNOWN"]
drift_count:
type: integer
example: 0
files:
type: array
items:
type: object
properties:
name:
type: string
last_check:
type: string
format: date-time
example: "2026-04-23T10:30:00Z"
"""
try:
status = load_status()
if status:
@ -80,8 +114,61 @@ def get_status():
@app.route('/api/status', methods=['GET', 'POST', 'OPTIONS'])
def api_status():
"""
GET /api/status - Retrieve current status
POST /api/status - Update status with new data
GitOps Status API endpoint
---
get:
summary: Retrieve current status
responses:
200:
description: Current GitOps status
schema:
type: object
properties:
repo:
type: string
server:
type: string
sync_status:
type: string
drift_count:
type: integer
files:
type: array
last_check:
type: string
post:
summary: Update status with new data
parameters:
- in: body
name: body
required: true
schema:
type: object
properties:
repo:
type: string
example: "rsyslog"
server:
type: string
example: "rsyslog-lab"
sync_status:
type: string
enum: ["SYNCED", "OUT_OF_SYNC", "UNKNOWN", "PROGRESSING"]
drift_count:
type: integer
files:
type: array
items:
type: object
last_check:
type: string
responses:
200:
description: Status updated successfully
400:
description: No JSON data provided
500:
description: Failed to save status
"""
if request.method == 'OPTIONS':
return '', 204
@ -127,13 +214,27 @@ def api_status():
@app.route('/health', methods=['GET'])
def health():
"""GET /health - Kubernetes liveness probe"""
"""
GET /health - Kubernetes liveness probe
---
responses:
200:
description: API is healthy
"""
return jsonify({"status": "healthy"}), 200
@app.route('/ready', methods=['GET'])
def ready():
"""GET /ready - Kubernetes readiness probe"""
"""
GET /ready - Kubernetes readiness probe
---
responses:
200:
description: API is ready to serve requests
503:
description: API is not ready
"""
try:
# Check if data directory is writable
data_dir = os.path.dirname(STATUS_FILE)
@ -166,7 +267,13 @@ def ready():
@app.route('/', methods=['GET'])
def root():
"""GET / - Simple info endpoint"""
"""
GET / - API information and available endpoints
---
responses:
200:
description: API metadata and endpoint list
"""
return jsonify({
"name": "GitOps Status API",
"version": "1.0.0",

View File

@ -1,2 +1,3 @@
Flask==2.3.2
Werkzeug==2.3.6
flasgger