Skip to content

Commit 0af4b16

Browse files
committed
fix: Flask service and api_invocation() are up-to-date with DFD_extraction()
It is possible to provide a commit hash also to Flask request
1 parent 218acb6 commit 0af4b16

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ If you want to analyse in application on GitHub, simply put in the GitHub handle
3838
For example, for the repository `https://github.com/sqshq/piggymetrics`, run the command `python3 code2DFD.py --github_path sqshq/piggymetrics`
3939

4040
To run the tool as a RESTful API service, run `python3 flask_code2DFD.py`.
41-
This will spawn up a Flask server and you can trigger DFD-extractions by sending a request to or opening your browser at `localhost:5000/dfd?path=*repository/path*`
41+
This will spawn up a Flask server and you can trigger DFD-extractions by sending a request to `localhost:5001/dfd` with parameters `url` and optionally `commit`.
42+
Currently only GitHub URLs are supported this way.
4243

4344

4445
##### 3. Output

code2DFD.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import core.dfd_extraction as dfd_extraction
1111
from output_generators.logger import logger
1212
import tmp.tmp as tmp
13-
from core.file_interaction import clone_repo
1413

1514
CONFIG_SECTIONS = ["Analysis Settings", "Repository", "Technology Profiles", "DFD"]
1615
COMMUNICATIONS_TECH_LIST = '[("RabbitMQ", "rmq"), ("Kafka", "kfk"), ("RestTemplate", "rst"),\
@@ -24,33 +23,35 @@
2423
DEFAULT_CONFIG.set("Technology Profiles", "communication_techs_list", COMMUNICATIONS_TECH_LIST)
2524

2625

27-
def api_invocation(path: str) -> dict:
26+
def api_invocation(url: str, commit: str) -> dict:
2827
"""Entry function for when tool is called via API call.
2928
"""
3029

31-
print("New call for " + path)
32-
response = dict()
30+
repo_path = url.split("github.com/")[1] # TODO This needs to generalize beyond GitHub
31+
print("New call for " + repo_path)
3332

3433
start_time = datetime.now()
3534

3635
logger.info("*** New execution ***")
37-
logger.debug("Copying config file to tmp file")
36+
logger.debug("Initializing config to tmp file")
37+
for section in CONFIG_SECTIONS: # Copying what is needed from default to temp
38+
tmp.tmp_config.add_section(section)
39+
for entry in DEFAULT_CONFIG[section]:
40+
tmp.tmp_config.set(section, entry, DEFAULT_CONFIG[section][entry])
3841

3942
# Overwrite repo_path from config file with the one from the API call
40-
# TODO add analysis of specific commit with Flask API
41-
repo_path = str(path)
4243
tmp.tmp_config.set("Repository", "path", repo_path)
43-
44-
local_path = os.path.join(os.getcwd(), "analysed_repositories", *repo_path.split("/")[1:])
45-
tmp.tmp_config.set("Repository", "local_path", local_path)
46-
47-
clone_repo(repo_path, local_path) # TODO use Pydriller
44+
tmp.tmp_config.set("Repository", "local_path",
45+
os.path.join(os.getcwd(), "analysed_repositories"))
46+
if commit is not None:
47+
tmp.tmp_config.set("Analysis Settings", "commit", commit)
4848

4949
# Call extraction
5050
codeable_models, traceability = dfd_extraction.perform_analysis()
5151

52+
response = dict()
5253
response["codeable_models_file"] = codeable_models
53-
response["traceability"] = traceability
54+
response["traceability_file"] = traceability
5455

5556
# Execution time
5657
end_time = datetime.now()

flask_code2DFD.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,33 @@
44

55
app = Flask(__name__, instance_relative_config = True)
66

7-
# Create default endpoint
7+
88
@app.get('/')
99
def index():
10-
index_message = "API for DFD extraction. \
10+
index_message = ("API for DFD extraction. \
1111
Provide a GitHub URL to endpoint /dfd as parameter \"url\" to receive the extracted DFD: \
1212
/dfd?url=https://github.com/georgwittberger/apache-spring-boot \
13-
-microservice-example"
13+
-microservice-example; \
14+
Optionally provide a commit hash as \"commit\" parameter")
1415

1516
return index_message
1617

1718

18-
# Create endpoint /dfd
1919
@app.get('/dfd')
2020
def dfd():
2121

22-
# Retrieve argument 'path' from request
2322
url = request.args.get("url")
23+
commit = request.args.get("commit", None)
2424

2525
if not url:
2626
return "Please specify a URL, e.g. /dfd?url=https://github.com/georgwittberger/apache-spring-boot" \
2727
"-microservice-example "
28-
try:
29-
path = url.split("github.com/")[1]
30-
except:
31-
return "Please specify the complete URL, e.g. /dfd?url=https://github.com/georgwittberger/apache-spring-boot" \
32-
"-microservice-example "
3328

3429
# Call Code2DFD
35-
results = code2DFD.api_invocation(path)
30+
results = code2DFD.api_invocation(url, commit)
3631

3732
# Create response JSON object and return it
38-
response = jsonify(
39-
codeable_models_file = results["codeable_models_file"],
40-
traceability_file = results["traceability"],
41-
execution_time = results["execution_time"]
42-
)
33+
response = jsonify(**results)
4334

4435
return response
4536

0 commit comments

Comments
 (0)