forked from localstack/localstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
110 lines (87 loc) · 3.06 KB
/
api.py
File metadata and controls
110 lines (87 loc) · 3.06 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import os
import json
import logging
import click
from flask import Flask, render_template, jsonify, send_from_directory, request
from flask_swagger import swagger
from localstack.constants import VERSION
from localstack.utils.aws.aws_stack import Environment
from localstack.utils import common
from localstack.dashboard import infra
root_path = os.path.dirname(os.path.realpath(__file__))
web_dir = root_path + '/web/'
app = Flask('app', template_folder=web_dir)
app.root_path = root_path
@app.route('/swagger.json')
def spec():
swag = swagger(app)
swag['info']['version'] = VERSION
swag['info']['title'] = 'AWS Resources Dashboard'
return jsonify(swag)
@app.route('/graph', methods=['POST'])
def get_graph():
""" Get deployment graph
---
operationId: 'getGraph'
parameters:
- name: request
in: body
"""
data = get_payload(request)
env = Environment.from_string(data.get('awsEnvironment'))
graph = infra.get_graph(name_filter=data['nameFilter'], env=env)
return jsonify(graph)
@app.route('/kinesis/<streamName>/<shardId>/events/latest', methods=['POST'])
def get_kinesis_events(streamName, shardId):
""" Get latest events from Kinesis.
---
operationId: 'getKinesisEvents'
parameters:
- name: streamName
in: path
- name: shardId
in: path
- name: request
in: body
"""
data = get_payload(request)
env = Environment.from_string(data.get('awsEnvironment'))
result = infra.get_kinesis_events(stream_name=streamName, shard_id=shardId, env=env)
return jsonify(result)
@app.route('/lambda/<functionName>/code', methods=['POST'])
def get_lambda_code(functionName):
""" Get source code for Lambda function.
---
operationId: 'getLambdaCode'
parameters:
- name: functionName
in: path
- name: request
in: body
"""
data = get_payload(request)
env = Environment.from_string(data.get('awsEnvironment'))
result = infra.get_lambda_code(func_name=functionName, env=env)
return jsonify(result)
@app.route('/')
def hello():
return render_template('index.html')
@app.route('/<path:path>')
def send_static(path):
return send_from_directory(web_dir + '/', path)
def get_payload(request):
return json.loads(common.to_str(request.data))
def ensure_webapp_installed():
web_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), 'web'))
node_modules_dir = os.path.join(web_dir, 'node_modules', 'jquery')
if not os.path.exists(node_modules_dir):
print('Initializing installation of Web application (this could take a long time, please be patient)')
common.run('cd "%s"; npm install' % web_dir)
def serve(port):
ensure_webapp_installed()
def noecho(*args, **kwargs):
pass
click.echo = noecho
logging.getLogger('werkzeug').setLevel(logging.ERROR)
app.config['ENV'] = 'development'
app.run(port=int(port), debug=True, threaded=True, host='0.0.0.0')