//native
/**
* Update Issue
* Change a Wiz issue's status (e.g. resolve, reject, set in progress). Resolving or rejecting requires both a resolution reason and a note.
*/
export async function main(
auth: RT.Wiz,
issue_id: string,
status: "OPEN" | "IN_PROGRESS" | "RESOLVED" | "REJECTED",
note: string | undefined,
resolution_reason:
| "OBJECT_DELETED"
| "ISSUE_FIXED"
| "CONTROL_CHANGED"
| "CONTROL_DISABLED"
| "CONTROL_DELETED"
| "FALSE_POSITIVE"
| "EXCEPTION"
| "WONT_FIX"
| undefined,
due_at: string | undefined
) {
const tokenResponse = await fetch(
auth.auth_url || "https://auth.app.wiz.io/oauth/token",
{
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
grant_type: "client_credentials",
audience: auth.audience || "wiz-api",
client_id: auth.client_id,
client_secret: auth.client_secret,
}),
}
)
if (!tokenResponse.ok) {
throw new Error(`${tokenResponse.status} ${await tokenResponse.text()}`)
}
const { access_token } = (await tokenResponse.json()) as {
access_token: string
}
const patch: { [key: string]: any } = { status }
if (note !== undefined && note !== "") patch.note = note
if (resolution_reason !== undefined)
patch.resolutionReason = resolution_reason
if (due_at !== undefined && due_at !== "") patch.dueAt = due_at
const query = `
mutation UpdateIssue($issueId: ID!, $patch: UpdateIssuePatch) {
updateIssue(input: { id: $issueId, patch: $patch }) {
issue {
id
status
dueAt
resolutionReason
notes { id text createdAt updatedAt user { name email } }
}
}
}`
const response = await fetch(auth.api_endpoint, {
method: "POST",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query,
variables: { issueId: issue_id, patch },
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const result = (await response.json()) as { data?: any; errors?: any }
if (result.errors) {
throw new Error(JSON.stringify(result.errors))
}
return result.data.updateIssue.issue
}
Submitted by hugo989 5 days ago