summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-api/opendc/api
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-15 13:09:06 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-18 15:46:40 +0200
commit2281d3265423d01e60f8cc088de5a5730bb8a910 (patch)
tree8dc81338cfd30845717f1b9025176d26c82fe930 /opendc-web/opendc-web-api/opendc/api
parent05d2318538eba71ac0555dc5ec146499d9cb0592 (diff)
api: Migrate to Flask Restful
This change updates the API to use Flask Restful instead of our own in-house REST library. This change reduces the maintenance effort and allows us to drastically simplify the API implementation needed for the OpenDC v2 API.
Diffstat (limited to 'opendc-web/opendc-web-api/opendc/api')
-rw-r--r--opendc-web/opendc-web-api/opendc/api/portfolios.py135
-rw-r--r--opendc-web/opendc-web-api/opendc/api/prefabs.py120
-rw-r--r--opendc-web/opendc-web-api/opendc/api/projects.py195
-rw-r--r--opendc-web/opendc-web-api/opendc/api/scenarios.py81
-rw-r--r--opendc-web/opendc-web-api/opendc/api/schedulers.py46
-rw-r--r--opendc-web/opendc-web-api/opendc/api/topologies.py93
-rw-r--r--opendc-web/opendc-web-api/opendc/api/traces.py51
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/paths.json19
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/portfolios/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/endpoint.py67
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py49
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/test_endpoint.py125
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/test_endpoint.py149
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/endpoint.py19
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/test_endpoint.py71
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/endpoint.py22
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/endpoint.py50
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/test_endpoint.py145
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/prefabs/test_endpoint.py24
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py36
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/endpoint.py60
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/endpoint.py35
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/test_endpoint.py85
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/test_endpoint.py119
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/endpoint.py31
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/test_endpoint.py52
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/test_endpoint.py32
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/scenarios/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/endpoint.py59
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/test_endpoint.py115
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/schedulers/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/schedulers/endpoint.py19
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/schedulers/test_endpoint.py2
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/topologies/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/endpoint.py58
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/test_endpoint.py113
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/traces/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/traces/endpoint.py10
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/traces/test_endpoint.py6
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/__init__.py0
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/endpoint.py14
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/test_endpoint.py15
54 files changed, 721 insertions, 1601 deletions
diff --git a/opendc-web/opendc-web-api/opendc/api/portfolios.py b/opendc-web/opendc-web-api/opendc/api/portfolios.py
new file mode 100644
index 00000000..b07e9da5
--- /dev/null
+++ b/opendc-web/opendc-web-api/opendc/api/portfolios.py
@@ -0,0 +1,135 @@
+# Copyright (c) 2021 AtLarge Research
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+from flask import request
+from flask_restful import Resource
+from marshmallow import Schema, fields
+
+from opendc.exts import requires_auth, current_user
+from opendc.models.portfolio import Portfolio as PortfolioModel, PortfolioSchema
+from opendc.models.project import Project
+from opendc.models.scenario import ScenarioSchema, Scenario
+from opendc.models.topology import Topology
+
+
+class Portfolio(Resource):
+ """
+ Resource representing a portfolio.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self, portfolio_id):
+ """
+ Get a portfolio by identifier.
+ """
+ portfolio = PortfolioModel.from_id(portfolio_id)
+
+ portfolio.check_exists()
+ portfolio.check_user_access(current_user['sub'], False)
+
+ data = portfolio.obj
+ return {'data': data}
+
+ def put(self, portfolio_id):
+ """
+ Replace the portfolio.
+ """
+ schema = Portfolio.PutSchema()
+ result = schema.load(request.json)
+
+ portfolio = PortfolioModel.from_id(portfolio_id)
+ portfolio.check_exists()
+ portfolio.check_user_access(current_user['sub'], True)
+
+ portfolio.set_property('name', result['portfolio']['name'])
+ portfolio.set_property('targets.enabledMetrics', result['portfolio']['targets']['enabledMetrics'])
+ portfolio.set_property('targets.repeatsPerScenario', result['portfolio']['targets']['repeatsPerScenario'])
+
+ portfolio.update()
+ data = portfolio.obj
+ return {'data': data}
+
+ def delete(self, portfolio_id):
+ """
+ Delete a portfolio.
+ """
+ portfolio = PortfolioModel.from_id(portfolio_id)
+
+ portfolio.check_exists()
+ portfolio.check_user_access(current_user['sub'], True)
+
+ portfolio_id = portfolio.get_id()
+
+ project = Project.from_id(portfolio.obj['projectId'])
+ project.check_exists()
+ if portfolio_id in project.obj['portfolioIds']:
+ project.obj['portfolioIds'].remove(portfolio_id)
+ project.update()
+
+ old_object = portfolio.delete()
+ return {'data': old_object}
+
+ class PutSchema(Schema):
+ """
+ Schema for the PUT operation on a portfolio.
+ """
+ portfolio = fields.Nested(PortfolioSchema, required=True)
+
+
+class PortfolioScenarios(Resource):
+ """
+ Resource representing the scenarios of a portfolio.
+ """
+ method_decorators = [requires_auth]
+
+ def post(self, portfolio_id):
+ """
+ Add a new scenario to this portfolio
+ """
+ schema = PortfolioScenarios.PostSchema()
+ result = schema.load(request.json)
+
+ portfolio = PortfolioModel.from_id(portfolio_id)
+
+ portfolio.check_exists()
+ portfolio.check_user_access(current_user['sub'], True)
+
+ scenario = Scenario(result['scenario'])
+
+ topology = Topology.from_id(scenario.obj['topology']['topologyId'])
+ topology.check_exists()
+ topology.check_user_access(current_user['sub'], True)
+
+ scenario.set_property('portfolioId', portfolio.get_id())
+ scenario.set_property('simulation', {'state': 'QUEUED'})
+ scenario.set_property('topology.topologyId', topology.get_id())
+
+ scenario.insert()
+
+ portfolio.obj['scenarioIds'].append(scenario.get_id())
+ portfolio.update()
+ data = scenario.obj
+ return {'data': data}
+
+ class PostSchema(Schema):
+ """
+ Schema for the POST operation on a portfolio's scenarios.
+ """
+ scenario = fields.Nested(ScenarioSchema, required=True)
diff --git a/opendc-web/opendc-web-api/opendc/api/prefabs.py b/opendc-web/opendc-web-api/opendc/api/prefabs.py
new file mode 100644
index 00000000..7bb17e7d
--- /dev/null
+++ b/opendc-web/opendc-web-api/opendc/api/prefabs.py
@@ -0,0 +1,120 @@
+# Copyright (c) 2021 AtLarge Research
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+from datetime import datetime
+from flask import request
+from flask_restful import Resource
+from marshmallow import Schema, fields
+
+from opendc.models.prefab import Prefab as PrefabModel, PrefabSchema
+from opendc.database import Database
+from opendc.exts import current_user, requires_auth, db
+
+
+class PrefabList(Resource):
+ """
+ Resource for the list of prefabs available to the user.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self):
+ """
+ Get the available prefabs for a user.
+ """
+ user_id = current_user['sub']
+
+ own_prefabs = db.fetch_all({'authorId': user_id}, PrefabModel.collection_name)
+ public_prefabs = db.fetch_all({'visibility': 'public'}, PrefabModel.collection_name)
+
+ authorizations = {"authorizations": []}
+ authorizations["authorizations"].append(own_prefabs)
+ authorizations["authorizations"].append(public_prefabs)
+ return {'data': authorizations}
+
+ def post(self):
+ """
+ Create a new prefab.
+ """
+ schema = PrefabList.PostSchema()
+ result = schema.load(request.json)
+
+ prefab = PrefabModel(result['prefab'])
+ prefab.set_property('datetimeCreated', Database.datetime_to_string(datetime.now()))
+ prefab.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
+
+ user_id = current_user['sub']
+ prefab.set_property('authorId', user_id)
+
+ prefab.insert()
+ return {'data': prefab.obj}
+
+ class PostSchema(Schema):
+ """
+ Schema for the POST operation on the prefab list.
+ """
+ prefab = fields.Nested(PrefabSchema, required=True)
+
+
+class Prefab(Resource):
+ """
+ Resource representing a single prefab.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self, prefab_id):
+ """Get this Prefab."""
+ prefab = PrefabModel.from_id(prefab_id)
+ prefab.check_exists()
+ prefab.check_user_access(current_user['sub'])
+ return {'data': prefab.obj}
+
+ def put(self, prefab_id):
+ """Update a prefab's name and/or contents."""
+
+ schema = Prefab.PutSchema()
+ result = schema.load(request.json)
+
+ prefab = PrefabModel.from_id(prefab_id)
+ prefab.check_exists()
+ prefab.check_user_access(current_user['sub'])
+
+ prefab.set_property('name', result['prefab']['name'])
+ prefab.set_property('rack', result['prefab']['rack'])
+ prefab.set_property('datetime_last_edited', Database.datetime_to_string(datetime.now()))
+ prefab.update()
+
+ return {'data': prefab.obj}
+
+ def delete(self, prefab_id):
+ """Delete this Prefab."""
+ prefab = PrefabModel.from_id(prefab_id)
+
+ prefab.check_exists()
+ prefab.check_user_access(current_user['sub'])
+
+ old_object = prefab.delete()
+
+ return {'data': old_object}
+
+ class PutSchema(Schema):
+ """
+ Schema for the PUT operation on a prefab.
+ """
+ prefab = fields.Nested(PrefabSchema, required=True)
diff --git a/opendc-web/opendc-web-api/opendc/api/projects.py b/opendc-web/opendc-web-api/opendc/api/projects.py
new file mode 100644
index 00000000..8c44b680
--- /dev/null
+++ b/opendc-web/opendc-web-api/opendc/api/projects.py
@@ -0,0 +1,195 @@
+# Copyright (c) 2021 AtLarge Research
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+from datetime import datetime
+from flask import request
+from flask_restful import Resource
+from marshmallow import Schema, fields
+
+from opendc.models.portfolio import Portfolio, PortfolioSchema
+from opendc.models.topology import Topology, TopologySchema
+from opendc.models.project import Project as ProjectModel, ProjectSchema
+from opendc.exts import current_user, requires_auth
+from opendc.database import Database
+
+
+class ProjectList(Resource):
+ """
+ Resource representing the list of projects available to a user.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self):
+ """Get the authorized projects of the user"""
+ user_id = current_user['sub']
+ projects = ProjectModel.get_for_user(user_id)
+ return {'data': projects}
+
+ def post(self):
+ """Create a new project, and return that new project."""
+ user_id = current_user['sub']
+
+ schema = Project.PutSchema()
+ result = schema.load(request.json)
+
+ topology = Topology({'name': 'Default topology', 'rooms': []})
+ topology.insert()
+
+ project = ProjectModel(result['project'])
+ project.set_property('datetimeCreated', Database.datetime_to_string(datetime.now()))
+ project.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
+ project.set_property('topologyIds', [topology.get_id()])
+ project.set_property('portfolioIds', [])
+ project.set_property('authorizations', [{'userId': user_id, 'level': 'OWN'}])
+ project.insert()
+
+ topology.set_property('projectId', project.get_id())
+ topology.update()
+
+ return {'data': project.obj}
+
+
+class Project(Resource):
+ """
+ Resource representing a single project.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self, project_id):
+ """Get this Project."""
+ project = ProjectModel.from_id(project_id)
+
+ project.check_exists()
+ project.check_user_access(current_user['sub'], False)
+
+ return {'data': project.obj}
+
+ def put(self, project_id):
+ """Update a project's name."""
+ schema = Project.PutSchema()
+ result = schema.load(request.json)
+
+ project = ProjectModel.from_id(project_id)
+
+ project.check_exists()
+ project.check_user_access(current_user['sub'], True)
+
+ project.set_property('name', result['project']['name'])
+ project.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
+ project.update()
+
+ return {'data': project.obj}
+
+ def delete(self, project_id):
+ """Delete this Project."""
+ project = ProjectModel.from_id(project_id)
+
+ project.check_exists()
+ project.check_user_access(current_user['sub'], True)
+
+ for topology_id in project.obj['topologyIds']:
+ topology = Topology.from_id(topology_id)
+ topology.delete()
+
+ for portfolio_id in project.obj['portfolioIds']:
+ portfolio = Portfolio.from_id(portfolio_id)
+ portfolio.delete()
+
+ old_object = project.delete()
+
+ return {'data': old_object}
+
+ class PutSchema(Schema):
+ """
+ Schema for the PUT operation on a project.
+ """
+ project = fields.Nested(ProjectSchema, required=True)
+
+
+class ProjectTopologies(Resource):
+ """
+ Resource representing the topologies of a project.
+ """
+ method_decorators = [requires_auth]
+
+ def post(self, project_id):
+ """Add a new Topology to the specified project and return it"""
+ schema = ProjectTopologies.PutSchema()
+ result = schema.load(request.json)
+
+ project = ProjectModel.from_id(project_id)
+
+ project.check_exists()
+ project.check_user_access(current_user['sub'], True)
+
+ topology = Topology({
+ 'projectId': project.get_id(),
+ 'name': result['topology']['name'],
+ 'rooms': result['topology']['rooms'],
+ })
+
+ topology.insert()
+
+ project.obj['topologyIds'].append(topology.get_id())
+ project.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
+ project.update()
+
+ return {'data': topology.obj}
+
+ class PutSchema(Schema):
+ """
+ Schema for the PUT operation on a project topology.
+ """
+ topology = fields.Nested(TopologySchema, required=True)
+
+
+class ProjectPortfolios(Resource):
+ """
+ Resource representing the portfolios of a project.
+ """
+ method_decorators = [requires_auth]
+
+ def post(self, project_id):
+ """Add a new Portfolio for this Project."""
+ schema = ProjectPortfolios.PutSchema()
+ result = schema.load(request.json)
+
+ project = ProjectModel.from_id(project_id)
+
+ project.check_exists()
+ project.check_user_access(current_user['sub'], True)
+
+ portfolio = Portfolio(result['portfolio'])
+
+ portfolio.set_property('projectId', project.get_id())
+ portfolio.set_property('scenarioIds', [])
+
+ portfolio.insert()
+
+ project.obj['portfolioIds'].append(portfolio.get_id())
+ project.update()
+
+ return {'data': portfolio.obj}
+
+ class PutSchema(Schema):
+ """
+ Schema for the PUT operation on a project portfolio.
+ """
+ portfolio = fields.Nested(PortfolioSchema, required=True)
diff --git a/opendc-web/opendc-web-api/opendc/api/scenarios.py b/opendc-web/opendc-web-api/opendc/api/scenarios.py
new file mode 100644
index 00000000..b566950a
--- /dev/null
+++ b/opendc-web/opendc-web-api/opendc/api/scenarios.py
@@ -0,0 +1,81 @@
+# Copyright (c) 2021 AtLarge Research
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+from flask import request
+from flask_restful import Resource
+from marshmallow import Schema, fields
+
+from opendc.models.scenario import Scenario as ScenarioModel, ScenarioSchema
+from opendc.models.portfolio import Portfolio
+from opendc.exts import current_user, requires_auth
+
+
+class Scenario(Resource):
+ """
+ A Scenario resource.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self, scenario_id):
+ """Get scenario by identifier."""
+ scenario = ScenarioModel.from_id(scenario_id)
+ scenario.check_exists()
+ scenario.check_user_access(current_user['sub'], False)
+ data = scenario.obj
+ return {'data': data}
+
+ def put(self, scenario_id):
+ """Update this Scenarios name."""
+ schema = Scenario.PutSchema()
+ result = schema.load(request.json)
+
+ scenario = ScenarioModel.from_id(scenario_id)
+
+ scenario.check_exists()
+ scenario.check_user_access(current_user['sub'], True)
+
+ scenario.set_property('name', result['scenario']['name'])
+
+ scenario.update()
+ data = scenario.obj
+ return {'data': data}
+
+ def delete(self, scenario_id):
+ """Delete this Scenario."""
+ scenario = ScenarioModel.from_id(scenario_id)
+ scenario.check_exists()
+ scenario.check_user_access(current_user['sub'], True)
+
+ scenario_id = scenario.get_id()
+
+ portfolio = Portfolio.from_id(scenario.obj['portfolioId'])
+ portfolio.check_exists()
+ if scenario_id in portfolio.obj['scenarioIds']:
+ portfolio.obj['scenarioIds'].remove(scenario_id)
+ portfolio.update()
+
+ old_object = scenario.delete()
+ return {'data': old_object}
+
+ class PutSchema(Schema):
+ """
+ Schema for the put operation.
+ """
+ scenario = fields.Nested(ScenarioSchema, required=True)
diff --git a/opendc-web/opendc-web-api/opendc/api/schedulers.py b/opendc-web/opendc-web-api/opendc/api/schedulers.py
new file mode 100644
index 00000000..b00d8c31
--- /dev/null
+++ b/opendc-web/opendc-web-api/opendc/api/schedulers.py
@@ -0,0 +1,46 @@
+# Copyright (c) 2021 AtLarge Research
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+from flask_restful import Resource
+from opendc.exts import requires_auth
+
+SCHEDULERS = [
+ 'mem',
+ 'mem-inv',
+ 'core-mem',
+ 'core-mem-inv',
+ 'active-servers',
+ 'active-servers-inv',
+ 'provisioned-cores',
+ 'provisioned-cores-inv',
+ 'random'
+]
+
+
+class SchedulerList(Resource):
+ """
+ Resource for the list of schedulers to pick from.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self):
+ """Get all available Traces."""
+ return {'data': [{'name': name} for name in SCHEDULERS]}
diff --git a/opendc-web/opendc-web-api/opendc/api/topologies.py b/opendc-web/opendc-web-api/opendc/api/topologies.py
new file mode 100644
index 00000000..eedf049d
--- /dev/null
+++ b/opendc-web/opendc-web-api/opendc/api/topologies.py
@@ -0,0 +1,93 @@
+# Copyright (c) 2021 AtLarge Research
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+from datetime import datetime
+
+from flask import request
+from flask_restful import Resource
+from marshmallow import Schema, fields
+
+from opendc.database import Database
+from opendc.models.project import Project
+from opendc.models.topology import Topology as TopologyModel, TopologySchema
+from opendc.exts import current_user, requires_auth
+
+
+class Topology(Resource):
+ """
+ Resource representing a single topology.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self, topology_id):
+ """
+ Get a single topology.
+ """
+ topology = TopologyModel.from_id(topology_id)
+ topology.check_exists()
+ topology.check_user_access(current_user['sub'], False)
+ data = topology.obj
+ return {'data': data}
+
+ def put(self, topology_id):
+ """
+ Replace the topology.
+ """
+ topology = TopologyModel.from_id(topology_id)
+
+ schema = Topology.PutSchema()
+ result = schema.load(request.json)
+
+ topology.check_exists()
+ topology.check_user_access(current_user['sub'], True)
+
+ topology.set_property('name', result['topology']['name'])
+ topology.set_property('rooms', result['topology']['rooms'])
+ topology.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
+
+ topology.update()
+ data = topology.obj
+ return {'data': data}
+
+ def delete(self, topology_id):
+ """
+ Delete a topology.
+ """
+ topology = TopologyModel.from_id(topology_id)
+
+ topology.check_exists()
+ topology.check_user_access(current_user['sub'], True)
+
+ topology_id = topology.get_id()
+
+ project = Project.from_id(topology.obj['projectId'])
+ project.check_exists()
+ if topology_id in project.obj['topologyIds']:
+ project.obj['topologyIds'].remove(topology_id)
+ project.update()
+
+ old_object = topology.delete()
+ return {'data': old_object}
+
+ class PutSchema(Schema):
+ """
+ Schema for the PUT operation on a topology.
+ """
+ topology = fields.Nested(TopologySchema, required=True)
diff --git a/opendc-web/opendc-web-api/opendc/api/traces.py b/opendc-web/opendc-web-api/opendc/api/traces.py
new file mode 100644
index 00000000..f685f00c
--- /dev/null
+++ b/opendc-web/opendc-web-api/opendc/api/traces.py
@@ -0,0 +1,51 @@
+# Copyright (c) 2021 AtLarge Research
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+from flask_restful import Resource
+
+from opendc.exts import requires_auth
+from opendc.models.trace import Trace as TraceModel
+
+
+class TraceList(Resource):
+ """
+ Resource for the list of traces to pick from.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self):
+ """Get all available Traces."""
+ traces = TraceModel.get_all()
+ data = traces.obj
+ return {'data': data}
+
+
+class Trace(Resource):
+ """
+ Resource representing a single trace.
+ """
+ method_decorators = [requires_auth]
+
+ def get(self, trace_id):
+ """Get trace information by identifier."""
+ trace = TraceModel.from_id(trace_id)
+ trace.check_exists()
+ data = trace.obj
+ return {'data': data}
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/paths.json b/opendc-web/opendc-web-api/opendc/api/v2/paths.json
deleted file mode 100644
index 652be5bc..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/paths.json
+++ /dev/null
@@ -1,19 +0,0 @@
-[
- "/users",
- "/users/{userId}",
- "/projects",
- "/projects/{projectId}",
- "/projects/{projectId}/authorizations",
- "/projects/{projectId}/topologies",
- "/projects/{projectId}/portfolios",
- "/topologies/{topologyId}",
- "/portfolios/{portfolioId}",
- "/portfolios/{portfolioId}/scenarios",
- "/scenarios/{scenarioId}",
- "/schedulers",
- "/traces",
- "/traces/{traceId}",
- "/prefabs",
- "/prefabs/{prefabId}",
- "/prefabs/authorizations"
-]
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/portfolios/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/endpoint.py
deleted file mode 100644
index c856f4ce..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/endpoint.py
+++ /dev/null
@@ -1,67 +0,0 @@
-from opendc.models.portfolio import Portfolio
-from opendc.models.project import Project
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Portfolio."""
-
- request.check_required_parameters(path={'portfolioId': 'string'})
-
- portfolio = Portfolio.from_id(request.params_path['portfolioId'])
-
- portfolio.check_exists()
- portfolio.check_user_access(request.current_user['sub'], False)
-
- return Response(200, 'Successfully retrieved portfolio.', portfolio.obj)
-
-
-def PUT(request):
- """Update this Portfolio."""
-
- request.check_required_parameters(path={'portfolioId': 'string'}, body={'portfolio': {
- 'name': 'string',
- 'targets': {
- 'enabledMetrics': 'list',
- 'repeatsPerScenario': 'int',
- },
- }})
-
- portfolio = Portfolio.from_id(request.params_path['portfolioId'])
-
- portfolio.check_exists()
- portfolio.check_user_access(request.current_user['sub'], True)
-
- portfolio.set_property('name',
- request.params_body['portfolio']['name'])
- portfolio.set_property('targets.enabledMetrics',
- request.params_body['portfolio']['targets']['enabledMetrics'])
- portfolio.set_property('targets.repeatsPerScenario',
- request.params_body['portfolio']['targets']['repeatsPerScenario'])
-
- portfolio.update()
-
- return Response(200, 'Successfully updated portfolio.', portfolio.obj)
-
-
-def DELETE(request):
- """Delete this Portfolio."""
-
- request.check_required_parameters(path={'portfolioId': 'string'})
-
- portfolio = Portfolio.from_id(request.params_path['portfolioId'])
-
- portfolio.check_exists()
- portfolio.check_user_access(request.current_user['sub'], True)
-
- portfolio_id = portfolio.get_id()
-
- project = Project.from_id(portfolio.obj['projectId'])
- project.check_exists()
- if portfolio_id in project.obj['portfolioIds']:
- project.obj['portfolioIds'].remove(portfolio_id)
- project.update()
-
- old_object = portfolio.delete()
-
- return Response(200, 'Successfully deleted portfolio.', old_object)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py
deleted file mode 100644
index b12afce3..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py
+++ /dev/null
@@ -1,49 +0,0 @@
-from opendc.models.portfolio import Portfolio
-from opendc.models.scenario import Scenario
-from opendc.models.topology import Topology
-from opendc.util.rest import Response
-
-
-def POST(request):
- """Add a new Scenario for this Portfolio."""
-
- request.check_required_parameters(path={'portfolioId': 'string'},
- body={
- 'scenario': {
- 'name': 'string',
- 'trace': {
- 'traceId': 'string',
- 'loadSamplingFraction': 'float',
- },
- 'topology': {
- 'topologyId': 'string',
- },
- 'operational': {
- 'failuresEnabled': 'bool',
- 'performanceInterferenceEnabled': 'bool',
- 'schedulerName': 'string',
- },
- }
- })
-
- portfolio = Portfolio.from_id(request.params_path['portfolioId'])
-
- portfolio.check_exists()
- portfolio.check_user_access(request.current_user['sub'], True)
-
- scenario = Scenario(request.params_body['scenario'])
-
- topology = Topology.from_id(scenario.obj['topology']['topologyId'])
- topology.check_exists()
- topology.check_user_access(request.current_user['sub'], True)
-
- scenario.set_property('portfolioId', portfolio.get_id())
- scenario.set_property('simulation', {'state': 'QUEUED'})
- scenario.set_property('topology.topologyId', topology.get_id())
-
- scenario.insert()
-
- portfolio.obj['scenarioIds'].append(scenario.get_id())
- portfolio.update()
-
- return Response(200, 'Successfully added Scenario.', scenario.obj)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/test_endpoint.py
deleted file mode 100644
index ff1666c0..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/scenarios/test_endpoint.py
+++ /dev/null
@@ -1,125 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-
-
-def test_add_scenario_missing_parameter(client):
- assert '400' in client.post('/v2/portfolios/1/scenarios').status
-
-
-def test_add_scenario_non_existing_portfolio(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.post(f'/v2/portfolios/{test_id}/scenarios',
- json={
- 'scenario': {
- 'name': 'test',
- 'trace': {
- 'traceId': test_id,
- 'loadSamplingFraction': 1.0,
- },
- 'topology': {
- 'topologyId': test_id,
- },
- 'operational': {
- 'failuresEnabled': True,
- 'performanceInterferenceEnabled': False,
- 'schedulerName': 'DEFAULT',
- },
- }
- }).status
-
-
-def test_add_scenario_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'portfolioId': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'VIEW'
- }]
- })
- assert '403' in client.post(f'/v2/portfolios/{test_id}/scenarios',
- json={
- 'scenario': {
- 'name': 'test',
- 'trace': {
- 'traceId': test_id,
- 'loadSamplingFraction': 1.0,
- },
- 'topology': {
- 'topologyId': test_id,
- },
- 'operational': {
- 'failuresEnabled': True,
- 'performanceInterferenceEnabled': False,
- 'schedulerName': 'DEFAULT',
- },
- }
- }).status
-
-
-def test_add_scenario(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'portfolioId': test_id,
- 'portfolioIds': [test_id],
- 'scenarioIds': [test_id],
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'EDIT'
- }],
- 'simulation': {
- 'state': 'QUEUED',
- },
- })
- mocker.patch.object(DB,
- 'insert',
- return_value={
- '_id': test_id,
- 'name': 'test',
- 'trace': {
- 'traceId': test_id,
- 'loadSamplingFraction': 1.0,
- },
- 'topology': {
- 'topologyId': test_id,
- },
- 'operational': {
- 'failuresEnabled': True,
- 'performanceInterferenceEnabled': False,
- 'schedulerName': 'DEFAULT',
- },
- 'portfolioId': test_id,
- 'simulationState': {
- 'state': 'QUEUED',
- },
- })
- mocker.patch.object(DB, 'update', return_value=None)
- res = client.post(
- f'/v2/portfolios/{test_id}/scenarios',
- json={
- 'scenario': {
- 'name': 'test',
- 'trace': {
- 'traceId': test_id,
- 'loadSamplingFraction': 1.0,
- },
- 'topology': {
- 'topologyId': test_id,
- },
- 'operational': {
- 'failuresEnabled': True,
- 'performanceInterferenceEnabled': False,
- 'schedulerName': 'DEFAULT',
- },
- }
- })
- assert 'portfolioId' in res.json['content']
- assert 'simulation' in res.json['content']
- assert '200' in res.status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/test_endpoint.py
deleted file mode 100644
index 1a44c63d..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/portfolios/portfolioId/test_endpoint.py
+++ /dev/null
@@ -1,149 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-test_id_2 = 24 * '2'
-
-
-def test_get_portfolio_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get(f'/v2/portfolios/{test_id}').status
-
-
-def test_get_portfolio_no_authorizations(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'projectId': test_id, 'authorizations': []})
- res = client.get(f'/v2/portfolios/{test_id}')
- assert '403' in res.status
-
-
-def test_get_portfolio_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- 'projectId': test_id,
- '_id': test_id,
- 'authorizations': []
- })
- res = client.get(f'/v2/portfolios/{test_id}')
- assert '403' in res.status
-
-
-def test_get_portfolio(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- 'projectId': test_id,
- '_id': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'EDIT'
- }]
- })
- res = client.get(f'/v2/portfolios/{test_id}')
- assert '200' in res.status
-
-
-def test_update_portfolio_missing_parameter(client):
- assert '400' in client.put(f'/v2/portfolios/{test_id}').status
-
-
-def test_update_portfolio_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.put(f'/v2/portfolios/{test_id}', json={
- 'portfolio': {
- 'name': 'test',
- 'targets': {
- 'enabledMetrics': ['test'],
- 'repeatsPerScenario': 2
- }
- }
- }).status
-
-
-def test_update_portfolio_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'VIEW'
- }]
- })
- mocker.patch.object(DB, 'update', return_value={})
- assert '403' in client.put(f'/v2/portfolios/{test_id}', json={
- 'portfolio': {
- 'name': 'test',
- 'targets': {
- 'enabledMetrics': ['test'],
- 'repeatsPerScenario': 2
- }
- }
- }).status
-
-
-def test_update_portfolio(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'OWN'
- }],
- 'targets': {
- 'enabledMetrics': [],
- 'repeatsPerScenario': 1
- }
- })
- mocker.patch.object(DB, 'update', return_value={})
-
- res = client.put(f'/v2/portfolios/{test_id}', json={'portfolio': {
- 'name': 'test',
- 'targets': {
- 'enabledMetrics': ['test'],
- 'repeatsPerScenario': 2
- }
- }})
- assert '200' in res.status
-
-
-def test_delete_project_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.delete(f'/v2/portfolios/{test_id}').status
-
-
-def test_delete_project_different_user(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'googleId': 'other_test',
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'VIEW'
- }]
- })
- mocker.patch.object(DB, 'delete_one', return_value=None)
- assert '403' in client.delete(f'/v2/portfolios/{test_id}').status
-
-
-def test_delete_project(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'googleId': 'test',
- 'portfolioIds': [test_id],
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'OWN'
- }]
- })
- mocker.patch.object(DB, 'delete_one', return_value={})
- mocker.patch.object(DB, 'update', return_value=None)
- res = client.delete(f'/v2/portfolios/{test_id}')
- assert '200' in res.status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/endpoint.py
deleted file mode 100644
index 5a8d367f..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/endpoint.py
+++ /dev/null
@@ -1,19 +0,0 @@
-from opendc.models.prefab import Prefab
-from opendc.util.database import DB
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Return all prefabs the user is authorized to access"""
-
- user_id = request.current_user['sub']
-
- own_prefabs = DB.fetch_all({'authorId': user_id}, Prefab.collection_name)
- public_prefabs = DB.fetch_all({'visibility': 'public'}, Prefab.collection_name)
-
- authorizations = {"authorizations": []}
-
- authorizations["authorizations"].append(own_prefabs)
- authorizations["authorizations"].append(public_prefabs)
-
- return Response(200, 'Successfully fetched authorizations.', authorizations)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/test_endpoint.py
deleted file mode 100644
index 6d36d428..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/authorizations/test_endpoint.py
+++ /dev/null
@@ -1,71 +0,0 @@
-from opendc.util.database import DB
-from unittest.mock import Mock
-
-test_id = 24 * '1'
-
-
-def test_get_authorizations(client, mocker):
- DB.fetch_all = Mock()
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': test_id})
- DB.fetch_all.side_effect = [
- [{
- '_id': test_id,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': test_id,
- 'visibility' : 'private'
- },
- {
- '_id': '2' * 24,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': test_id,
- 'visibility' : 'private'
- },
- {
- '_id': '3' * 24,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': test_id,
- 'visibility' : 'public'
- },
- {
- '_id': '4' * 24,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': test_id,
- 'visibility' : 'public'
- }],
- [{
- '_id': '5' * 24,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': '2' * 24,
- 'visibility' : 'public'
- },
- {
- '_id': '6' * 24,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': '2' * 24,
- 'visibility' : 'public'
- },
- {
- '_id': '7' * 24,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': '2' * 24,
- 'visibility' : 'public'
- },
- {
- '_id': '8' * 24,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': '2' * 24,
- 'visibility' : 'public'
- }]
- ]
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': test_id})
- res = client.get('/v2/prefabs/authorizations')
- assert '200' in res.status
-
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/endpoint.py
deleted file mode 100644
index 4a30f7eb..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/endpoint.py
+++ /dev/null
@@ -1,22 +0,0 @@
-from datetime import datetime
-
-from opendc.models.prefab import Prefab
-from opendc.util.database import Database
-from opendc.util.rest import Response
-
-
-def POST(request):
- """Create a new prefab, and return that new prefab."""
-
- request.check_required_parameters(body={'prefab': {'name': 'string'}})
-
- prefab = Prefab(request.params_body['prefab'])
- prefab.set_property('datetimeCreated', Database.datetime_to_string(datetime.now()))
- prefab.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
-
- user_id = request.current_user['sub']
- prefab.set_property('authorId', user_id)
-
- prefab.insert()
-
- return Response(200, 'Successfully created prefab.', prefab.obj)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/endpoint.py
deleted file mode 100644
index f1cf1fcd..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/endpoint.py
+++ /dev/null
@@ -1,50 +0,0 @@
-from datetime import datetime
-
-from opendc.models.prefab import Prefab
-from opendc.util.database import Database
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Prefab."""
-
- request.check_required_parameters(path={'prefabId': 'string'})
-
- prefab = Prefab.from_id(request.params_path['prefabId'])
- prefab.check_exists()
- prefab.check_user_access(request.current_user['sub'])
-
- return Response(200, 'Successfully retrieved prefab', prefab.obj)
-
-
-def PUT(request):
- """Update a prefab's name and/or contents."""
-
- request.check_required_parameters(body={'prefab': {'name': 'name'}}, path={'prefabId': 'string'})
-
- prefab = Prefab.from_id(request.params_path['prefabId'])
-
- prefab.check_exists()
- prefab.check_user_access(request.current_user['sub'])
-
- prefab.set_property('name', request.params_body['prefab']['name'])
- prefab.set_property('rack', request.params_body['prefab']['rack'])
- prefab.set_property('datetime_last_edited', Database.datetime_to_string(datetime.now()))
- prefab.update()
-
- return Response(200, 'Successfully updated prefab.', prefab.obj)
-
-
-def DELETE(request):
- """Delete this Prefab."""
-
- request.check_required_parameters(path={'prefabId': 'string'})
-
- prefab = Prefab.from_id(request.params_path['prefabId'])
-
- prefab.check_exists()
- prefab.check_user_access(request.current_user['sub'])
-
- old_object = prefab.delete()
-
- return Response(200, 'Successfully deleted prefab.', old_object)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/test_endpoint.py
deleted file mode 100644
index bc3b1a32..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/prefabId/test_endpoint.py
+++ /dev/null
@@ -1,145 +0,0 @@
-from opendc.util.database import DB
-from unittest.mock import Mock
-
-test_id = 24 * '1'
-test_id_2 = 24 * '2'
-
-
-def test_get_prefab_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get(f'/v2/prefabs/{test_id}').status
-
-
-def test_get_private_prefab_not_authorized(client, mocker):
- DB.fetch_one = Mock()
- DB.fetch_one.side_effect = [{
- '_id': test_id,
- 'name': 'test prefab',
- 'authorId': test_id_2,
- 'visibility': 'private',
- 'rack': {}
- },
- {
- '_id': test_id
- }
- ]
- res = client.get(f'/v2/prefabs/{test_id}')
- assert '403' in res.status
-
-
-def test_get_private_prefab(client, mocker):
- DB.fetch_one = Mock()
- DB.fetch_one.side_effect = [{
- '_id': test_id,
- 'name': 'test prefab',
- 'authorId': 'test',
- 'visibility': 'private',
- 'rack': {}
- },
- {
- '_id': test_id
- }
- ]
- res = client.get(f'/v2/prefabs/{test_id}')
- assert '200' in res.status
-
-
-def test_get_public_prefab(client, mocker):
- DB.fetch_one = Mock()
- DB.fetch_one.side_effect = [{
- '_id': test_id,
- 'name': 'test prefab',
- 'authorId': test_id_2,
- 'visibility': 'public',
- 'rack': {}
- },
- {
- '_id': test_id
- }
- ]
- res = client.get(f'/v2/prefabs/{test_id}')
- assert '200' in res.status
-
-
-def test_update_prefab_missing_parameter(client):
- assert '400' in client.put(f'/v2/prefabs/{test_id}').status
-
-
-def test_update_prefab_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.put(f'/v2/prefabs/{test_id}', json={'prefab': {'name': 'S'}}).status
-
-
-def test_update_prefab_not_authorized(client, mocker):
- DB.fetch_one = Mock()
- DB.fetch_one.side_effect = [{
- '_id': test_id,
- 'name': 'test prefab',
- 'authorId': test_id_2,
- 'visibility': 'private',
- 'rack': {}
- },
- {
- '_id': test_id
- }
- ]
- mocker.patch.object(DB, 'update', return_value={})
- assert '403' in client.put(f'/v2/prefabs/{test_id}', json={'prefab': {'name': 'test prefab', 'rack': {}}}).status
-
-
-def test_update_prefab(client, mocker):
- DB.fetch_one = Mock()
- DB.fetch_one.side_effect = [{
- '_id': test_id,
- 'name': 'test prefab',
- 'authorId': 'test',
- 'visibility': 'private',
- 'rack': {}
- },
- {
- '_id': test_id
- }
- ]
- mocker.patch.object(DB, 'update', return_value={})
- res = client.put(f'/v2/prefabs/{test_id}', json={'prefab': {'name': 'test prefab', 'rack': {}}})
- assert '200' in res.status
-
-
-def test_delete_prefab_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.delete(f'/v2/prefabs/{test_id}').status
-
-
-def test_delete_prefab_different_user(client, mocker):
- DB.fetch_one = Mock()
- DB.fetch_one.side_effect = [{
- '_id': test_id,
- 'name': 'test prefab',
- 'authorId': test_id_2,
- 'visibility': 'private',
- 'rack': {}
- },
- {
- '_id': test_id
- }
- ]
- mocker.patch.object(DB, 'delete_one', return_value=None)
- assert '403' in client.delete(f'/v2/prefabs/{test_id}').status
-
-
-def test_delete_prefab(client, mocker):
- DB.fetch_one = Mock()
- DB.fetch_one.side_effect = [{
- '_id': test_id,
- 'name': 'test prefab',
- 'authorId': 'test',
- 'visibility': 'private',
- 'rack': {}
- },
- {
- '_id': test_id
- }
- ]
- mocker.patch.object(DB, 'delete_one', return_value={'prefab': {'name': 'name'}})
- res = client.delete(f'/v2/prefabs/{test_id}')
- assert '200' in res.status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/prefabs/test_endpoint.py
deleted file mode 100644
index 39a78c21..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/prefabs/test_endpoint.py
+++ /dev/null
@@ -1,24 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-
-
-def test_add_prefab_missing_parameter(client):
- assert '400' in client.post('/v2/prefabs').status
-
-
-def test_add_prefab(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': test_id, 'authorizations': []})
- mocker.patch.object(DB,
- 'insert',
- return_value={
- '_id': test_id,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'authorId': test_id
- })
- res = client.post('/v2/prefabs', json={'prefab': {'name': 'test prefab'}})
- assert 'datetimeCreated' in res.json['content']
- assert 'datetimeLastEdited' in res.json['content']
- assert 'authorId' in res.json['content']
- assert '200' in res.status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py
deleted file mode 100644
index b381d689..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py
+++ /dev/null
@@ -1,36 +0,0 @@
-from datetime import datetime
-
-from opendc.models.project import Project
-from opendc.models.topology import Topology
-from opendc.util.database import Database
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get the authorized projects of the user"""
- user_id = request.current_user['sub']
- projects = Project.get_for_user(user_id)
- return Response(200, 'Successfully retrieved projects', projects)
-
-
-def POST(request):
- """Create a new project, and return that new project."""
-
- request.check_required_parameters(body={'project': {'name': 'string'}})
- user_id = request.current_user['sub']
-
- topology = Topology({'name': 'Default topology', 'rooms': []})
- topology.insert()
-
- project = Project(request.params_body['project'])
- project.set_property('datetimeCreated', Database.datetime_to_string(datetime.now()))
- project.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
- project.set_property('topologyIds', [topology.get_id()])
- project.set_property('portfolioIds', [])
- project.set_property('authorizations', [{'userId': user_id, 'authorizationLevel': 'OWN'}])
- project.insert()
-
- topology.set_property('projectId', project.get_id())
- topology.update()
-
- return Response(200, 'Successfully created project.', project.obj)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/endpoint.py
deleted file mode 100644
index fa53ce6b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/endpoint.py
+++ /dev/null
@@ -1,60 +0,0 @@
-from datetime import datetime
-
-from opendc.models.portfolio import Portfolio
-from opendc.models.project import Project
-from opendc.models.topology import Topology
-from opendc.util.database import Database
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Project."""
-
- request.check_required_parameters(path={'projectId': 'string'})
-
- project = Project.from_id(request.params_path['projectId'])
-
- project.check_exists()
- project.check_user_access(request.current_user['sub'], False)
-
- return Response(200, 'Successfully retrieved project', project.obj)
-
-
-def PUT(request):
- """Update a project's name."""
-
- request.check_required_parameters(body={'project': {'name': 'name'}}, path={'projectId': 'string'})
-
- project = Project.from_id(request.params_path['projectId'])
-
- project.check_exists()
- project.check_user_access(request.current_user['sub'], True)
-
- project.set_property('name', request.params_body['project']['name'])
- project.set_property('datetime_last_edited', Database.datetime_to_string(datetime.now()))
- project.update()
-
- return Response(200, 'Successfully updated project.', project.obj)
-
-
-def DELETE(request):
- """Delete this Project."""
-
- request.check_required_parameters(path={'projectId': 'string'})
-
- project = Project.from_id(request.params_path['projectId'])
-
- project.check_exists()
- project.check_user_access(request.current_user['sub'], True)
-
- for topology_id in project.obj['topologyIds']:
- topology = Topology.from_id(topology_id)
- topology.delete()
-
- for portfolio_id in project.obj['portfolioIds']:
- portfolio = Portfolio.from_id(portfolio_id)
- portfolio.delete()
-
- old_object = project.delete()
-
- return Response(200, 'Successfully deleted project.', old_object)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/endpoint.py
deleted file mode 100644
index 18b4d007..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/endpoint.py
+++ /dev/null
@@ -1,35 +0,0 @@
-from opendc.models.portfolio import Portfolio
-from opendc.models.project import Project
-from opendc.util.rest import Response
-
-
-def POST(request):
- """Add a new Portfolio for this Project."""
-
- request.check_required_parameters(path={'projectId': 'string'},
- body={
- 'portfolio': {
- 'name': 'string',
- 'targets': {
- 'enabledMetrics': 'list',
- 'repeatsPerScenario': 'int',
- },
- }
- })
-
- project = Project.from_id(request.params_path['projectId'])
-
- project.check_exists()
- project.check_user_access(request.current_user['sub'], True)
-
- portfolio = Portfolio(request.params_body['portfolio'])
-
- portfolio.set_property('projectId', project.get_id())
- portfolio.set_property('scenarioIds', [])
-
- portfolio.insert()
-
- project.obj['portfolioIds'].append(portfolio.get_id())
- project.update()
-
- return Response(200, 'Successfully added Portfolio.', portfolio.obj)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/test_endpoint.py
deleted file mode 100644
index 7ddfe0ce..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/portfolios/test_endpoint.py
+++ /dev/null
@@ -1,85 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-
-
-def test_add_portfolio_missing_parameter(client):
- assert '400' in client.post(f'/v2/projects/{test_id}/portfolios').status
-
-
-def test_add_portfolio_non_existing_project(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.post(f'/v2/projects/{test_id}/portfolios',
- json={
- 'portfolio': {
- 'name': 'test',
- 'targets': {
- 'enabledMetrics': ['test'],
- 'repeatsPerScenario': 2
- }
- }
- }).status
-
-
-def test_add_portfolio_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'VIEW'
- }]
- })
- assert '403' in client.post(f'/v2/projects/{test_id}/portfolios',
- json={
- 'portfolio': {
- 'name': 'test',
- 'targets': {
- 'enabledMetrics': ['test'],
- 'repeatsPerScenario': 2
- }
- }
- }).status
-
-
-def test_add_portfolio(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'portfolioIds': [test_id],
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'EDIT'
- }]
- })
- mocker.patch.object(DB,
- 'insert',
- return_value={
- '_id': test_id,
- 'name': 'test',
- 'targets': {
- 'enabledMetrics': ['test'],
- 'repeatsPerScenario': 2
- },
- 'projectId': test_id,
- 'scenarioIds': [],
- })
- mocker.patch.object(DB, 'update', return_value=None)
- res = client.post(
- f'/v2/projects/{test_id}/portfolios',
- json={
- 'portfolio': {
- 'name': 'test',
- 'targets': {
- 'enabledMetrics': ['test'],
- 'repeatsPerScenario': 2
- }
- }
- })
- assert 'projectId' in res.json['content']
- assert 'scenarioIds' in res.json['content']
- assert '200' in res.status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/test_endpoint.py
deleted file mode 100644
index 03e6758b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/test_endpoint.py
+++ /dev/null
@@ -1,119 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-test_id_2 = 24 * '2'
-
-
-def test_get_project_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get(f'/v2/projects/{test_id}').status
-
-
-def test_get_project_no_authorizations(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'authorizations': []})
- res = client.get(f'/v2/projects/{test_id}')
- assert '403' in res.status
-
-
-def test_get_project_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'authorizations': []
- })
- res = client.get(f'/v2/projects/{test_id}')
- assert '403' in res.status
-
-
-def test_get_project(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'EDIT'
- }]
- })
- res = client.get(f'/v2/projects/{test_id}')
- assert '200' in res.status
-
-
-def test_update_project_missing_parameter(client):
- assert '400' in client.put(f'/v2/projects/{test_id}').status
-
-
-def test_update_project_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.put(f'/v2/projects/{test_id}', json={'project': {'name': 'S'}}).status
-
-
-def test_update_project_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'VIEW'
- }]
- })
- mocker.patch.object(DB, 'update', return_value={})
- assert '403' in client.put(f'/v2/projects/{test_id}', json={'project': {'name': 'S'}}).status
-
-
-def test_update_project(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'OWN'
- }]
- })
- mocker.patch.object(DB, 'update', return_value={})
-
- res = client.put(f'/v2/projects/{test_id}', json={'project': {'name': 'S'}})
- assert '200' in res.status
-
-
-def test_delete_project_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.delete(f'/v2/projects/{test_id}').status
-
-
-def test_delete_project_different_user(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'googleId': 'other_test',
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'VIEW'
- }],
- 'topologyIds': []
- })
- mocker.patch.object(DB, 'delete_one', return_value=None)
- assert '403' in client.delete(f'/v2/projects/{test_id}').status
-
-
-def test_delete_project(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'googleId': 'test',
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'OWN'
- }],
- 'topologyIds': [],
- 'portfolioIds': [],
- })
- mocker.patch.object(DB, 'update', return_value=None)
- mocker.patch.object(DB, 'delete_one', return_value={'googleId': 'test'})
- res = client.delete(f'/v2/projects/{test_id}')
- assert '200' in res.status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/endpoint.py
deleted file mode 100644
index 47f2a207..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/endpoint.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from datetime import datetime
-
-from opendc.models.project import Project
-from opendc.models.topology import Topology
-from opendc.util.rest import Response
-from opendc.util.database import Database
-
-
-def POST(request):
- """Add a new Topology to the specified project and return it"""
-
- request.check_required_parameters(path={'projectId': 'string'}, body={'topology': {'name': 'string'}})
-
- project = Project.from_id(request.params_path['projectId'])
-
- project.check_exists()
- project.check_user_access(request.current_user['sub'], True)
-
- topology = Topology({
- 'projectId': project.get_id(),
- 'name': request.params_body['topology']['name'],
- 'rooms': request.params_body['topology']['rooms'],
- })
-
- topology.insert()
-
- project.obj['topologyIds'].append(topology.get_id())
- project.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
- project.update()
-
- return Response(200, 'Successfully inserted topology.', topology.obj)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/test_endpoint.py
deleted file mode 100644
index 2e872415..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/projectId/topologies/test_endpoint.py
+++ /dev/null
@@ -1,52 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-
-
-def test_add_topology_missing_parameter(client):
- assert '400' in client.post(f'/v2/projects/{test_id}/topologies').status
-
-
-def test_add_topology(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'OWN'
- }],
- 'topologyIds': []
- })
- mocker.patch.object(DB,
- 'insert',
- return_value={
- '_id': test_id,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'topologyIds': []
- })
- mocker.patch.object(DB, 'update', return_value={})
- res = client.post(f'/v2/projects/{test_id}/topologies', json={'topology': {'name': 'test project', 'rooms': []}})
- assert 'rooms' in res.json['content']
- assert '200' in res.status
-
-
-def test_add_topology_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'VIEW'
- }]
- })
- assert '403' in client.post(f'/v2/projects/{test_id}/topologies',
- json={
- 'topology': {
- 'name': 'test_topology',
- 'rooms': {}
- }
- }).status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/test_endpoint.py
deleted file mode 100644
index db768f28..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/projects/test_endpoint.py
+++ /dev/null
@@ -1,32 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-
-
-def test_get_user_projects(client, mocker):
- mocker.patch.object(DB, 'fetch_all', return_value={'_id': test_id, 'authorizations': [{'userId': 'test',
- 'authorizationLevel': 'OWN'}]})
- res = client.get('/v2/projects')
- assert '200' in res.status
-
-
-def test_add_project_missing_parameter(client):
- assert '400' in client.post('/v2/projects').status
-
-
-def test_add_project(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'_id': test_id, 'authorizations': []})
- mocker.patch.object(DB,
- 'insert',
- return_value={
- '_id': test_id,
- 'datetimeCreated': '000',
- 'datetimeLastEdited': '000',
- 'topologyIds': []
- })
- mocker.patch.object(DB, 'update', return_value={})
- res = client.post('/v2/projects', json={'project': {'name': 'test project'}})
- assert 'datetimeCreated' in res.json['content']
- assert 'datetimeLastEdited' in res.json['content']
- assert 'topologyIds' in res.json['content']
- assert '200' in res.status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/scenarios/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/scenarios/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/scenarios/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/endpoint.py
deleted file mode 100644
index 7399f98c..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/endpoint.py
+++ /dev/null
@@ -1,59 +0,0 @@
-from opendc.models.scenario import Scenario
-from opendc.models.portfolio import Portfolio
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Scenario."""
-
- request.check_required_parameters(path={'scenarioId': 'string'})
-
- scenario = Scenario.from_id(request.params_path['scenarioId'])
-
- scenario.check_exists()
- scenario.check_user_access(request.current_user['sub'], False)
-
- return Response(200, 'Successfully retrieved scenario.', scenario.obj)
-
-
-def PUT(request):
- """Update this Scenarios name."""
-
- request.check_required_parameters(path={'scenarioId': 'string'}, body={'scenario': {
- 'name': 'string',
- }})
-
- scenario = Scenario.from_id(request.params_path['scenarioId'])
-
- scenario.check_exists()
- scenario.check_user_access(request.current_user['sub'], True)
-
- scenario.set_property('name',
- request.params_body['scenario']['name'])
-
- scenario.update()
-
- return Response(200, 'Successfully updated scenario.', scenario.obj)
-
-
-def DELETE(request):
- """Delete this Scenario."""
-
- request.check_required_parameters(path={'scenarioId': 'string'})
-
- scenario = Scenario.from_id(request.params_path['scenarioId'])
-
- scenario.check_exists()
- scenario.check_user_access(request.current_user['sub'], True)
-
- scenario_id = scenario.get_id()
-
- portfolio = Portfolio.from_id(scenario.obj['portfolioId'])
- portfolio.check_exists()
- if scenario_id in portfolio.obj['scenarioIds']:
- portfolio.obj['scenarioIds'].remove(scenario_id)
- portfolio.update()
-
- old_object = scenario.delete()
-
- return Response(200, 'Successfully deleted scenario.', old_object)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/test_endpoint.py
deleted file mode 100644
index 24b38671..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/scenarios/scenarioId/test_endpoint.py
+++ /dev/null
@@ -1,115 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-test_id_2 = 24 * '2'
-
-
-def test_get_scenario_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get(f'/v2/scenarios/{test_id}').status
-
-
-def test_get_scenario_no_authorizations(client, mocker):
- m = mocker.MagicMock()
- m.side_effect = ({'portfolioId': test_id}, {'projectId': test_id}, {'authorizations': []})
- mocker.patch.object(DB, 'fetch_one', m)
- res = client.get(f'/v2/scenarios/{test_id}')
- assert '403' in res.status
-
-
-def test_get_scenario(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- side_effect=[
- {'portfolioId': test_id},
- {'projectId': test_id},
- {'authorizations':
- [{'userId': 'test', 'authorizationLevel': 'OWN'}]
- }])
- res = client.get(f'/v2/scenarios/{test_id}')
- assert '200' in res.status
-
-
-def test_update_scenario_missing_parameter(client):
- assert '400' in client.put(f'/v2/scenarios/{test_id}').status
-
-
-def test_update_scenario_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.put(f'/v2/scenarios/{test_id}', json={
- 'scenario': {
- 'name': 'test',
- }
- }).status
-
-
-def test_update_scenario_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- side_effect=[
- {'portfolioId': test_id},
- {'projectId': test_id},
- {'authorizations':
- [{'userId': 'test', 'authorizationLevel': 'VIEW'}]
- }])
- mocker.patch.object(DB, 'update', return_value={})
- assert '403' in client.put(f'/v2/scenarios/{test_id}', json={
- 'scenario': {
- 'name': 'test',
- }
- }).status
-
-
-def test_update_scenario(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- side_effect=[
- {'_id': test_id, 'portfolioId': test_id},
- {'projectId': test_id},
- {'authorizations':
- [{'userId': 'test', 'authorizationLevel': 'OWN'}]
- }])
- mocker.patch.object(DB, 'update', return_value={})
-
- res = client.put(f'/v2/scenarios/{test_id}', json={'scenario': {
- 'name': 'test',
- }})
- assert '200' in res.status
-
-
-def test_delete_project_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.delete(f'/v2/scenarios/{test_id}').status
-
-
-def test_delete_project_different_user(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- side_effect=[
- {'_id': test_id, 'portfolioId': test_id},
- {'projectId': test_id},
- {'authorizations':
- [{'userId': 'test', 'authorizationLevel': 'VIEW'}]
- }])
- mocker.patch.object(DB, 'delete_one', return_value=None)
- assert '403' in client.delete(f'/v2/scenarios/{test_id}').status
-
-
-def test_delete_project(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'portfolioId': test_id,
- 'googleId': 'test',
- 'scenarioIds': [test_id],
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'OWN'
- }]
- })
- mocker.patch.object(DB, 'delete_one', return_value={})
- mocker.patch.object(DB, 'update', return_value=None)
- res = client.delete(f'/v2/scenarios/{test_id}')
- assert '200' in res.status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/schedulers/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/schedulers/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/schedulers/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/schedulers/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/schedulers/endpoint.py
deleted file mode 100644
index f33159bf..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/schedulers/endpoint.py
+++ /dev/null
@@ -1,19 +0,0 @@
-from opendc.util.rest import Response
-
-SCHEDULERS = [
- 'mem',
- 'mem-inv',
- 'core-mem',
- 'core-mem-inv',
- 'active-servers',
- 'active-servers-inv',
- 'provisioned-cores',
- 'provisioned-cores-inv',
- 'random'
-]
-
-
-def GET(_):
- """Get all available Schedulers."""
-
- return Response(200, 'Successfully retrieved Schedulers.', [{'name': name} for name in SCHEDULERS])
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/schedulers/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/schedulers/test_endpoint.py
deleted file mode 100644
index 4950ca4c..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/schedulers/test_endpoint.py
+++ /dev/null
@@ -1,2 +0,0 @@
-def test_get_schedulers(client):
- assert '200' in client.get('/v2/schedulers').status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/topologies/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/topologies/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/topologies/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/endpoint.py
deleted file mode 100644
index 80618190..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/endpoint.py
+++ /dev/null
@@ -1,58 +0,0 @@
-from datetime import datetime
-
-from opendc.util.database import Database
-from opendc.models.project import Project
-from opendc.models.topology import Topology
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Topology."""
-
- request.check_required_parameters(path={'topologyId': 'string'})
-
- topology = Topology.from_id(request.params_path['topologyId'])
-
- topology.check_exists()
- topology.check_user_access(request.current_user['sub'], False)
-
- return Response(200, 'Successfully retrieved topology.', topology.obj)
-
-
-def PUT(request):
- """Update this topology"""
- request.check_required_parameters(path={'topologyId': 'string'}, body={'topology': {'name': 'string', 'rooms': {}}})
- topology = Topology.from_id(request.params_path['topologyId'])
-
- topology.check_exists()
- topology.check_user_access(request.current_user['sub'], True)
-
- topology.set_property('name', request.params_body['topology']['name'])
- topology.set_property('rooms', request.params_body['topology']['rooms'])
- topology.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
-
- topology.update()
-
- return Response(200, 'Successfully updated topology.', topology.obj)
-
-
-def DELETE(request):
- """Delete this topology"""
- request.check_required_parameters(path={'topologyId': 'string'})
-
- topology = Topology.from_id(request.params_path['topologyId'])
-
- topology.check_exists()
- topology.check_user_access(request.current_user['sub'], True)
-
- topology_id = topology.get_id()
-
- project = Project.from_id(topology.obj['projectId'])
- project.check_exists()
- if topology_id in project.obj['topologyIds']:
- project.obj['topologyIds'].remove(topology_id)
- project.update()
-
- old_object = topology.delete()
-
- return Response(200, 'Successfully deleted topology.', old_object)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/test_endpoint.py
deleted file mode 100644
index 96d2e08e..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/topologies/topologyId/test_endpoint.py
+++ /dev/null
@@ -1,113 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-test_id_2 = 24 * '2'
-
-
-def test_get_topology(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'EDIT'
- }]
- })
- res = client.get(f'/v2/topologies/{test_id}')
- assert '200' in res.status
-
-
-def test_get_topology_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get('/v2/topologies/1').status
-
-
-def test_get_topology_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'authorizations': []
- })
- res = client.get(f'/v2/topologies/{test_id}')
- assert '403' in res.status
-
-
-def test_get_topology_no_authorizations(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'projectId': test_id, 'authorizations': []})
- res = client.get(f'/v2/topologies/{test_id}')
- assert '403' in res.status
-
-
-def test_update_topology_missing_parameter(client):
- assert '400' in client.put(f'/v2/topologies/{test_id}').status
-
-
-def test_update_topology_non_existent(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.put(f'/v2/topologies/{test_id}', json={'topology': {'name': 'test_topology', 'rooms': {}}}).status
-
-
-def test_update_topology_not_authorized(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'authorizations': []
- })
- mocker.patch.object(DB, 'update', return_value={})
- assert '403' in client.put(f'/v2/topologies/{test_id}', json={
- 'topology': {
- 'name': 'updated_topology',
- 'rooms': {}
- }
- }).status
-
-
-def test_update_topology(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'OWN'
- }]
- })
- mocker.patch.object(DB, 'update', return_value={})
-
- assert '200' in client.put(f'/v2/topologies/{test_id}', json={
- 'topology': {
- 'name': 'updated_topology',
- 'rooms': {}
- }
- }).status
-
-
-def test_delete_topology(client, mocker):
- mocker.patch.object(DB,
- 'fetch_one',
- return_value={
- '_id': test_id,
- 'projectId': test_id,
- 'googleId': 'test',
- 'topologyIds': [test_id],
- 'authorizations': [{
- 'userId': 'test',
- 'authorizationLevel': 'OWN'
- }]
- })
- mocker.patch.object(DB, 'delete_one', return_value={})
- mocker.patch.object(DB, 'update', return_value=None)
- res = client.delete(f'/v2/topologies/{test_id}')
- assert '200' in res.status
-
-
-def test_delete_nonexistent_topology(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.delete(f'/v2/topologies/{test_id}').status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/traces/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/traces/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/traces/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/traces/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/traces/endpoint.py
deleted file mode 100644
index ee699e02..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/traces/endpoint.py
+++ /dev/null
@@ -1,10 +0,0 @@
-from opendc.models.trace import Trace
-from opendc.util.rest import Response
-
-
-def GET(_):
- """Get all available Traces."""
-
- traces = Trace.get_all()
-
- return Response(200, 'Successfully retrieved Traces', traces.obj)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/traces/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/traces/test_endpoint.py
deleted file mode 100644
index 36846bd9..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/traces/test_endpoint.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from opendc.util.database import DB
-
-
-def test_get_traces(client, mocker):
- mocker.patch.object(DB, 'fetch_all', return_value=[])
- assert '200' in client.get('/v2/traces').status
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/__init__.py b/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/__init__.py
+++ /dev/null
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/endpoint.py
deleted file mode 100644
index 670f88d1..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/endpoint.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from opendc.models.trace import Trace
-from opendc.util.rest import Response
-
-
-def GET(request):
- """Get this Trace."""
-
- request.check_required_parameters(path={'traceId': 'string'})
-
- trace = Trace.from_id(request.params_path['traceId'])
-
- trace.check_exists()
-
- return Response(200, 'Successfully retrieved trace.', trace.obj)
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/test_endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/test_endpoint.py
deleted file mode 100644
index 0c51538b..00000000
--- a/opendc-web/opendc-web-api/opendc/api/v2/traces/traceId/test_endpoint.py
+++ /dev/null
@@ -1,15 +0,0 @@
-from opendc.util.database import DB
-
-test_id = 24 * '1'
-
-
-def test_get_trace_non_existing(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value=None)
- assert '404' in client.get(f'/v2/traces/{test_id}').status
-
-
-def test_get_trace(client, mocker):
- mocker.patch.object(DB, 'fetch_one', return_value={'name': 'test trace'})
- res = client.get(f'/v2/traces/{test_id}')
- assert 'name' in res.json['content']
- assert '200' in res.status