diff options
Diffstat (limited to 'opendc')
42 files changed, 78 insertions, 94 deletions
diff --git a/opendc/api/v2/datacenters/datacenterId/endpoint.py b/opendc/api/v2/datacenters/datacenterId/endpoint.py index 14dbbd2a..3265abb2 100644 --- a/opendc/api/v2/datacenters/datacenterId/endpoint.py +++ b/opendc/api/v2/datacenters/datacenterId/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'datacenterId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Datacenter from the database diff --git a/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py b/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py index 2cca01fd..593b38a7 100644 --- a/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py +++ b/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py @@ -12,7 +12,7 @@ def GET(request): try: request.check_required_parameters(path={'datacenterId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Datacenter from the database @@ -48,7 +48,7 @@ def POST(request): 'roomType': 'string' }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Make sure the passed object's datacenter id matches the path datacenter id diff --git a/opendc/api/v2/experiments/experimentId/endpoint.py b/opendc/api/v2/experiments/experimentId/endpoint.py index a306e441..4ae4abf2 100644 --- a/opendc/api/v2/experiments/experimentId/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/endpoint.py @@ -10,7 +10,7 @@ def GET(request): request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment from the database @@ -49,7 +49,7 @@ def PUT(request): }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment from the database @@ -92,7 +92,7 @@ def DELETE(request): request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment and make sure it exists diff --git a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py b/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py index f96c90ff..554c03b5 100644 --- a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment from the database diff --git a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py index 5f586896..e903e691 100644 --- a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment from the database diff --git a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py index 54b2fd8a..a1841bf0 100644 --- a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment from the database diff --git a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py index 9b1e0a68..19ecec22 100644 --- a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment from the database diff --git a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py b/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py index fe62f7f6..6bc0d4bd 100644 --- a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment from the database diff --git a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py index 3f6ce4a7..b4d8a702 100644 --- a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Experiment from the database diff --git a/opendc/api/v2/jobs/jobId/endpoint.py b/opendc/api/v2/jobs/jobId/endpoint.py index c24b04d0..4dc43728 100644 --- a/opendc/api/v2/jobs/jobId/endpoint.py +++ b/opendc/api/v2/jobs/jobId/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'jobId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Job and make sure it exists diff --git a/opendc/api/v2/jobs/jobId/tasks/endpoint.py b/opendc/api/v2/jobs/jobId/tasks/endpoint.py index d412df00..f2cb3384 100644 --- a/opendc/api/v2/jobs/jobId/tasks/endpoint.py +++ b/opendc/api/v2/jobs/jobId/tasks/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'jobId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Job and make sure it exists diff --git a/opendc/api/v2/paths/pathId/branches/endpoint.py b/opendc/api/v2/paths/pathId/branches/endpoint.py index 5d3b6ec1..d3256e8c 100644 --- a/opendc/api/v2/paths/pathId/branches/endpoint.py +++ b/opendc/api/v2/paths/pathId/branches/endpoint.py @@ -21,7 +21,7 @@ def POST(request): request.check_required_parameters(path={'pathId': 'int'}, body={'section': {'startTick': 'int'}}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate the current Path from the database diff --git a/opendc/api/v2/paths/pathId/endpoint.py b/opendc/api/v2/paths/pathId/endpoint.py index 7a73ce17..42357fc5 100644 --- a/opendc/api/v2/paths/pathId/endpoint.py +++ b/opendc/api/v2/paths/pathId/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'pathId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Path from the database diff --git a/opendc/api/v2/paths/pathId/sections/endpoint.py b/opendc/api/v2/paths/pathId/sections/endpoint.py index b8e4a861..a983ff1f 100644 --- a/opendc/api/v2/paths/pathId/sections/endpoint.py +++ b/opendc/api/v2/paths/pathId/sections/endpoint.py @@ -12,7 +12,7 @@ def GET(request): try: request.check_required_parameters(path={'pathId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Path from the database diff --git a/opendc/api/v2/room-types/name/allowed-objects/endpoint.py b/opendc/api/v2/room-types/name/allowed-objects/endpoint.py index 9cc0dbca..166781e8 100644 --- a/opendc/api/v2/room-types/name/allowed-objects/endpoint.py +++ b/opendc/api/v2/room-types/name/allowed-objects/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'name': 'string'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Get the AllowedObjects diff --git a/opendc/api/v2/rooms/roomId/endpoint.py b/opendc/api/v2/rooms/roomId/endpoint.py index a43a82e7..90bcdfd6 100644 --- a/opendc/api/v2/rooms/roomId/endpoint.py +++ b/opendc/api/v2/rooms/roomId/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'roomId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Room from the database @@ -48,7 +48,7 @@ def PUT(request): }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Room from the database @@ -88,7 +88,7 @@ def DELETE(request): request.check_required_parameters(path={'roomId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Room and make sure it exists diff --git a/opendc/api/v2/rooms/roomId/tiles/endpoint.py b/opendc/api/v2/rooms/roomId/tiles/endpoint.py index 6e498a48..971514ec 100644 --- a/opendc/api/v2/rooms/roomId/tiles/endpoint.py +++ b/opendc/api/v2/rooms/roomId/tiles/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'roomId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Room from the database @@ -53,7 +53,7 @@ def POST(request): }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) if request.params_path['roomId'] != request.params_body['tile']['roomId']: return Response(400, 'ID mismatch') diff --git a/opendc/api/v2/sections/sectionId/endpoint.py b/opendc/api/v2/sections/sectionId/endpoint.py index 0cda37bf..80e15328 100644 --- a/opendc/api/v2/sections/sectionId/endpoint.py +++ b/opendc/api/v2/sections/sectionId/endpoint.py @@ -11,7 +11,7 @@ def GET(request): try: request.check_required_parameters(path={'sectionId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Section from the database diff --git a/opendc/api/v2/simulations/endpoint.py b/opendc/api/v2/simulations/endpoint.py index 72501379..3eb7e903 100644 --- a/opendc/api/v2/simulations/endpoint.py +++ b/opendc/api/v2/simulations/endpoint.py @@ -19,7 +19,7 @@ def POST(request): request.check_required_parameters(body={'simulation': {'name': 'string'}}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Simulation diff --git a/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py b/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py index 80d45d04..b0a54524 100644 --- a/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Simulation and make sure it exists diff --git a/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py b/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py index d417936f..edc86c88 100644 --- a/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py @@ -14,7 +14,7 @@ def DELETE(request): request.check_required_parameters(path={'simulationId': 'int', 'userId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Authorization @@ -46,7 +46,7 @@ def GET(request): request.check_required_parameters(path={'simulationId': 'int', 'userId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Authorization @@ -81,7 +81,7 @@ def POST(request): }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate an Authorization @@ -142,7 +142,7 @@ def PUT(request): }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate and Authorization diff --git a/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py b/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py index 88c5fe21..c1d49228 100644 --- a/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py @@ -17,7 +17,7 @@ def POST(request): }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Make sure the passed object's simulation id matches the path simulation id diff --git a/opendc/api/v2/simulations/simulationId/endpoint.py b/opendc/api/v2/simulations/simulationId/endpoint.py index a6fc0a02..4aa33c7a 100644 --- a/opendc/api/v2/simulations/simulationId/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/endpoint.py @@ -14,7 +14,7 @@ def DELETE(request): request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Simulation and make sure it exists @@ -46,7 +46,7 @@ def GET(request): request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Simulation and make sure it exists @@ -76,7 +76,7 @@ def PUT(request): request.check_required_parameters(body={'simulation': {'name': 'name'}}, path={'simulationId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Simulation and make sure it exists diff --git a/opendc/api/v2/simulations/simulationId/experiments/endpoint.py b/opendc/api/v2/simulations/simulationId/experiments/endpoint.py index 68465bdc..07305690 100644 --- a/opendc/api/v2/simulations/simulationId/experiments/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/experiments/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Simulation from the database @@ -55,7 +55,7 @@ def POST(request): }) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Make sure the passed object's simulation id matches the path simulation id @@ -88,7 +88,7 @@ def POST(request): experiment.insert() except exceptions.ForeignKeyError as e: - return Response(400, 'Foreign key constraint not met.' + e.message) + return Response(400, 'Foreign key constraint not met.' + e) # Return this Experiment diff --git a/opendc/api/v2/simulations/simulationId/paths/endpoint.py b/opendc/api/v2/simulations/simulationId/paths/endpoint.py index 85a373b2..69a302ba 100644 --- a/opendc/api/v2/simulations/simulationId/paths/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/paths/endpoint.py @@ -12,7 +12,7 @@ def GET(request): try: request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Simulation from the database diff --git a/opendc/api/v2/specifications/cpus/id/endpoint.py b/opendc/api/v2/specifications/cpus/id/endpoint.py index 9c4229e1..205b61c5 100644 --- a/opendc/api/v2/specifications/cpus/id/endpoint.py +++ b/opendc/api/v2/specifications/cpus/id/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a CPU and make sure it exists diff --git a/opendc/api/v2/specifications/failure-models/id/endpoint.py b/opendc/api/v2/specifications/failure-models/id/endpoint.py index 67fe004a..db450f70 100644 --- a/opendc/api/v2/specifications/failure-models/id/endpoint.py +++ b/opendc/api/v2/specifications/failure-models/id/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a FailureModel and make sure it exists diff --git a/opendc/api/v2/specifications/gpus/id/endpoint.py b/opendc/api/v2/specifications/gpus/id/endpoint.py index e08833b8..489b7e8d 100644 --- a/opendc/api/v2/specifications/gpus/id/endpoint.py +++ b/opendc/api/v2/specifications/gpus/id/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a GPU and make sure it exists diff --git a/opendc/api/v2/specifications/memories/id/endpoint.py b/opendc/api/v2/specifications/memories/id/endpoint.py index 5f547f76..f34ca36f 100644 --- a/opendc/api/v2/specifications/memories/id/endpoint.py +++ b/opendc/api/v2/specifications/memories/id/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Memory and make sure it exists diff --git a/opendc/api/v2/specifications/storages/id/endpoint.py b/opendc/api/v2/specifications/storages/id/endpoint.py index b1f7e8c0..1b7a5ac7 100644 --- a/opendc/api/v2/specifications/storages/id/endpoint.py +++ b/opendc/api/v2/specifications/storages/id/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Storage and make sure it exists diff --git a/opendc/api/v2/tiles/tileId/endpoint.py b/opendc/api/v2/tiles/tileId/endpoint.py index 85cbd9f4..4a1a5447 100644 --- a/opendc/api/v2/tiles/tileId/endpoint.py +++ b/opendc/api/v2/tiles/tileId/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'tileId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Tile from the database @@ -44,7 +44,7 @@ def DELETE(request): request.check_required_parameters(path={'tileId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Tile from the database diff --git a/opendc/api/v2/tiles/tileId/rack/endpoint.py b/opendc/api/v2/tiles/tileId/rack/endpoint.py index 0e1017e8..2a5803e4 100644 --- a/opendc/api/v2/tiles/tileId/rack/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'tileId': 'int'}, ) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Tile from the database @@ -59,7 +59,7 @@ def POST(request): }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Tile from the database @@ -112,7 +112,7 @@ def PUT(request): }}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Tile from the database @@ -160,7 +160,7 @@ def DELETE(request): request.check_required_parameters(path={'tileId': 'int'}, ) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Tile from the database diff --git a/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py b/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py index 1ff25f44..34d3866e 100644 --- a/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'tileId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Rack from the database @@ -59,7 +59,7 @@ def POST(request): }) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Rack from the database diff --git a/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py b/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py index d82014b3..e769a049 100644 --- a/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'tileId': 'int', 'position': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Machine from the database @@ -57,7 +57,7 @@ def PUT(request): }) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Machine from the database @@ -115,7 +115,7 @@ def DELETE(request): request.check_required_parameters(path={'tileId': 'int', 'position': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Machine from the database diff --git a/opendc/api/v2/traces/traceId/endpoint.py b/opendc/api/v2/traces/traceId/endpoint.py index fe837c73..720d3fd0 100644 --- a/opendc/api/v2/traces/traceId/endpoint.py +++ b/opendc/api/v2/traces/traceId/endpoint.py @@ -12,7 +12,7 @@ def GET(request): request.check_required_parameters(path={'traceId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Trace and make sure it exists diff --git a/opendc/api/v2/traces/traceId/jobs/endpoint.py b/opendc/api/v2/traces/traceId/jobs/endpoint.py index 671e4d83..eec52b56 100644 --- a/opendc/api/v2/traces/traceId/jobs/endpoint.py +++ b/opendc/api/v2/traces/traceId/jobs/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'traceId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a Trace and make sure it exists diff --git a/opendc/api/v2/users/endpoint.py b/opendc/api/v2/users/endpoint.py index 27c8a9ef..2712c625 100644 --- a/opendc/api/v2/users/endpoint.py +++ b/opendc/api/v2/users/endpoint.py @@ -1,6 +1,8 @@ +from werkzeug.exceptions import abort + from opendc.models.user import User from opendc.util import exceptions -from opendc.util.database import fetch_one +from opendc.util.database import fetch_one, insert from opendc.util.rest import Response @@ -10,7 +12,7 @@ def GET(request): try: request.check_required_parameters(query={'email': 'string'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) user = fetch_one({'email': request.params_query['email']}, 'users') @@ -23,34 +25,21 @@ def GET(request): def POST(request): """Add a new User.""" - # Make sure required parameters are there - try: request.check_required_parameters(body={'user': {'email': 'string'}}) - except exceptions.ParameterError as e: - return Response(400, e.message) - - # Instantiate a User + return Response(400, str(e)) request.params_body['user']['googleId'] = request.google_id - user = User.from_JSON(request.params_body['user']) + user = request.params_body['user'] + existing_user = fetch_one({'googleId': user['googleId']}, 'users') - # Make sure a User with this Google ID does not already exist + if existing_user is not None: + return Response(409, '{} already exists.'.format(existing_user)) - if user.exists('google_id'): - user = user.from_google_id(user.google_id) - return Response(409, '{} already exists.'.format(user)) - - # Make sure this User is authorized to create this User - - if not request.google_id == user.google_id: + if not request.google_id == user['googleId']: return Response(403, 'Forbidden from creating this User.') - # Insert the User - - user.insert() - - # Return a JSON representation of the User + user = insert(user, 'users') - return Response(200, 'Successfully created {}'.format(user), user.to_JSON()) + return Response(200, 'Successfully created {}'.format(user), user) diff --git a/opendc/api/v2/users/userId/authorizations/endpoint.py b/opendc/api/v2/users/userId/authorizations/endpoint.py index bb3e173c..161034e1 100644 --- a/opendc/api/v2/users/userId/authorizations/endpoint.py +++ b/opendc/api/v2/users/userId/authorizations/endpoint.py @@ -13,7 +13,7 @@ def GET(request): request.check_required_parameters(path={'userId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a User and make sure they exist diff --git a/opendc/api/v2/users/userId/endpoint.py b/opendc/api/v2/users/userId/endpoint.py index 7f1ce84f..b7519973 100644 --- a/opendc/api/v2/users/userId/endpoint.py +++ b/opendc/api/v2/users/userId/endpoint.py @@ -12,7 +12,7 @@ def DELETE(request): request.check_required_parameters(path={'userId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a User and make sure they exist @@ -44,7 +44,7 @@ def GET(request): request.check_required_parameters(path={'userId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a User and make sure they exist @@ -75,7 +75,7 @@ def PUT(request): path={'userId': 'int'}) except exceptions.ParameterError as e: - return Response(400, e.message) + return Response(400, str(e)) # Instantiate a User and make sure they exist diff --git a/opendc/models/model.py b/opendc/models/model.py index 896eb235..73eabd26 100644 --- a/opendc/models/model.py +++ b/opendc/models/model.py @@ -269,7 +269,7 @@ class Model(object): last_row_id = database.execute(statement, values) except Exception as e: print(e) - raise exceptions.ForeignKeyError(e.message) + raise exceptions.ForeignKeyError(e) if 'id' in self.COLUMNS_PRIMARY_KEY: if is_auto_generated: @@ -300,4 +300,4 @@ class Model(object): try: database.execute(statement, values) except Exception as e: - raise exceptions.ForeignKeyError(e.message) + raise exceptions.ForeignKeyError(e) diff --git a/opendc/util/parameter_checker.py b/opendc/util/parameter_checker.py index 561ed497..d3e7ef13 100644 --- a/opendc/util/parameter_checker.py +++ b/opendc/util/parameter_checker.py @@ -66,8 +66,7 @@ def _format_parameter(parameter): def check(request, **kwargs): """Return True if all required parameters are there.""" - for location, params_required in kwargs.iteritems(): - + for location, params_required in kwargs.items(): params_actual = getattr(request, 'params_{}'.format(location)) missing_parameter = _missing_parameter(params_required, params_actual) diff --git a/opendc/util/rest.py b/opendc/util/rest.py index d5df5306..d892a358 100644 --- a/opendc/util/rest.py +++ b/opendc/util/rest.py @@ -40,16 +40,12 @@ class Request(object): # Parse the path and import the appropriate module try: - self.path = message['path'].encode('ascii', 'ignore').strip('/') + self.path = message['path'].strip('/') module_base = 'opendc.api.{}.endpoint' - module_path = self.path.translate(None, '{}').replace('/', '.') + module_path = self.path.replace('/', '.') self.module = importlib.import_module(module_base.format(module_path)) - - except UnicodeError: - raise exceptions.UnimplementedEndpointError('Non-ASCII path') - except ImportError: raise exceptions.UnimplementedEndpointError('Unimplemented endpoint: {}.'.format(self.path)) @@ -68,7 +64,7 @@ class Request(object): self.google_id = self._verify_token(self.token) except crypt.AppIdentityError as e: - raise exceptions.AuthorizationTokenError(e.message) + raise exceptions.AuthorizationTokenError(e) def _verify_token(self, token): """Return the ID of the signed-in user. |
