Skip to content

Commit a06cab7

Browse files
committed
fix: schedule creation authorization and no-wipe validation
feat: added ostype to self-schedule closes: #563 closes: #564 closes: #565 Change-Id: I9b7d31a505fd325cc5fa138ed472179d0aa41e4d
1 parent 8055b8d commit a06cab7

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/quads/server/blueprints/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def decorated_function(*args, **kwargs) -> Response:
7676
"error": "Bad Request",
7777
}
7878
return Response(response=json.dumps(response), status=400)
79-
g.current_user = username
79+
g.current_user = current_user
8080
return f(*args, **kwargs)
8181

8282
return decorated_function

src/quads/server/blueprints/assignments.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def create_self_assignment() -> Response:
244244
qinq = data.get("qinq")
245245
wipe = data.get("wipe")
246246
cc_user = data.get("cc_user")
247+
ostype = data.get("ostype")
247248

248249
required_fields = [
249250
"description",
@@ -308,6 +309,7 @@ def create_self_assignment() -> Response:
308309
"ccuser": cc_user,
309310
"is_self_schedule": True,
310311
"cloud": _cloud.name,
312+
"ostype": ostype,
311313
}
312314
if _vlan:
313315
kwargs["vlan_id"] = int(vlan)
@@ -456,7 +458,7 @@ def terminate_assignment(assignment_id) -> Response:
456458
}
457459
return make_response(jsonify(response), 400)
458460

459-
username = g.current_user.split("@")[0]
461+
username = g.current_user.email.split("@")[0]
460462
if username != _assignment.owner:
461463
response = {
462464
"status_code": 403,

src/quads/server/blueprints/schedules.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime, timedelta
22

3-
from flask import Blueprint, Response, jsonify, make_response, request
3+
from flask import Blueprint, Response, g, jsonify, make_response, request
44

55
from quads.config import Config
66
from quads.server.blueprints import check_access
@@ -114,6 +114,13 @@ def create_schedule() -> Response:
114114
"message": f"No active assignment for cloud: {cloud}",
115115
}
116116
return make_response(jsonify(response), 400)
117+
if not _assignment.is_self_schedule and "admin" not in [role.name for role in g.current_user.roles]:
118+
response = {
119+
"status_code": 403,
120+
"error": "Forbidden",
121+
"message": f"You({g.current_user.email}) don't have permission to create a schedule on {cloud}",
122+
}
123+
return make_response(jsonify(response), 403)
117124

118125
existing_schedules = ScheduleDao.get_current_schedule(cloud=_cloud)
119126
if _assignment.is_self_schedule and len(existing_schedules) >= Config.get("ssm_host_limit", 10):

src/quads/tools/validate_env.py

+3
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ async def main(_args, _logger=None): # pragma: no cover
409409
except Exception as ex:
410410
logger.debug(ex)
411411
logger.info("Failed validation for %s" % ass.cloud.name)
412+
elif _schedule_count and not _assignment.wipe:
413+
logger.info(f"Auto-Validating {ass.cloud.name} as marked for no wipe")
414+
quads.update_assignment(ass.id, {"validated": True})
412415

413416

414417
if __name__ == "__main__": # pragma: no cover

0 commit comments

Comments
 (0)