forked from angrymeir/Module-3-DevSecOps-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (24 loc) · 920 Bytes
/
main.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
from flask import Flask, send_file
import requests
import os
app = Flask(__name__)
repo = os.getenv('REPO')
workflow_runs_url = "https://api.github.com/repos/{}/actions/runs"
workflows = ['Container Scanning with Trivy', 'SAST with Bandit', 'Secrets scanning with GitLeaks']
def serve_image(state):
return send_file("bla.jpeg", mimetype="image/png")
@app.route("/")
def hello_world():
try:
workflow_runs = requests.get(workflow_runs_url.format(repo)).json()['workflow_runs']
workflow_states = {}
for workflow in workflows:
relevant_workflows = list(filter(lambda x: x['name'] == workflow, workflow_runs))[0]
workflow_states[workflow] = relevant_workflows['status']
except Exception:
return "<p>Hm something went terribly wrong</p>"
return "<p>{}</p>".format(workflow_states)
def main():
app.run()
if __name__ == '__main__':
main()