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