summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-ui/src/api')
-rw-r--r--opendc-web/opendc-web-ui/src/api/index.js20
-rw-r--r--opendc-web/opendc-web-ui/src/api/portfolios.js16
-rw-r--r--opendc-web/opendc-web-ui/src/api/prefabs.js16
-rw-r--r--opendc-web/opendc-web-ui/src/api/projects.js20
-rw-r--r--opendc-web/opendc-web-ui/src/api/scenarios.js16
-rw-r--r--opendc-web/opendc-web-ui/src/api/schedulers.js4
-rw-r--r--opendc-web/opendc-web-ui/src/api/token-signin.js32
-rw-r--r--opendc-web/opendc-web-ui/src/api/topologies.js16
-rw-r--r--opendc-web/opendc-web-ui/src/api/traces.js4
-rw-r--r--opendc-web/opendc-web-ui/src/api/users.js39
10 files changed, 59 insertions, 124 deletions
diff --git a/opendc-web/opendc-web-ui/src/api/index.js b/opendc-web/opendc-web-ui/src/api/index.js
index 65358745..680d49ce 100644
--- a/opendc-web/opendc-web-ui/src/api/index.js
+++ b/opendc-web/opendc-web-ui/src/api/index.js
@@ -20,30 +20,32 @@
* SOFTWARE.
*/
-import { getAuthToken } from '../auth'
-
const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL
/**
* Send the specified request to the OpenDC API.
+ *
+ * @param auth The authentication context.
* @param path Relative path for the API.
* @param method The method to use for the request.
* @param body The body of the request.
*/
-export async function request(path, method = 'GET', body) {
- const res = await fetch(`${apiUrl}/v2/${path}`, {
+export async function request(auth, path, method = 'GET', body) {
+ const { getAccessTokenSilently } = auth
+ const token = await getAccessTokenSilently()
+ const response = await fetch(`${apiUrl}/${path}`, {
method: method,
headers: {
- 'auth-token': getAuthToken(),
+ Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: body && JSON.stringify(body),
})
- const { status, content } = await res.json()
+ const json = await response.json()
- if (status.code !== 200) {
- throw status
+ if (!response.ok) {
+ throw response.message
}
- return content
+ return json.data
}
diff --git a/opendc-web/opendc-web-ui/src/api/portfolios.js b/opendc-web/opendc-web-ui/src/api/portfolios.js
index 6202e702..28898e6a 100644
--- a/opendc-web/opendc-web-ui/src/api/portfolios.js
+++ b/opendc-web/opendc-web-ui/src/api/portfolios.js
@@ -22,18 +22,18 @@
import { request } from './index'
-export function addPortfolio(projectId, portfolio) {
- return request(`projects/${projectId}/portfolios`, 'POST', { portfolio })
+export function addPortfolio(auth, projectId, portfolio) {
+ return request(auth, `projects/${projectId}/portfolios`, 'POST', { portfolio })
}
-export function getPortfolio(portfolioId) {
- return request(`portfolios/${portfolioId}`)
+export function getPortfolio(auth, portfolioId) {
+ return request(auth, `portfolios/${portfolioId}`)
}
-export function updatePortfolio(portfolioId, portfolio) {
- return request(`portfolios/${portfolioId}`, 'PUT', { portfolio })
+export function updatePortfolio(auth, portfolioId, portfolio) {
+ return request(auth, `portfolios/${portfolioId}`, 'PUT', { portfolio })
}
-export function deletePortfolio(portfolioId) {
- return request(`portfolios/${portfolioId}`, 'DELETE')
+export function deletePortfolio(auth, portfolioId) {
+ return request(auth, `portfolios/${portfolioId}`, 'DELETE')
}
diff --git a/opendc-web/opendc-web-ui/src/api/prefabs.js b/opendc-web/opendc-web-ui/src/api/prefabs.js
index a8bd3f3b..eb9aa23c 100644
--- a/opendc-web/opendc-web-ui/src/api/prefabs.js
+++ b/opendc-web/opendc-web-ui/src/api/prefabs.js
@@ -22,18 +22,18 @@
import { request } from './index'
-export function getPrefab(prefabId) {
- return request(`prefabs/${prefabId}`)
+export function getPrefab(auth, prefabId) {
+ return request(auth, `prefabs/${prefabId}`)
}
-export function addPrefab(prefab) {
- return request('prefabs', 'POST', { prefab })
+export function addPrefab(auth, prefab) {
+ return request(auth, 'prefabs/', 'POST', { prefab })
}
-export function updatePrefab(prefab) {
- return request(`prefabs/${prefab._id}`, 'PUT', { prefab })
+export function updatePrefab(auth, prefab) {
+ return request(auth, `prefabs/${prefab._id}`, 'PUT', { prefab })
}
-export function deletePrefab(prefabId) {
- return request(`prefabs/${prefabId}`, 'DELETE')
+export function deletePrefab(auth, prefabId) {
+ return request(auth, `prefabs/${prefabId}`, 'DELETE')
}
diff --git a/opendc-web/opendc-web-ui/src/api/projects.js b/opendc-web/opendc-web-ui/src/api/projects.js
index 9ff7deda..93052080 100644
--- a/opendc-web/opendc-web-ui/src/api/projects.js
+++ b/opendc-web/opendc-web-ui/src/api/projects.js
@@ -22,18 +22,22 @@
import { request } from './index'
-export function getProject(projectId) {
- return request(`projects/${projectId}`)
+export function getProjects(auth) {
+ return request(auth, `projects/`)
}
-export function addProject(project) {
- return request('projects', 'POST', { project })
+export function getProject(auth, projectId) {
+ return request(auth, `projects/${projectId}`)
}
-export function updateProject(project) {
- return request(`projects/${project._id}`, 'PUT', { project })
+export function addProject(auth, project) {
+ return request(auth, 'projects/', 'POST', { project })
}
-export function deleteProject(projectId) {
- return request(`projects/${projectId}`, 'DELETE')
+export function updateProject(auth, project) {
+ return request(auth, `projects/${project._id}`, 'PUT', { project })
+}
+
+export function deleteProject(auth, projectId) {
+ return request(auth, `projects/${projectId}`, 'DELETE')
}
diff --git a/opendc-web/opendc-web-ui/src/api/scenarios.js b/opendc-web/opendc-web-ui/src/api/scenarios.js
index 9f8c717b..095aa788 100644
--- a/opendc-web/opendc-web-ui/src/api/scenarios.js
+++ b/opendc-web/opendc-web-ui/src/api/scenarios.js
@@ -22,18 +22,18 @@
import { request } from './index'
-export function addScenario(portfolioId, scenario) {
- return request(`portfolios/${portfolioId}/scenarios`, 'POST', { scenario })
+export function addScenario(auth, portfolioId, scenario) {
+ return request(auth, `portfolios/${portfolioId}/scenarios`, 'POST', { scenario })
}
-export function getScenario(scenarioId) {
- return request(`scenarios/${scenarioId}`)
+export function getScenario(auth, scenarioId) {
+ return request(auth, `scenarios/${scenarioId}`)
}
-export function updateScenario(scenarioId, scenario) {
- return request(`scenarios/${scenarioId}`, 'PUT', { scenario })
+export function updateScenario(auth, scenarioId, scenario) {
+ return request(auth, `scenarios/${scenarioId}`, 'PUT', { scenario })
}
-export function deleteScenario(scenarioId) {
- return request(`scenarios/${scenarioId}`, 'DELETE')
+export function deleteScenario(auth, scenarioId) {
+ return request(auth, `scenarios/${scenarioId}`, 'DELETE')
}
diff --git a/opendc-web/opendc-web-ui/src/api/schedulers.js b/opendc-web/opendc-web-ui/src/api/schedulers.js
index 7791e51e..1b69f1a1 100644
--- a/opendc-web/opendc-web-ui/src/api/schedulers.js
+++ b/opendc-web/opendc-web-ui/src/api/schedulers.js
@@ -22,6 +22,6 @@
import { request } from './index'
-export function getAllSchedulers() {
- return request('schedulers')
+export function getAllSchedulers(auth) {
+ return request(auth, 'schedulers/')
}
diff --git a/opendc-web/opendc-web-ui/src/api/token-signin.js b/opendc-web/opendc-web-ui/src/api/token-signin.js
deleted file mode 100644
index a3761fa1..00000000
--- a/opendc-web/opendc-web-ui/src/api/token-signin.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.
- */
-
-export function performTokenSignIn(token) {
- const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL
-
- return fetch(`${apiUrl}/tokensignin`, {
- method: 'POST',
- body: new URLSearchParams({
- idtoken: token,
- }),
- }).then((res) => res.json())
-}
diff --git a/opendc-web/opendc-web-ui/src/api/topologies.js b/opendc-web/opendc-web-ui/src/api/topologies.js
index e6df73c7..c8744e6c 100644
--- a/opendc-web/opendc-web-ui/src/api/topologies.js
+++ b/opendc-web/opendc-web-ui/src/api/topologies.js
@@ -22,18 +22,18 @@
import { request } from './index'
-export function addTopology(topology) {
- return request(`projects/${topology.projectId}/topologies`, 'POST', { topology })
+export function addTopology(auth, topology) {
+ return request(auth, `projects/${topology.projectId}/topologies`, 'POST', { topology })
}
-export function getTopology(topologyId) {
- return request(`topologies/${topologyId}`)
+export function getTopology(auth, topologyId) {
+ return request(auth, `topologies/${topologyId}`)
}
-export function updateTopology(topology) {
- return request(`topologies/${topology._id}`, 'PUT', { topology })
+export function updateTopology(auth, topology) {
+ return request(auth, `topologies/${topology._id}`, 'PUT', { topology })
}
-export function deleteTopology(topologyId) {
- return request(`topologies/${topologyId}`, 'DELETE')
+export function deleteTopology(auth, topologyId) {
+ return request(auth, `topologies/${topologyId}`, 'DELETE')
}
diff --git a/opendc-web/opendc-web-ui/src/api/traces.js b/opendc-web/opendc-web-ui/src/api/traces.js
index 1c5cfa1d..df03a2dd 100644
--- a/opendc-web/opendc-web-ui/src/api/traces.js
+++ b/opendc-web/opendc-web-ui/src/api/traces.js
@@ -22,6 +22,6 @@
import { request } from './index'
-export function getAllTraces() {
- return request('traces')
+export function getAllTraces(auth) {
+ return request(auth, 'traces/')
}
diff --git a/opendc-web/opendc-web-ui/src/api/users.js b/opendc-web/opendc-web-ui/src/api/users.js
deleted file mode 100644
index 3da030ad..00000000
--- a/opendc-web/opendc-web-ui/src/api/users.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.
- */
-
-import { request } from './index'
-
-export function getUserByEmail(email) {
- return request(`users` + new URLSearchParams({ email }))
-}
-
-export function addUser(user) {
- return request('users', 'POST', { user })
-}
-
-export function getUser(userId) {
- return request(`users/${userId}`)
-}
-
-export function deleteUser(userId) {
- return request(`users/${userId}`, 'DELETE')
-}