//native
/**
* Get Project
* Retrieve a single Wiz project by its ID, including its security score, business impact and resource counts.
*/
export async function main(auth: RT.Wiz, project_id: string) {
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 query = `
query GetProject($id: ID!) {
project(id: $id) {
id
name
slug
description
businessUnit
archived
securityScore
riskProfile { businessImpact }
cloudAccountCount
cloudOrganizationCount
repositoryCount
kubernetesClusterCount
workloadCount
entityCount
technologyCount
teamMemberCount
identifiers
projectOwners { id }
resourceTagLinks { environment resourceTags { key value } }
}
}`
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: { id: project_id },
}),
})
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.project
}
Submitted by hugo989 5 days ago