Edits history of script submission #22712 for ' Get Issue (wiz)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Issue
     * Retrieve a single Wiz issue by its ID, including the triggering rule, the affected entity, projects and notes.
     */
    export async function main(auth: RT.Wiz, issue_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 GetIssue($filterBy: IssueFilters, $first: Int) {
      issues: issuesV2(filterBy: $filterBy, first: $first) {
        nodes {
          id
          type
          severity
          status
          createdAt
          updatedAt
          dueAt
          resolvedAt
          statusChangedAt
          resolutionReason
          sourceRule {
            __typename
            ... on Control { id name description resolutionRecommendation }
            ... on CloudConfigurationRule { id name description remediationInstructions serviceType }
            ... on CloudEventRule { id name description sourceType }
          }
          entitySnapshot {
            id
            name
            type
            nativeType
            status
            cloudPlatform
            cloudProviderURL
            region
            subscriptionName
            subscriptionExternalId
            providerId
            externalId
            tags
          }
          projects { id name slug businessUnit riskProfile { businessImpact } }
          notes { id text createdAt updatedAt user { name email } serviceAccount { name } }
          serviceTickets { externalId name url }
        }
      }
    }`
    
      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: { filterBy: { id: issue_id }, first: 1 },
        }),
      })
    
      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.issues.nodes[0] ?? null
    }
    

    Submitted by hugo989 5 days ago