csm-rs 0.43.23

A library for Shasta
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
/// Structs related to CFS confguration with data related to most recent commit id like, author
/// name, commit date, etc

pub mod v2 {
    use std::collections::BTreeMap;

    use serde::{Deserialize, Serialize};
    use serde_yaml::Value;

    use crate::common::gitea;

    #[derive(Debug, Serialize, Deserialize, Clone)]
    pub struct Layer {
        #[serde(skip_serializing_if = "Option::is_none")] // Either commit or branch is passed
        pub name: Option<String>,
        #[serde(rename = "cloneUrl")]
        #[serde(skip_serializing_if = "Option::is_none")]
        // Either commit or branch is passed
        pub clone_url: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")] // Either commit or branch is passed
        pub commit: Option<String>,
        playbook: String,
        #[serde(skip_serializing_if = "Option::is_none")] // Either commit or branch is passed
        pub branch: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")]
        pub tag: Option<String>,
        #[serde(rename = "specialParameters")]
        #[serde(skip_serializing_if = "Option::is_none")]
        pub special_parameters: Option<Vec<SpecialParameter>>,
    }

    #[derive(Debug, Serialize, Deserialize, Clone)]
    pub struct SpecialParameter {
        #[serde(rename = "imsRequiredDkms")]
        #[serde(skip_serializing_if = "Option::is_none")]
        ims_required_dkms: Option<bool>,
    }

    #[derive(Debug, Deserialize, Serialize, Clone)]
    pub struct CfsConfigurationRequest {
        pub name: String,
        pub layers: Vec<Layer>,
    }

    impl Layer {
        pub fn new(
            clone_url: Option<String>,
            commit: Option<String>,
            name: Option<String>,
            playbook: String,
            branch: Option<String>,
            tag: Option<String>,
            special_parameters: Option<Vec<SpecialParameter>>,
        ) -> Self {
            Self {
                clone_url,
                commit,
                name,
                playbook,
                branch,
                tag,
                special_parameters,
            }
        }
    }

    impl Default for CfsConfigurationRequest {
        fn default() -> Self {
            Self::new()
        }
    }

    impl CfsConfigurationRequest {
        pub fn new() -> Self {
            Self {
                name: String::default(),
                layers: Vec::default(),
            }
        }

        pub fn add_layer(&mut self, layer: Layer) {
            self.layers.push(layer);
        }

        pub async fn from_sat_file_serde_yaml(
            shasta_root_cert: &[u8],
            gitea_base_url: &str,
            gitea_token: &str,
            configuration_yaml: &serde_yaml::Value,
            cray_product_catalog: &BTreeMap<String, String>,
            site_name: &str,
        ) -> (String, Self) {
            let cfs_configuration_name;
            let mut cfs_configuration = Self::new();

            cfs_configuration_name = configuration_yaml["name"].as_str().unwrap().to_string();

            cfs_configuration.name = configuration_yaml["name"].as_str().unwrap().to_string();

            for layer_yaml in configuration_yaml["layers"].as_sequence().unwrap() {
                // println!("\n\n### Layer:\n{:#?}\n", layer_json);

                if layer_yaml.get("git").is_some() {
                    // Git layer

                    let layer_name = layer_yaml["name"].as_str().unwrap().to_string();

                    let repo_url = layer_yaml["git"]["url"].as_str().unwrap().to_string();

                    let commit_id_value_opt = layer_yaml["git"].get("commit");
                    let tag_value_opt = layer_yaml["git"].get("tag");
                    let branch_value_opt = layer_yaml["git"].get("branch");

                    let commit_id_opt: Option<String> = if commit_id_value_opt.is_some() {
                        // Git commit id
                        layer_yaml["git"]
                            .get("commit")
                            .map(|commit_id| commit_id.as_str().unwrap().to_string())
                    } else if let Some(git_tag_value) = tag_value_opt {
                        // Git tag
                        let git_tag = git_tag_value.as_str().unwrap();

                        log::info!("git tag: {}", git_tag_value.as_str().unwrap());

                        let tag_details_rslt = gitea::http_client::get_tag_details(
                            &repo_url,
                            git_tag,
                            gitea_token,
                            shasta_root_cert,
                            site_name,
                        )
                        .await;

                        let tag_details = if let Ok(tag_details) = tag_details_rslt {
                            log::debug!("tag details:\n{:#?}", tag_details);
                            tag_details
                        } else {
                            eprintln!("ERROR - Could not get details for git tag '{}' in CFS configuration '{}'. Reason:\n{:#?}", git_tag, cfs_configuration.name, tag_details_rslt);
                            std::process::exit(1);
                        };

                        // Assumming user sets an existing tag name. It could be an annotated tag
                        // (different object than the commit id with its own sha value) or a
                        // lightweight tag (pointer to commit id, therefore the tag will have the
                        // same sha as the commit id it points to), either way CFS session will
                        // do a `git checkout` to the sha we found here, if an annotated tag, then,
                        // git is clever enough to take us to the final commit id, if it is a
                        // lighweight tag, then there is no problem because the sha is the same
                        // as the commit id
                        // NOTE: the `id` field is the tag's sha, note we are not taking the commit id
                        // the tag points to and we should not use sha because otherwise we won't be
                        // able to fetch the annotated tag using a commit sha through the Gitea APIs
                        tag_details["id"].as_str().map(|commit| commit.to_string())
                    } else if branch_value_opt.is_some() {
                        // Branch name
                        Some(
                            gitea::http_client::get_commit_pointed_by_branch(
                                gitea_base_url,
                                gitea_token,
                                shasta_root_cert,
                                &repo_url,
                                branch_value_opt.unwrap().as_str().unwrap(),
                                site_name,
                            )
                            .await
                            .unwrap(),
                        )
                    } else {
                        // This should be an error but we will let CSM to handle this
                        None
                    };

                    // IMPORTANT: CSM won't allow CFS configuration layers with both commit id and
                    // branch name, therefore, we will set branch name to None if we already have a
                    // commit id
                    let branch_name = if commit_id_opt.is_some() {
                        None
                    } else {
                        branch_value_opt
                            .map(|branch_value| branch_value.as_str().unwrap().to_string())
                    };

                    let layer = Layer::new(
                        Some(repo_url),
                        commit_id_opt,
                        Some(layer_name),
                        layer_yaml["playbook"]
                            .as_str()
                            .unwrap_or_default()
                            .to_string(),
                        branch_name,
                        None,
                        None,
                    );
                    cfs_configuration.add_layer(layer);
                } else if layer_yaml.get("product").is_some() {
                    // Product layer

                    let product_name = layer_yaml["product"]["name"].as_str().unwrap();
                    let product_version = layer_yaml["product"]["version"].as_str().unwrap();
                    let product_branch_value_opt = layer_yaml["product"].get("branch");

                    let product = cray_product_catalog.get(product_name);

                    if product.is_none() {
                        eprintln!("Product {} not found in cray product catalog", product_name);
                        std::process::exit(1);
                    }

                    let cos_cray_product_catalog =
                        serde_yaml::from_str::<Value>(product.unwrap()).unwrap();

                    let product_details_opt = cos_cray_product_catalog
                        .get(product_version)
                        .and_then(|product| product.get("configuration"));

                    if product_details_opt.is_none() {
                        eprintln!("Product details for product name '{}', product_version '{}' and 'configuration' not found in cray product catalog", product_name, product_version);
                        std::process::exit(1);
                    }

                    let product_details = product_details_opt.unwrap().clone();

                    log::debug!(
                        "CRAY product catalog details for product: {}, version: {}:\n{:#?}",
                        product_name,
                        product_version,
                        product_details
                    );

                    // Manta may run outside the CSM local network therefore we have to change the
                    // internal URLs for the external one
                    let repo_url = product_details["clone_url"].as_str().unwrap().to_string();
                    // .replace("vcs.cmn.alps.cscs.ch", "api-gw-service-nmn.local");

                    let commit_id_opt = if product_branch_value_opt.is_some() {
                        // If branch is provided, then ignore the commit id in the CRAY products table
                        let commit = Some(
                            gitea::http_client::get_commit_pointed_by_branch(
                                gitea_base_url,
                                gitea_token,
                                shasta_root_cert,
                                &repo_url,
                                product_branch_value_opt.unwrap().as_str().unwrap(),
                                site_name,
                            )
                            .await
                            .unwrap(),
                        );

                        commit
                    } else {
                        Some(product_details["commit"].as_str().unwrap().to_string())
                    };

                    // IMPORTANT: CSM won't allow CFS configuration layers with both commit id and
                    // branch name, therefore, we will set branch name to None if we already have a
                    // commit id
                    let branch_name = if commit_id_opt.is_some() {
                        None
                    } else {
                        product_branch_value_opt
                            .map(|branch_value| branch_value.as_str().unwrap().to_string())
                    };

                    // Create CFS configuration layer struct
                    let layer = Layer::new(
                        Some(repo_url),
                        commit_id_opt,
                        Some(product_name.to_string()),
                        layer_yaml["playbook"].as_str().unwrap().to_string(),
                        branch_name,
                        None,
                        None,
                    );
                    cfs_configuration.add_layer(layer);
                } else {
                    eprintln!("ERROR - configurations section in SAT file error - CFS configuration layer error");
                    std::process::exit(1);
                }
            }

            (cfs_configuration_name, cfs_configuration)
        }

        /* pub async fn create_from_repos(
            gitea_token: &str,
            gitea_base_url: &str,
            shasta_root_cert: &[u8],
            repos: Vec<PathBuf>,
            cfs_configuration_name: &String,
        ) -> Self {
            // Create CFS configuration
            let mut cfs_configuration = CfsConfigurationRequest::new();
            cfs_configuration.name = cfs_configuration_name.to_string();

            for repo_path in &repos {
                // Get repo from path
                let repo = match local_git_repo::get_repo(&repo_path.to_string_lossy()) {
                    Ok(repo) => repo,
                    Err(_) => {
                        eprintln!(
                            "Could not find a git repo in {}",
                            repo_path.to_string_lossy()
                        );
                        std::process::exit(1);
                    }
                };

                // Get last (most recent) commit
                let local_last_commit = local_git_repo::get_last_commit(&repo).unwrap();

                // Get repo name
                let repo_ref_origin = repo.find_remote("origin").unwrap();

                log::info!("Repo ref origin URL: {}", repo_ref_origin.url().unwrap());

                let repo_ref_origin_url = repo_ref_origin.url().unwrap();

                let repo_name = repo_ref_origin_url.substring(
                    repo_ref_origin_url.rfind(|c| c == '/').unwrap() + 1, // repo name should not include URI '/' separator
                    repo_ref_origin_url.len(), // repo_ref_origin_url.rfind(|c| c == '.').unwrap(),
                );

                let api_url = "cray/".to_owned() + repo_name;

                // Check if repo and local commit id exists in Shasta cvs
                let shasta_commitid_details_resp =
                    gitea::http_client::get_commit_details_from_internal_url(
                        &api_url,
                        // &format!("/cray/{}", repo_name),
                        &local_last_commit.id().to_string(),
                        gitea_token,
                        shasta_root_cert,
                    )
                    .await;

                // Check sync status between user face and shasta VCS
                let shasta_commitid_details: serde_json::Value = match shasta_commitid_details_resp
                {
                    Ok(_) => {
                        log::debug!(
                            "Local latest commit id {} for repo {} exists in shasta",
                            local_last_commit.id(),
                            repo_name
                        );
                        shasta_commitid_details_resp.unwrap()
                    }
                    Err(e) => {
                        eprintln!("{}", e);
                        std::process::exit(1);
                    }
                };

                let clone_url = gitea_base_url.to_owned() + "/cray/" + repo_name;

                // Create CFS layer
                let cfs_layer = Layer::new(
                    clone_url,
                    Some(shasta_commitid_details["sha"].as_str().unwrap().to_string()),
                    format!(
                        "{}-{}",
                        repo_name.substring(0, repo_name.len()),
                        chrono::offset::Local::now()
                            .to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
                    ),
                    String::from("site.yml"),
                    None,
                    None,
                    None,
                );

                CfsConfigurationRequest::add_layer(&mut cfs_configuration, cfs_layer);
            }

            cfs_configuration
        } */
    }
}

pub mod v3 {
    use std::collections::BTreeMap;

    use serde::{Deserialize, Serialize};
    use serde_yaml::Value;

    use crate::common::gitea;

    #[derive(Debug, Serialize, Deserialize, Clone)]
    pub struct Layer {
        #[serde(skip_serializing_if = "Option::is_none")] // Either commit or branch is passed
        pub name: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")] // Either commit or branch is passed
        pub clone_url: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")] // Either commit or branch is passed
        pub source: Option<String>,
        playbook: String,
        #[serde(skip_serializing_if = "Option::is_none")] // Either commit or branch is passed
        pub commit: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")] // Either commit or branch is passed
        pub branch: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")]
        pub special_parameters: Option<Vec<SpecialParameter>>,
    }

    impl Layer {
        pub fn new(
            name: Option<String>,
            clone_url: Option<String>,
            source: Option<String>,
            playbook: String,
            commit: Option<String>,
            branch: Option<String>,
            special_parameters: Option<Vec<SpecialParameter>>,
        ) -> Self {
            Self {
                clone_url,
                commit,
                name,
                playbook,
                branch,
                special_parameters,
                source,
            }
        }
    }

    #[derive(Debug, Serialize, Deserialize, Clone)]
    pub struct SpecialParameter {
        #[serde(skip_serializing_if = "Option::is_none")]
        ims_required_dkms: Option<bool>,
    }

    #[derive(Debug, Deserialize, Serialize, Clone)]
    pub struct AdditionalInventory {
        name: Option<String>,
        clone_url: String,
        source: Option<String>,
        commit: Option<String>,
        branch: Option<String>,
    }

    #[derive(Debug, Deserialize, Serialize, Clone)]
    pub struct CfsConfigurationRequest {
        pub description: Option<String>,
        pub layers: Option<Vec<Layer>>,
        pub additional_inventory: Option<AdditionalInventory>,
    }

    impl Default for CfsConfigurationRequest {
        fn default() -> Self {
            Self::new()
        }
    }

    impl CfsConfigurationRequest {
        pub fn new() -> Self {
            Self {
                description: None,
                layers: Some(Vec::default()),
                additional_inventory: None,
            }
        }

        pub fn add_layer(&mut self, layer: Layer) {
            if let Some(ref mut layers) = self.layers.as_mut() {
                layers.push(layer);
            }
        }

        pub async fn from_sat_file_serde_yaml(
            shasta_root_cert: &[u8],
            gitea_base_url: &str,
            gitea_token: &str,
            configuration_yaml: &serde_yaml::Value,
            cray_product_catalog: &BTreeMap<String, String>,
            site_name: &str,
        ) -> (String, Self) {
            let cfs_configuration_name;
            let mut cfs_configuration = Self::new();

            cfs_configuration_name = configuration_yaml["name"].as_str().unwrap().to_string();

            for layer_yaml in configuration_yaml["layers"].as_sequence().unwrap() {
                // println!("DEBUG - ### Layer:\n{:#?}\n", layer_yaml);

                if layer_yaml.get("git").is_some() {
                    // Git layer

                    let layer_name = layer_yaml["name"].as_str().unwrap().to_string();

                    let repo_url = layer_yaml["git"]["url"].as_str().unwrap().to_string();

                    let commit_id_value_opt = layer_yaml["git"].get("commit");
                    let tag_value_opt = layer_yaml["git"].get("tag");
                    let branch_value_opt = layer_yaml["git"].get("branch");

                    let commit_id_opt: Option<String> = if commit_id_value_opt.is_some() {
                        // Git commit id
                        layer_yaml["git"]
                            .get("commit")
                            .map(|commit_id| commit_id.as_str().unwrap().to_string())
                    } else if let Some(git_tag_value) = tag_value_opt {
                        // Git tag
                        let git_tag = git_tag_value.as_str().unwrap();

                        log::info!("git tag: {}", git_tag_value.as_str().unwrap());

                        let tag_details_rslt = gitea::http_client::get_tag_details(
                            &repo_url,
                            git_tag,
                            gitea_token,
                            shasta_root_cert,
                            site_name,
                        )
                        .await;

                        let tag_details = if let Ok(tag_details) = tag_details_rslt {
                            log::debug!("tag details:\n{:#?}", tag_details);
                            tag_details
                        } else {
                            eprintln!("ERROR - Could not get details for git tag '{}' in CFS configuration '{}'. Reason:\n{:#?}", git_tag, cfs_configuration_name, tag_details_rslt);
                            std::process::exit(1);
                        };

                        // Assumming user sets an existing tag name. It could be an annotated tag
                        // (different object than the commit id with its own sha value) or a
                        // lightweight tag (pointer to commit id, therefore the tag will have the
                        // same sha as the commit id it points to), either way CFS session will
                        // do a `git checkout` to the sha we found here, if an annotated tag, then,
                        // git is clever enough to take us to the final commit id, if it is a
                        // lighweight tag, then there is no problem because the sha is the same
                        // as the commit id
                        // NOTE: the `id` field is the tag's sha, note we are not taking the commit id
                        // the tag points to and we should not use sha because otherwise we won't be
                        // able to fetch the annotated tag using a commit sha through the Gitea APIs
                        tag_details["id"].as_str().map(|commit| commit.to_string())
                    } else if branch_value_opt.is_some() {
                        // Branch name
                        Some(
                            gitea::http_client::get_commit_pointed_by_branch(
                                gitea_base_url,
                                gitea_token,
                                shasta_root_cert,
                                &repo_url,
                                branch_value_opt.unwrap().as_str().unwrap(),
                                site_name,
                            )
                            .await
                            .unwrap(),
                        )
                    } else {
                        // This should be an error but we will let CSM to handle this
                        None
                    };

                    // IMPORTANT: CSM won't allow CFS configuration layers with both commit id and
                    // branch name, therefore, we will set branch name to None if we already have a
                    // commit id
                    let branch_name = if commit_id_opt.is_some() {
                        None
                    } else {
                        branch_value_opt
                            .map(|branch_value| branch_value.as_str().unwrap().to_string())
                    };

                    let layer = Layer::new(
                        Some(layer_name),
                        Some(repo_url),
                        layer_yaml["source"]
                            .as_str()
                            .and_then(|source_value| Some(source_value.to_string())),
                        layer_yaml["playbook"]
                            .as_str()
                            .unwrap_or_default()
                            .to_string(),
                        commit_id_opt,
                        branch_name,
                        None,
                    );
                    cfs_configuration.add_layer(layer);
                } else if layer_yaml.get("product").is_some() {
                    // Product layer

                    let product_name = layer_yaml["product"]["name"].as_str().unwrap();
                    let product_version = layer_yaml["product"]["version"].as_str().unwrap();
                    let product_branch_value_opt = layer_yaml["product"].get("branch");
                    let product_commit_value_opt = layer_yaml["product"].get("commit");

                    let product = cray_product_catalog.get(product_name);

                    if product.is_none() {
                        eprintln!("Product {} not found in cray product catalog", product_name);
                        std::process::exit(1);
                    }

                    let cos_cray_product_catalog =
                        serde_yaml::from_str::<Value>(product.unwrap()).unwrap();

                    let product_details_opt = cos_cray_product_catalog
                        .get(product_version)
                        .and_then(|product| product.get("configuration"));

                    if product_details_opt.is_none() {
                        eprintln!("Product details for product name '{}', product_version '{}' and 'configuration' not found in cray product catalog", product_name, product_version);
                        std::process::exit(1);
                    }

                    let product_details = product_details_opt.unwrap().clone();

                    log::debug!(
                        "CRAY product catalog details for product: {}, version: {}:\n{:#?}",
                        product_name,
                        product_version,
                        product_details
                    );

                    // Manta may run outside the CSM local network therefore we have to change the
                    // internal URLs for the external one
                    let repo_url = product_details["clone_url"].as_str().unwrap().to_string();
                    // .replace("vcs.cmn.alps.cscs.ch", "api-gw-service-nmn.local");

                    let commit_id_opt = if let Some(commit_value) = product_commit_value_opt {
                        commit_value
                            .clone()
                            .as_str()
                            .map(|commit_str| commit_str.to_string())
                    } else {
                        if product_branch_value_opt.is_some() {
                            // If branch is provided, then ignore the commit id in the CRAY products table
                            Some(
                                gitea::http_client::get_commit_pointed_by_branch(
                                    gitea_base_url,
                                    gitea_token,
                                    shasta_root_cert,
                                    &repo_url,
                                    product_branch_value_opt.unwrap().as_str().unwrap(),
                                    site_name,
                                )
                                .await
                                .unwrap(),
                            )
                        } else {
                            Some(product_details["commit"].as_str().unwrap().to_string())
                        }
                    };

                    // IMPORTANT: CSM won't allow CFS configuration layers with both commit id and
                    // branch name, therefore, we will set branch name to None if we already have a
                    // commit id
                    let branch_name = if commit_id_opt.is_some() {
                        None
                    } else {
                        product_branch_value_opt
                            .map(|branch_value| branch_value.as_str().unwrap().to_string())
                    };

                    // Create CFS configuration layer struct
                    let layer = Layer::new(
                        Some(product_name.to_string()),
                        Some(repo_url),
                        layer_yaml["source"]
                            .as_str()
                            .map(|source_value| source_value.to_string()),
                        layer_yaml["playbook"].as_str().unwrap().to_string(),
                        commit_id_opt,
                        branch_name,
                        None,
                    );
                    cfs_configuration.add_layer(layer);
                } else {
                    eprintln!("ERROR - configurations section in SAT file error - CFS configuration layer error");
                    std::process::exit(1);
                }
            }

            (cfs_configuration_name, cfs_configuration)
        }

        /* pub async fn create_from_repos(
            gitea_token: &str,
            gitea_base_url: &str,
            shasta_root_cert: &[u8],
            repos: Vec<PathBuf>,
            cfs_configuration_name: &String,
        ) -> Self {
            // Create CFS configuration
            let mut cfs_configuration = CfsConfigurationRequest::new();
            cfs_configuration.name = cfs_configuration_name.to_string();

            for repo_path in &repos {
                // Get repo from path
                let repo = match local_git_repo::get_repo(&repo_path.to_string_lossy()) {
                    Ok(repo) => repo,
                    Err(_) => {
                        eprintln!(
                            "Could not find a git repo in {}",
                            repo_path.to_string_lossy()
                        );
                        std::process::exit(1);
                    }
                };

                // Get last (most recent) commit
                let local_last_commit = local_git_repo::get_last_commit(&repo).unwrap();

                // Get repo name
                let repo_ref_origin = repo.find_remote("origin").unwrap();

                log::info!("Repo ref origin URL: {}", repo_ref_origin.url().unwrap());

                let repo_ref_origin_url = repo_ref_origin.url().unwrap();

                let repo_name = repo_ref_origin_url.substring(
                    repo_ref_origin_url.rfind(|c| c == '/').unwrap() + 1, // repo name should not include URI '/' separator
                    repo_ref_origin_url.len(), // repo_ref_origin_url.rfind(|c| c == '.').unwrap(),
                );

                let api_url = "cray/".to_owned() + repo_name;

                // Check if repo and local commit id exists in Shasta cvs
                let shasta_commitid_details_resp =
                    gitea::http_client::get_commit_details_from_internal_url(
                        &api_url,
                        // &format!("/cray/{}", repo_name),
                        &local_last_commit.id().to_string(),
                        gitea_token,
                        shasta_root_cert,
                    )
                    .await;

                // Check sync status between user face and shasta VCS
                let shasta_commitid_details: serde_json::Value = match shasta_commitid_details_resp
                {
                    Ok(_) => {
                        log::debug!(
                            "Local latest commit id {} for repo {} exists in shasta",
                            local_last_commit.id(),
                            repo_name
                        );
                        shasta_commitid_details_resp.unwrap()
                    }
                    Err(e) => {
                        eprintln!("{}", e);
                        std::process::exit(1);
                    }
                };

                let clone_url = gitea_base_url.to_owned() + "/cray/" + repo_name;

                // Create CFS layer
                let cfs_layer = Layer::new(
                    clone_url,
                    Some(shasta_commitid_details["sha"].as_str().unwrap().to_string()),
                    format!(
                        "{}-{}",
                        repo_name.substring(0, repo_name.len()),
                        chrono::offset::Local::now()
                            .to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
                    ),
                    String::from("site.yml"),
                    None,
                    None,
                    None,
                );

                CfsConfigurationRequest::add_layer(&mut cfs_configuration, cfs_layer);
            }

            cfs_configuration
        } */
    }
}