wick_oci_utils/
options.rs

1use std::path::PathBuf;
2
3use oci_distribution::secrets::RegistryAuth;
4
5#[derive(Clone, Debug, Copy, serde::Serialize)]
6#[non_exhaustive]
7pub enum OnExisting {
8  Ignore,
9  Overwrite,
10  Error,
11}
12
13#[derive(getset::Getters, getset::Setters, Clone, serde::Serialize)]
14#[must_use]
15pub struct OciOptions {
16  #[getset(get = "pub", set = "pub")]
17  pub(crate) allow_latest: bool,
18  #[getset(get = "pub", set = "pub")]
19  pub(crate) allow_insecure: Vec<String>,
20  #[getset(get = "pub", set = "pub")]
21  pub(crate) username: Option<String>,
22  #[getset(get = "pub", set = "pub")]
23  pub(crate) password: Option<String>,
24  #[getset(get = "pub", set = "pub")]
25  pub(crate) cache_dir: PathBuf,
26  #[getset(get = "pub", set = "pub")]
27  pub(crate) flatten: bool,
28  #[getset(get = "pub", set = "pub")]
29  pub(crate) on_existing: OnExisting,
30  #[getset(get = "pub", set = "pub")]
31  pub(crate) ignore_manifest: bool,
32}
33
34impl Default for OciOptions {
35  fn default() -> Self {
36    let xdg = wick_xdg::Settings::new();
37    Self {
38      allow_latest: false,
39      allow_insecure: vec![],
40      username: None,
41      password: None,
42      flatten: false,
43      cache_dir: xdg.global().cache().clone(),
44      on_existing: OnExisting::Ignore,
45      ignore_manifest: false,
46    }
47  }
48}
49
50impl OciOptions {
51  #[must_use]
52  pub fn get_auth(&self) -> RegistryAuth {
53    match (self.username.as_ref(), self.password.as_ref()) {
54      (Some(username), Some(password)) => RegistryAuth::Basic(username.clone(), password.clone()),
55      _ => RegistryAuth::Anonymous,
56    }
57  }
58}
59
60impl std::fmt::Debug for OciOptions {
61  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62    f.debug_struct("OciOptions")
63      .field("allow_latest", &self.allow_latest)
64      .field("allow_insecure", &self.allow_insecure)
65      .field("username", &self.username)
66      .field("password", &self.password.as_ref().map(|_| "********"))
67      .finish()
68  }
69}