-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·51 lines (40 loc) · 1.43 KB
/
app.py
File metadata and controls
executable file
·51 lines (40 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import argparse
import json
from flask import Flask, render_template
from flask_restful import Resource, Api, abort
app = Flask(__name__)
api = Api(app)
with open('data/flags.json', 'r') as f:
flags = json.load(f)
@app.route('/')
def index():
return render_template('index.html')
def unique(l):
return sorted(set(l))
class Systems(Resource):
def get(self):
resp = { "results": unique(f["system"] for f in flags) }
resp["status"] = 200
return resp
class Applications(Resource):
def get(self, sysname):
resp = { "results": unique(f["application"] for f in flags if f["system"] == sysname) }
resp["status"] = 200 if len(resp["results"]) > 0 else 404
return resp
class Flags(Resource):
def get(self, sysname, appname):
resp = { "results": [f for f in flags if f["system"] == sysname
and f["application"] == appname] }
resp["status"] = 200 if len(resp["results"]) > 0 else 404
return resp
api.add_resource(Systems, '/api/systems')
api.add_resource(Applications, '/api/apps/<string:sysname>')
api.add_resource(Flags, '/api/flags/<string:sysname>/<string:appname>')
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('-b', '--bind', help='Address to bind.', default='127.0.0.1')
return parser.parse_args()
if __name__ == '__main__':
args = get_args()
app.run(debug=True, host=args.bind)