-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
37 lines (23 loc) · 875 Bytes
/
server.py
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
#!/usr/bin/env python
from flask import Flask, request
app = Flask(__name__)
import re
import json
from controller.models import Machine, Container
@app.route('/')
def home():
return 'Yolo'
@app.route('/deployment/list', methods=['GET'])
def get_deployments():
username = request.args.get('username', '')
if username == '':
return 'plz pass username as a query string arg.', 400
username = username.lower()
if not re.match(r'^[0-9a-z]+$', username):
if not( username.startswith('prod') and re.match(r'^[0-9a-z-\*]+$', username) ):
return 'invalid username, it must be alphanumeric only for now.', 400
ms = Machine.load_files(key='*')
containers = Container.load_files(ms, key=username)
return json.dumps(containers.keys())
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9000, debug=True)