Skip to main content

devops_armory/cloud/gcp/project/
list.rs

1use std::time::Duration;
2
3/// LIST GCP projects
4/// Token and organization ID required
5pub async fn list_gcp_projects(
6    token: String,
7    org_id: String
8) -> Result<(), std::io::Error> {
9
10    let client = awc::Client::default();
11    let request = client.get(format!("https://cloudresourcemanager.googleapis.com/v3/projects?parent={org_id}"))
12        .bearer_auth(token)
13        .insert_header(("Content-Type", "application/json"))
14        .timeout(Duration::from_secs(30))
15        .send()
16        .await
17        .expect("Request: GET Project List could not been sent");
18
19    let mut req = request;
20    let req_status = req.status().as_u16();
21    let respone = req.body().await.unwrap_or_default();
22
23    match req_status {
24
25        200 => {
26            println!("Request has been successfull: Status: {:?}, {:?}", req_status, respone);
27        },
28        400 => {
29            println!("Bad Request. Check URL parameters or body: {:?}", respone);
30        },
31        403 => {
32            println!("You don't have access to perform such request: {:?}", respone);
33        }
34        404 => {
35            println!("Requested resource does not exists: {:?}", respone);
36        },
37        409 => {
38            println!("Requested resource already exists! {:?}", respone)
39        }
40        _ => {
41            println!("Request status mismatch. Check response: {:?}", respone);
42        }
43
44    }
45
46    Ok(())
47
48}
49