agola-web/src/util/data.js

85 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-12-09 13:21:20 +00:00
import { apiurl, fetch } from "@/util/auth";
export async function fetchCurrentUser() {
let path = "/user"
let res = await fetch(apiurl(path));
return res.json();
}
export async function fetchRuns(group, lastrun) {
let u = apiurl("/runs");
if (group) {
u.searchParams.append("group", group)
}
if (lastrun) {
u.searchParams.append("lastrun", true)
}
let res = await fetch(u)
return res.json();
}
2018-12-09 13:21:20 +00:00
export async function fetchRun(runid) {
2019-04-08 14:12:08 +00:00
let res = await fetch(apiurl("/runs/" + runid));
2018-12-09 13:21:20 +00:00
return res.json();
}
export async function fetchTask(runid, taskid) {
2019-04-08 14:12:08 +00:00
let res = await fetch(apiurl("/runs/" + runid + "/tasks/" + taskid))
2018-12-09 13:21:20 +00:00
return res.json();
}
export async function fetchProject(ref) {
let path = "/projects/" + encodeURIComponent(ref)
let res = await fetch(apiurl(path));
return res.json();
}
export async function fetchVariables(ownertype, ref, all) {
let path
if (ownertype == "project") {
path = "/projects/"
} else if (ownertype == "projectgroup") {
path = "/projectgroups/"
}
path += encodeURIComponent(ref);
path += "/variables";
if (all) {
path += "?tree&removeoverridden";
}
let res = await fetch(apiurl(path));
return res.json();
}
export async function createUserToken(username, tokenname) {
let path = "/users/" + username + "/tokens"
let init = {
method: "POST",
body: JSON.stringify({
token_name: tokenname,
})
}
let res = await fetch(apiurl(path), init)
return res.json();
}
export async function deleteUserToken(username, tokenname) {
let path = "/users/" + username + "/tokens/" + tokenname
let init = {
method: "DELETE",
}
let res = await fetch(apiurl(path), init)
return res.text();
}
export async function approveTask(runid, taskid) {
let path = "/runs/" + runid + "/tasks/" + taskid + "/actions"
let init = {
method: "PUT",
body: JSON.stringify({
action_type: "approve"
})
}
let res = await fetch(apiurl(path), init)
return res.json();
2018-12-09 13:21:20 +00:00
}