summaryrefslogtreecommitdiff
path: root/opendc/api/v2/topologies/topologyId/endpoint.py
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-06-25 22:11:25 +0200
committerjc0b <j@jc0b.computer>2020-06-25 22:11:25 +0200
commit61cf27a9529e503d3c56854c9d664f2d9520213a (patch)
tree77b32f3dfd56af806520ed481450f6d3c2f33412 /opendc/api/v2/topologies/topologyId/endpoint.py
parent00597ec99f587557b88b9982a2c41a2cb8db8112 (diff)
GET for topologies with tests
Diffstat (limited to 'opendc/api/v2/topologies/topologyId/endpoint.py')
-rw-r--r--opendc/api/v2/topologies/topologyId/endpoint.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/opendc/api/v2/topologies/topologyId/endpoint.py b/opendc/api/v2/topologies/topologyId/endpoint.py
new file mode 100644
index 00000000..ef541daa
--- /dev/null
+++ b/opendc/api/v2/topologies/topologyId/endpoint.py
@@ -0,0 +1,34 @@
+from opendc.models.topology import Topology
+from opendc.util import exceptions
+from opendc.util.rest import Response
+
+
+def GET(request):
+ """Get this Topology."""
+
+ # Make sure required parameters are there
+
+ try:
+ request.check_required_parameters(path={'topologyId': 'int'})
+ except exceptions.ParameterError as e:
+ return Response(400, str(e))
+
+ # Instantiate a Topology from the database
+
+ topology = Topology.from_id(request.params_path['topologyId'])
+
+ # Make sure this Topology exists
+
+ validation_error = topology.validate()
+ if validation_error is not None:
+ return validation_error
+
+ # Make sure this user is authorized to view this Topology
+
+ access_error = topology.validate_user_access(request.google_id, False)
+ if access_error is not None:
+ return access_error
+
+ # Return this Topology
+
+ return Response(200, 'Successfully retrieved topology.', topology.obj)