devops_armory/cloud/gcp/dns/
update.rs1use super::models::CreateDNSRecord;
2
3pub async fn update_record_set(
7 project: String,
8 managed_zone: String,
9 token: String,
10 dns_name: String,
11 dns_type: String,
12 propagation_ttl: i32,
13 dns_rrdatas: Vec<String>,
14 dns_signatureRrdatas: Option<Vec<String>>,
15 dns_kind: String
16) -> Result<(), std::io::Error> {
17
18 let dns_data = CreateDNSRecord {
19 name: dns_name.clone(),
20 r#type: dns_type.clone(),
21 ttl: propagation_ttl,
22 rrdatas: dns_rrdatas,
23 signatureRrdatas: None,
24 kind: dns_kind
25 };
26
27 let client = awc::Client::default();
28 let request = client.patch(format!("https://dns.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/rrsets/{dns_name}/{dns_type}"))
29 .bearer_auth(&token)
30 .insert_header(("Content-Type", "application/json"))
31 .send_json(&dns_data)
32 .await
33 .unwrap();
34
35 let mut req = request;
36 let req_status = req.status().as_u16();
37 let respone = req.body().await.unwrap_or_default();
38
39 match req_status {
40
41 200 => {
42 println!("Request has been successfull: Status: {:?}, {:?}", req_status, respone);
43 },
44 400 => {
45 println!("Bad Request. Check URL parameters or body: {:?}", respone);
46 },
47 403 => {
48 println!("You don't have access to perform such request: {:?}", respone);
49 }
50 404 => {
51 println!("Requested resource does not exists: {:?}", respone);
52 },
53 409 => {
54 println!("Requested resource already exists! {:?}", respone)
55 }
56 _ => {
57 println!("Request status mismatch. Check response: {:?}", respone);
58 }
59
60 }
61
62 Ok(())
63
64}
65