Skip to content

Commit b61c652

Browse files
author
Samuzzal Choudhury
authored
Merge pull request #74 from samuzzal-choudhury/user_repo_api
Added dummy user-repo endpoints with swagger spec
2 parents 246d6dd + 5041896 commit b61c652

File tree

3 files changed

+224
-1
lines changed

3 files changed

+224
-1
lines changed

src/rest_api.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,78 @@ def report():
135135
return flask.jsonify(response), 404
136136

137137

138+
@app.route('/api/v1/user-repo/scan', methods=['POST'])
139+
@login_required
140+
def user_repo_scan():
141+
"""
142+
Endpoint for scanning an OSIO user's repository.
143+
144+
Runs a scan to find out security vulnerability in a user's repository
145+
"""
146+
resp_dict = {
147+
"status": "success",
148+
"summary": ""
149+
}
150+
151+
if request.content_type != 'application/json':
152+
resp_dict["status"] = "failure"
153+
resp_dict["summary"] = "Set content type to application/json"
154+
return flask.jsonify(resp_dict), 400
155+
156+
input_json = request.get_json()
157+
158+
# Return a dummy response for the endpoint while the development is in progress
159+
return flask.jsonify({'summary': 'Repository scan initiated'}), 200
160+
161+
162+
@app.route('/api/v1/user-repo/notify', methods=['POST'])
163+
@login_required
164+
def notify_user():
165+
"""
166+
Endpoint for notifying security vulnerability in a repository.
167+
168+
Runs a scan to find out security vulnerability in a user's repository
169+
"""
170+
resp_dict = {
171+
"status": "success",
172+
"summary": ""
173+
}
174+
175+
if request.content_type != 'application/json':
176+
resp_dict["status"] = "failure"
177+
resp_dict["summary"] = "Set content type to application/json"
178+
return flask.jsonify(resp_dict), 400
179+
180+
input_json = request.get_json()
181+
182+
# Return a dummy response for the endpoint while the development is in progress
183+
return flask.jsonify({'summary': 'Notification service called'}), 200
184+
185+
186+
@app.route('/api/v1/user-repo/drop', methods=['POST'])
187+
@login_required
188+
def drop():
189+
"""
190+
Endpoint to stop monitoring OSIO users' repository.
191+
192+
Runs a scan to find out security vulnerability in a user's repository
193+
"""
194+
resp_dict = {
195+
"status": "success",
196+
"summary": ""
197+
}
198+
199+
if request.content_type != 'application/json':
200+
resp_dict["status"] = "failure"
201+
resp_dict["summary"] = "Set content type to application/json"
202+
return flask.jsonify(resp_dict), 400
203+
204+
input_json = request.get_json()
205+
206+
# Return a dummy response for the endpoint while the development is in progress
207+
return flask.jsonify({'summary': 'Repository scan unsubscribed'}), 200
208+
209+
138210
@app.errorhandler(HTTPError)
139211
def handle_error(e): # pragma: no cover
140212
"""Handle http error response."""

swagger.yaml

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,90 @@ paths:
8282
description: Request unauthorized
8383
'404':
8484
description: Data not found
85+
'/user-repo/scan':
86+
post:
87+
tags:
88+
- Scan Services
89+
operationId: f8a_scanner.api_v1.scan
90+
summary: Scan an OSIO user repository. This will be called by the OSIO platform whenever a new repository is added to a space. The client request requires OSIO user token in the authorization header.
91+
consumes:
92+
- application/json
93+
produces:
94+
- application/json
95+
parameters:
96+
- in: body
97+
name: repo
98+
description: repository url
99+
required: true
100+
schema:
101+
$ref: '#/definitions/UserRepoInput'
102+
responses:
103+
'200':
104+
description: Repository scan initiated
105+
'400':
106+
description: Bad request from the client
107+
'401':
108+
description: Request unauthorized
109+
'404':
110+
description: Data not found
111+
'500':
112+
description: Internal server error
113+
'/user-repo/notify':
114+
post:
115+
tags:
116+
- Scan Services
117+
operationId: f8a_scanner.api_v1.notify
118+
summary: Call the notification service with the scan report.
119+
consumes:
120+
- application/json
121+
produces:
122+
- application/json
123+
parameters:
124+
- in: body
125+
name: repo
126+
description: List of ecosystem-package-version
127+
required: true
128+
schema:
129+
$ref: '#/definitions/EPVList'
130+
responses:
131+
'200':
132+
description: Notification service called
133+
'400':
134+
description: Bad request from the client
135+
'401':
136+
description: Request unauthorized
137+
'404':
138+
description: Data not found
139+
'500':
140+
description: Internal server error
141+
'/user-repo/drop':
142+
post:
143+
tags:
144+
- Scan Services
145+
operationId: f8a_scanner.api_v1.drop
146+
summary: Stop monitoring an OSIO user repository. This will be triggered by the platform whenever a codebase is removed from a space. The client request requires OSIO user token in the authorization header.
147+
consumes:
148+
- application/json
149+
produces:
150+
- application/json
151+
parameters:
152+
- in: body
153+
name: repo
154+
description: repository url and email id
155+
required: true
156+
schema:
157+
$ref: '#/definitions/UserRepoInput'
158+
responses:
159+
'200':
160+
description: Repository scan unsubscribed
161+
'400':
162+
description: Bad request from the client
163+
'401':
164+
description: Request unauthorized
165+
'404':
166+
description: Data not found
167+
'500':
168+
description: Internal server error
85169
definitions:
86170
RegisterResponse:
87171
title: Response Data for Register Endpoint
@@ -141,4 +225,31 @@ definitions:
141225
type: string
142226
git-sha:
143227
type: string
144-
228+
UserRepoInput:
229+
title: User Repository Scan Inputs
230+
description: Parameters to call user repository scan
231+
properties:
232+
git-url:
233+
type: string
234+
email-ids:
235+
type: array
236+
items:
237+
type: string
238+
EPV:
239+
title: EPV
240+
description: Describes EPV
241+
properties:
242+
ecosystem:
243+
type: string
244+
name:
245+
type: string
246+
version:
247+
type: string
248+
EPVList:
249+
title: User Repository notify inputs
250+
description: Parameters to call user repository notify
251+
properties:
252+
epv_list:
253+
type: array
254+
items:
255+
$ref: '#/definitions/EPV'

tests/test_rest_api.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
"git-sha": "sha"
1515
}
1616

17+
payload_user_repo_scan_drop = {
18+
"git-url": "test",
19+
"email-ids": ["abcd@gmail.com"]
20+
}
21+
22+
23+
payload_user_repo_notify = {
24+
"epv_list": [
25+
{
26+
"ecosystem": "maven",
27+
"name": "io.vertx:vertx-core",
28+
"version": "3.5.2"
29+
}
30+
]
31+
}
32+
1733

1834
def api_route_for(route):
1935
"""Construct an URL to the endpoint for given route."""
@@ -162,3 +178,27 @@ def test_register_endpoint_6(get_info, client):
162178
data=json.dumps(payload),
163179
content_type='application/json')
164180
assert reg_resp.status_code == 500
181+
182+
183+
def test_scan_endpoint(client):
184+
"""Test the /api/v1/user-repo/scan endpoint."""
185+
reg_resp = client.post(api_route_for('user-repo/scan'),
186+
data=json.dumps(payload_user_repo_scan_drop),
187+
content_type='application/json')
188+
assert reg_resp.status_code == 200
189+
190+
191+
def test_drop_endpoint(client):
192+
"""Test the /api/v1/user-repo/drop endpoint."""
193+
reg_resp = client.post(api_route_for('user-repo/scan'),
194+
data=json.dumps(payload_user_repo_scan_drop),
195+
content_type='application/json')
196+
assert reg_resp.status_code == 200
197+
198+
199+
def test_notify_endpoint(client):
200+
"""Test the /api/v1/user-repo/notify endpoint."""
201+
reg_resp = client.post(api_route_for('user-repo/scan'),
202+
data=json.dumps(payload_user_repo_notify),
203+
content_type='application/json')
204+
assert reg_resp.status_code == 200

0 commit comments

Comments
 (0)