devops_armory/cloud/gcp/vpc/subnet/
get.rs1use std::time::Duration;
2
3use crate::cloud::gcp::vpc::subnet::models::SubnetFingerprint;
4
5pub async fn get_subnetwork_info(
8 token: String,
9 project: String,
10 subnet_region: String,
11 subnet_name: String
12) -> Result<(), std::io::Error> {
13
14 let client = awc::Client::default();
15 let request = client.get(format!("https://compute.googleapis.com/compute/v1/projects/{project}/regions/{subnet_region}/subnetworks/{subnet_name}"))
16 .bearer_auth(&token)
17 .insert_header(("Content-Type", "application/json"))
18 .timeout(Duration::from_secs(30))
19 .send()
20 .await
21 .expect("Request GET subnet name could not been sent");
22
23 let mut req = request;
24 let req_status = req.status().as_u16();
25 let respone = req.body().await.unwrap_or_default();
26
27 match req_status {
28 200 => {
29 println!("Request has been successfull: Status: {:?}, {:?}", req_status, respone);
30 },
31 400 => {
32 println!("Bad Request. Check URL parameters or body: {:?}", respone);
33 },
34 403 => {
35 println!("You don't have access to perform such request: {:?}", respone);
36 }
37 404 => {
38 println!("Requested resource does not exists: {:?}", respone);
39 },
40 409 => {
41 println!("Requested resource already exists! {:?}", respone)
42 }
43 _ => {
44 println!("Request status mismatch. Check response: {:?}", respone);
45 }
46 }
47
48 Ok(())
49
50}
51
52pub async fn get_subnetwork_fingerprint(
55 token: String,
56 project: String,
57 subnet_region: String,
58 subnet_name: String
59) -> Result<String, std::io::Error> {
60
61
62 let client = awc::Client::default();
63 let request = client.get(format!("https://compute.googleapis.com/compute/v1/projects/{project}/regions/{subnet_region}/subnetworks/{subnet_name}"))
64 .bearer_auth(&token)
65 .insert_header(("Content-Type", "application/json"))
66 .timeout(Duration::from_secs(30))
67 .send()
68 .await
69 .expect("Request GET subnet fingerprint could not been sent")
70 .json::<SubnetFingerprint>()
71 .await
72 .unwrap_or_default();
73
74 Ok(request.fingerprint)
75
76}