Grcov report - purge_secrets.rs

1

    use std::fs;

2

    use std::path::Path;

3

4

    use clap::Args;

5

    use mk_lib::file::ToUtf8 as _;

6

7

    use crate::secrets::context::Context;

8

    use crate::secrets::vault::verify_vault;

9

10

    #[derive(Debug, Args)]

11

    pub struct PurgeSecrets {

12

      #[arg(help = "The secret identifier or prefix to export")]

13

      path: String,

14

15

      #[arg(short, long, help = "The path to the secret vault")]

16

      vault_location: Option<String>,

17

    }

18

19

    impl PurgeSecrets {

20

      pub fn execute(&self, context: &Context) -> anyhow::Result<()> {

21

        let path: &str = &self.path.clone();

22

        let vault_location: &str = &self

23

          .vault_location

24

          .clone()

25

          .unwrap_or_else(|| context.vault_location());

26

27

        assert!(!path.is_empty(), "Path or prefix must be provided");

28

        assert!(!vault_location.is_empty(), "Vault location must be provided");

29

30

        verify_vault(vault_location)?;

31

32

        let path = Path::new(vault_location).join(path);

33

        if path.exists() {

34

          fs::remove_dir_all(path.clone())?;

35

          println!("Secrets purged at {}", path.to_utf8()?);

36

        } else {

37

          println!("Secrets not found at {}", path.to_utf8()?);

38

        }

39

        Ok(())

40

      }

41

    }