forked from tuhh-softsec/code2DFD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflask_code2DFD.py
49 lines (36 loc) · 1.37 KB
/
flask_code2DFD.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
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import Flask, jsonify, request
import code2DFD
app = Flask(__name__, instance_relative_config = True)
# Create default endpoint
@app.get('/')
def index():
index_message = "API for DFD extraction. \
Provide a GitHub URL to endpoint /dfd as parameter \"url\" to receive the extracted DFD: \
/dfd?url=https://github.com/georgwittberger/apache-spring-boot \
-microservice-example"
return index_message
# Create endpoint /dfd
@app.get('/dfd')
def dfd():
# Retrieve argument 'path' from request
url = request.args.get("url")
if not url:
return "Please specify a URL, e.g. /dfd?url=https://github.com/georgwittberger/apache-spring-boot" \
"-microservice-example "
try:
path = url.split("github.com/")[1]
except:
return "Please specify the complete URL, e.g. /dfd?url=https://github.com/georgwittberger/apache-spring-boot" \
"-microservice-example "
# Call Code2DFD
results = code2DFD.api_invocation(path)
# Create response JSON object and return it
response = jsonify(
codeable_models_file = results["codeable_models_file"],
traceability_file = results["traceability"],
execution_time = results["execution_time"]
)
return response
# starts local server
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=5001)