devops_armory/cloud/gcp/ssl/
create.rs1use std::time::Duration;
2
3use super::models::CreateSSL;
4
5pub async fn create_ssl(
8 token: String,
9 project: String,
10 gcp_ssl_body: CreateSSL
11) -> Result<(), std::io::Error> {
12
13 let data = gcp_ssl_body;
14
15 let client = awc::Client::default();
16 let create_ssl_request = client
17 .post(format!("https://compute.googleapis.com/compute/v1/projects/{project}/global/sslCertificates"))
18 .bearer_auth(&token)
19 .insert_header(("Content-Type", "application/json"))
20 .timeout(Duration::from_secs(30))
21 .send_json(&data)
22 .await
23 .expect("Request CREATE global SSL failed");
24
25 let mut req = create_ssl_request;
26 let req_status = req.status().as_u16();
27 let respone = req.body().await.unwrap_or_default();
28
29 match req_status {
30 200 => {
31 println!("Request has been successfull: Status: {:?}, {:?}", req_status, respone);
32 },
33 201 => {
34 println!("Successfully created service: {:?}", respone);
35 }
36 400 => {
37 println!("Bad Request. Check URL parameters or body: {:?}", respone);
38 },
39 403 => {
40 println!("You don't have access to perform such request: {:?}", respone);
41 }
42 404 => {
43 println!("Requested resource does not exists: {:?}", respone);
44 },
45 409 => {
46 println!("Requested resource already exists! {:?}", respone)
47 }
48 _ => {
49 println!("Request status mismatch. Check response: {:?}", respone);
50 }
51 }
52
53 Ok(())
54
55}
56