//native
/**
* List Configuration Findings
* List cloud configuration findings (misconfigurations from compliance rule checks), with optional filters by severity, result and status.
*/
export async function main(
auth: RT.Wiz,
severity: ("NONE" | "LOW" | "MEDIUM" | "HIGH" | "CRITICAL")[] | undefined,
result_filter: ("PASS" | "FAIL" | "ERROR" | "NOT_ASSESSED")[] | undefined,
status: ("OPEN" | "IN_PROGRESS" | "RESOLVED" | "REJECTED")[] | undefined,
first: number | undefined,
after: 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 filterBy: { [key: string]: any } = {}
if (severity && severity.length > 0) filterBy.severity = severity
if (result_filter && result_filter.length > 0) filterBy.result = result_filter
if (status && status.length > 0) filterBy.status = status
const query = `
query ListConfigurationFindings($first: Int, $after: String, $filterBy: ConfigurationFindingFilters) {
configurationFindings(first: $first, after: $after, filterBy: $filterBy) {
totalCount
pageInfo { hasNextPage endCursor }
nodes {
id
result
severity
status
resolutionReason
remediation
analyzedAt
rule { id }
subscription { id }
resource {
id
name
type
nativeType
region
cloudPlatform
status
projects { id }
tags { 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: { first: first ?? 50, after: after || null, filterBy },
}),
})
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.configurationFindings
}
Submitted by hugo989 5 days ago