Skip to main content

devops_armory/cloud/gcp/sql/
get.rs

1use std::time::Duration;
2
3/// Get SQL instance info
4/// Token, project, sql instance name need to be provided
5pub async fn get_sql_instance_info(
6    token: String,
7    project: String,
8    sql_instance_name: String
9) -> Result<(), std::io::Error> {
10
11    let client = awc::Client::default();
12    let request = client.get(format!("https://sqladmin.googleapis.com/v1/projects/{project}/instances/{sql_instance_name}"))
13        .bearer_auth(&token)
14        .insert_header(("Content-Type", "application/json"))
15        .timeout(Duration::from_secs(30))
16        .send()
17        .await
18        .expect("Request GET SQL instance could not been sent");
19
20    let mut req = request;
21    let req_status = req.status().as_u16();
22    let respone = req.body().await.unwrap_or_default();
23
24    match req_status {
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    Ok(())
46
47}