...
1from typing import Dict
2
3import datetime
4import json
5import uuid
6
7from flask import Flask, jsonify, request
8
9from ambassador.utils import parse_yaml
10
11
12class FakeScoutApp (Flask):
13 def __init__(self, *args, **kwargs):
14 super().__init__(*args, **kwargs)
15 self.counts: Dict[str, int] = {}
16
17
18app = FakeScoutApp(__name__)
19
20def merge_dicts(x, y):
21 z = x.copy()
22 z.update(y)
23 return z
24
25
26@app.route('/scout', methods=['POST'])
27def report():
28 payload = request.json
29
30 print("\n---- %s" % datetime.datetime.now().isoformat())
31 print(json.dumps(payload, sort_keys=True, indent=4))
32
33 application = str(payload.get('application', '')).lower()
34
35 if application not in app.counts:
36 app.counts[application] = 0
37
38 app.counts[application] += 1
39
40 result = {
41 "latest_version": "0.52.1",
42 "application": application,
43 "cached": False,
44 "count": app.counts[application],
45 "timestamp": datetime.datetime.now().timestamp(),
46 "notices": [{ "level": "warning", "message": "Scout response is faked!" }]
47 }
48
49 return jsonify(result), 200
50
51
52def main():
53 print("fake_scout listening on port 9999")
54 app.run(host='0.0.0.0', port=9999, debug=True)
55
56
57if __name__ == '__main__':
58 main()
View as plain text