-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
69 lines (56 loc) · 1.7 KB
/
server.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
##################################################
#
# Code by Jioh L. Jung <ziozzang@gmail.com>
#
##################################################
# Import Flask Restful API library
from flask import Flask, request, abort, jsonify, make_response
# Import API
from conf import *
import clairdb
# Import OS
import os
# Process JSON
import json
####################################################
# Environment Override
if "DB_IP" in os.environ:
DB_IP = os.environ["DB_IP"]
if "DB_PORT" in os.environ:
DB_PORT = os.environ["DB_PORT"]
if "DB_ID" in os.environ:
DB_ID = os.environ["DB_ID"]
if "DB_PW" in os.environ:
DB_PW = os.environ["DB_PW"]
if "DEBUG" in os.environ:
if os.environ["DEBUG"].lower()[0] == "y" or \
os.environ["DEBUG"].lower()[0] == "t":
DEBUG = True
elif os.environ["DEBUG"].lower()[0] == "n" or \
os.environ["DEBUG"].lower()[0] == "f":
DEBUG = False
if "BIND_ADDR" in os.environ:
BIND_ADDR = os.environ["BIND_ADDR"]
app = Flask(__name__)
conn = clairdb.conn_db(DB_IP,DB_PORT,DB_ID,DB_PW)
####################################################
# Security Scanning
@app.route('/', methods=['PUT', 'POST'])
def check_security():
global conn
body = request.get_json()#silent=True)
print body["osver"]
print body["packages"]
if conn.closed != 0:
conn = clairdb.conn_db(DB_IP,DB_PORT,DB_ID,DB_PW)
res = clairdb.check(conn, body["osver"],body["packages"])
response = app.response_class(
response=json.dumps(res),
status=200,
mimetype='application/json'
)
return response
####################################################
if __name__ == '__main__':
app.run(host=BIND_ADDR, debug=DEBUG)