2018-12-09 13:21:20 +00:00
|
|
|
import { apiurl, fetch } from "@/util/auth";
|
|
|
|
|
2019-04-03 15:51:41 +00:00
|
|
|
export async function fetchCurrentUser() {
|
|
|
|
let path = "/user"
|
|
|
|
let res = await fetch(apiurl(path));
|
|
|
|
return res.json();
|
|
|
|
}
|
|
|
|
|
2019-03-27 14:41:29 +00:00
|
|
|
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();
|
2019-03-22 07:39:03 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 16:08:03 +00:00
|
|
|
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);
|
2019-03-22 07:39:03 +00:00
|
|
|
path += "/variables";
|
|
|
|
if (all) {
|
|
|
|
path += "?tree&removeoverridden";
|
|
|
|
}
|
|
|
|
let res = await fetch(apiurl(path));
|
|
|
|
return res.json();
|
2019-04-03 15:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2019-04-08 15:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 15:45:30 +00:00
|
|
|
export async function restartRun(runid, fromStart) {
|
|
|
|
let path = "/runs/" + runid + "/actions"
|
|
|
|
let init = {
|
|
|
|
method: "PUT",
|
|
|
|
body: JSON.stringify({
|
|
|
|
action_type: "restart",
|
|
|
|
from_start: fromStart
|
|
|
|
})
|
|
|
|
}
|
|
|
|
let res = await fetch(apiurl(path), init)
|
|
|
|
return res.json();
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function stopRun(runid) {
|
|
|
|
let path = "/runs/" + runid + "/actions"
|
|
|
|
let init = {
|
|
|
|
method: "PUT",
|
|
|
|
body: JSON.stringify({
|
|
|
|
action_type: "stop"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
let res = await fetch(apiurl(path), init)
|
|
|
|
return res.json();
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:43:34 +00:00
|
|
|
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();
|
2019-05-06 15:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function fetchRemoteSources() {
|
|
|
|
let path = "/remotesources"
|
|
|
|
let res = await fetch(apiurl(path));
|
|
|
|
return res.json();
|
2018-12-09 13:21:20 +00:00
|
|
|
}
|