1 | |
2 |
|
3 | |
4 | * Get Project |
5 | * Retrieve a single Wiz project by its ID, including its security score, business impact and resource counts. |
6 | */ |
7 | export async function main(auth: RT.Wiz, project_id: string) { |
8 | const tokenResponse = await fetch( |
9 | auth.auth_url || "https://auth.app.wiz.io/oauth/token", |
10 | { |
11 | method: "POST", |
12 | headers: { "Content-Type": "application/x-www-form-urlencoded" }, |
13 | body: new URLSearchParams({ |
14 | grant_type: "client_credentials", |
15 | audience: auth.audience || "wiz-api", |
16 | client_id: auth.client_id, |
17 | client_secret: auth.client_secret, |
18 | }), |
19 | } |
20 | ) |
21 | if (!tokenResponse.ok) { |
22 | throw new Error(`${tokenResponse.status} ${await tokenResponse.text()}`) |
23 | } |
24 | const { access_token } = (await tokenResponse.json()) as { |
25 | access_token: string |
26 | } |
27 |
|
28 | const query = ` |
29 | query GetProject($id: ID!) { |
30 | project(id: $id) { |
31 | id |
32 | name |
33 | slug |
34 | description |
35 | businessUnit |
36 | archived |
37 | securityScore |
38 | riskProfile { businessImpact } |
39 | cloudAccountCount |
40 | cloudOrganizationCount |
41 | repositoryCount |
42 | kubernetesClusterCount |
43 | workloadCount |
44 | entityCount |
45 | technologyCount |
46 | teamMemberCount |
47 | identifiers |
48 | projectOwners { id } |
49 | resourceTagLinks { environment resourceTags { key value } } |
50 | } |
51 | }` |
52 |
|
53 | const response = await fetch(auth.api_endpoint, { |
54 | method: "POST", |
55 | headers: { |
56 | Authorization: `Bearer ${access_token}`, |
57 | "Content-Type": "application/json", |
58 | Accept: "application/json", |
59 | }, |
60 | body: JSON.stringify({ |
61 | query, |
62 | variables: { id: project_id }, |
63 | }), |
64 | }) |
65 |
|
66 | if (!response.ok) { |
67 | throw new Error(`${response.status} ${await response.text()}`) |
68 | } |
69 |
|
70 | const result = (await response.json()) as { data?: any; errors?: any } |
71 | if (result.errors) { |
72 | throw new Error(JSON.stringify(result.errors)) |
73 | } |
74 | return result.data.project |
75 | } |
76 |
|