forked from mvazquezc/oscap-daemon-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
executable file
·108 lines (92 loc) · 4.06 KB
/
api.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
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
#!/usr/bin/python
from flask import Flask, jsonify, request
from lib.oscapdapi import OScapDaemonApi
app = Flask(__name__)
@app.route('/tasks', methods=['GET'])
def getTasks():
response = oscapd.get_task("all")
return response
@app.route('/tasks', methods=['POST'])
def newTask():
content = request.get_json(silent=False)
requiredFields = {'taskTitle', 'taskTarget', 'taskSSG', 'taskTailoring', 'taskProfileId', 'taskOnlineRemediation', 'taskScheduleNotBefore', 'taskScheduleRepeatAfter' }
if content is None:
return '{ "Error" : "json data required" }', 400
elif not requiredFields <= set(content):
return '{ "Error": "There are missing fields in the request" }', 400
elif content['taskSSG'] == "" or content['taskProfileId'] == "":
return '{ "Error": "Both taskSSG and taskProfileId fields cannot be empty" }', 400
else:
response = oscapd.new_task(content['taskTitle'], content['taskTarget'],
content['taskSSG'], content['taskTailoring'], content['taskProfileId'],
content['taskOnlineRemediation'], content['taskScheduleNotBefore'],
content['taskScheduleRepeatAfter'])
return response, 201
@app.route('/tasks/<int:taskId>', methods=['PUT'])
def updateTask(taskId):
content = request.get_json(silent=False)
requiredFields = {'taskTitle', 'taskTarget', 'taskSSG', 'taskTailoring', 'taskProfileId', 'taskOnlineRemediation', 'taskScheduleNotBefore', 'taskScheduleRepeatAfter' }
if content is None:
return '{ "Error" : "json data required" }', 400
elif not requiredFields <= set(content):
return '{ "Error": "There are missing fields in the request" }', 400
else:
response = oscapd.update_task(taskId, content['taskTitle'], content['taskTarget'],
content['taskSSG'], content['taskTailoring'], content['taskProfileId'],
content['taskOnlineRemediation'], content['taskScheduleNotBefore'],
content['taskScheduleRepeatAfter'])
return response
@app.route('/tasks/<int:taskId>', methods=['GET'])
def getTask(taskId):
response = oscapd.get_task(taskId)
return response
@app.route('/tasks/<int:taskId>/guide', methods=['GET'])
def getTaskGuide(taskId):
response = oscapd.get_task_guide(taskId)
return response
@app.route('/tasks/<int:taskId>/result/<int:resultId>', methods=['GET'])
def getTaskResult(taskId,resultId):
response = oscapd.get_task_result(taskId,resultId)
return response
@app.route('/tasks/<int:taskId>/result', methods=['DELETE'])
def remoteTaskResults(taskId):
response = oscapd.remove_task_result(taskId,"all")
return response
@app.route('/tasks/<int:taskId>/result/<int:resultId>', methods=['DELETE'])
def removeTaskResult(taskId,resultId):
response = oscapd.remove_task_result(taskId,resultId)
return response
@app.route('/tasks/<int:taskId>/run', methods=['GET'])
def runTaskOutsideSchedule(taskId):
response = oscapd.run_task_outside_schedule(taskId)
return response
@app.route('/tasks/<int:taskId>', methods=['DELETE'])
def removeTask(taskId):
response = oscapd.remove_task(taskId)
return response
@app.route('/tasks/<int:taskId>/<string:schedule>', methods=['PUT'])
def taskSchedule(taskId,schedule):
response = oscapd.task_schedule(taskId,schedule)
return response
@app.route('/ssgs', methods=['GET'])
def getSSGs():
response = oscapd.get_ssg("system","")
return response
@app.route('/ssgs', methods=['POST'])
def getSSG():
content = request.get_json(silent=False)
requiredFields = {'ssgFile', 'tailoringFile' }
if content is None:
return '{ "Error" : "json data required" }', 400
elif not requiredFields <= set(content):
return '{ "Error": "There are missing fields in the request" }', 400
elif content['ssgFile'] == "":
return '{ "Error": "ssgFile field cannot be empty" }', 400
else:
response = oscapd.get_ssg(content['ssgFile'],content['tailoringFile'])
return response
if __name__ == "__main__":
oscapd = OScapDaemonApi()
# Uncomment when testing
#app.debug = True
app.run()