2019-05-13 14:29:47 +00:00
|
|
|
import { apiurl, loginapi } from "@/util/auth";
|
|
|
|
import { fetch as authfetch } from "@/util/auth";
|
|
|
|
|
|
|
|
export async function fetch(url, init) {
|
|
|
|
try {
|
|
|
|
let res = await authfetch(url, init)
|
|
|
|
if (!res.ok) {
|
|
|
|
let data = await res.json()
|
|
|
|
return { data: null, error: data.message }
|
|
|
|
} else {
|
|
|
|
if (res.status == 204) {
|
|
|
|
return { data: null, error: null }
|
|
|
|
}
|
|
|
|
return { data: await res.json(), error: null }
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
return { data: null, error: "api call failed: " + e }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function login(username, password, remotesourcename) {
|
|
|
|
let init = {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
remote_source_name: remotesourcename,
|
|
|
|
login_name: username,
|
|
|
|
password: password
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let res = await loginapi(init)
|
|
|
|
if (!res.ok) {
|
|
|
|
let data = await res.json()
|
|
|
|
return { data: null, error: data.message }
|
|
|
|
} else {
|
|
|
|
return { data: await res.json(), error: null }
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
return { data: null, error: "api call failed: " + e }
|
|
|
|
}
|
|
|
|
}
|
2018-12-09 13:21:20 +00:00
|
|
|
|
2019-04-03 15:51:41 +00:00
|
|
|
export async function fetchCurrentUser() {
|
|
|
|
let path = "/user"
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path));
|
2019-04-03 15:51:41 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(u)
|
2019-03-27 14:41:29 +00:00
|
|
|
}
|
|
|
|
|
2018-12-09 13:21:20 +00:00
|
|
|
export async function fetchRun(runid) {
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl("/runs/" + runid));
|
2018-12-09 13:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function fetchTask(runid, taskid) {
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl("/runs/" + runid + "/tasks/" + taskid))
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function fetchUser(username) {
|
|
|
|
let path = "/users/" + username
|
|
|
|
return await fetch(apiurl(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function fetchProjectGroupSubgroups(projectgroupref) {
|
|
|
|
let path = "/projectgroups/" + encodeURIComponent(projectgroupref)
|
|
|
|
path += "/subgroups";
|
|
|
|
|
|
|
|
return await fetch(apiurl(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function fetchProjectGroupProjects(projectgroupref) {
|
|
|
|
let path = "/projectgroups/" + encodeURIComponent(projectgroupref)
|
|
|
|
path += "/projects";
|
|
|
|
|
|
|
|
return await fetch(apiurl(path));
|
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)
|
|
|
|
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path));
|
2019-04-02 16:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path));
|
2019-04-03 15:51:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 21:44:02 +00:00
|
|
|
export async function createOrganization(orgname, visibility) {
|
|
|
|
let path = "/orgs"
|
|
|
|
let init = {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: orgname,
|
|
|
|
visibility: visibility,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return await fetch(apiurl(path), init)
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-04-03 15:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteUserToken(username, tokenname) {
|
|
|
|
let path = "/users/" + username + "/tokens/" + tokenname
|
|
|
|
let init = {
|
|
|
|
method: "DELETE",
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-04-08 15:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 15:59:23 +00:00
|
|
|
export async function deleteLinkedAccount(username, laid) {
|
|
|
|
let path = "/users/" + username + "/linkedaccounts/" + laid
|
|
|
|
let init = {
|
|
|
|
method: "DELETE",
|
|
|
|
}
|
|
|
|
return await fetch(apiurl(path), init)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-04-08 15:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function stopRun(runid) {
|
|
|
|
let path = "/runs/" + runid + "/actions"
|
|
|
|
let init = {
|
|
|
|
method: "PUT",
|
|
|
|
body: JSON.stringify({
|
|
|
|
action_type: "stop"
|
|
|
|
})
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-04-08 15:45:30 +00:00
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
})
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-05-06 15:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function fetchRemoteSources() {
|
|
|
|
let path = "/remotesources"
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path));
|
2019-05-06 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function userRemoteRepos(remotesourceid) {
|
|
|
|
let path = "/user/remoterepos/" + remotesourceid
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path));
|
2019-05-06 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createProjectGroup(parentref, name) {
|
|
|
|
let path = "/projectgroups"
|
|
|
|
let init = {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: name,
|
|
|
|
parent_ref: parentref,
|
|
|
|
visibility: "public",
|
|
|
|
})
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-05-06 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function createProject(parentref, name, remotesourcename, remoterepopath) {
|
|
|
|
let path = "/projects"
|
|
|
|
let init = {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: name,
|
|
|
|
parent_ref: parentref,
|
|
|
|
visibility: "public",
|
|
|
|
remote_source_name: remotesourcename,
|
|
|
|
repo_path: remoterepopath,
|
|
|
|
})
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-05-11 12:30:16 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 15:17:02 +00:00
|
|
|
export async function updateProject(projectref, name, visibility) {
|
|
|
|
let path = "/projects/" + encodeURIComponent(projectref)
|
|
|
|
let init = {
|
|
|
|
method: "PUT",
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: name,
|
|
|
|
visibility: visibility,
|
|
|
|
})
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-05-13 15:17:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-11 12:30:16 +00:00
|
|
|
export async function deleteProject(projectref) {
|
|
|
|
let path = "/projects/" + encodeURIComponent(projectref)
|
|
|
|
let init = {
|
|
|
|
method: "DELETE",
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2019-05-11 13:12:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteProjectGroup(projectgroupref) {
|
|
|
|
let path = "/projectgroups/" + encodeURIComponent(projectgroupref)
|
|
|
|
let init = {
|
|
|
|
method: "DELETE",
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
return await fetch(apiurl(path), init)
|
2018-12-09 13:21:20 +00:00
|
|
|
}
|