|
| 1 | +//! The `podlet podman artifact pull` command and CLI options. |
| 2 | +
|
| 3 | +use std::path::PathBuf; |
| 4 | + |
| 5 | +use clap::{Args, Subcommand}; |
| 6 | + |
| 7 | +use crate::{ |
| 8 | + cli::image_to_name, |
| 9 | + quadlet::{self, image::DecryptionKey}, |
| 10 | +}; |
| 11 | + |
| 12 | +/// [`Subcommand`]s for `podlet podman artifact` |
| 13 | +#[derive(Subcommand, Debug, Clone, PartialEq)] |
| 14 | +pub enum Artifact { |
| 15 | + /// Generate a Podman Quadlet `.artifact` file |
| 16 | + /// |
| 17 | + /// For details on options see: |
| 18 | + /// https://docs.podman.io/en/stable/markdown/podman-pull.1.html and |
| 19 | + /// https://docs.podman.io/en/stable/markdown/podman-systemd.unit.5.html#artifact-units-artifact |
| 20 | + #[expect(clippy::doc_markdown, reason = "help links")] |
| 21 | + #[group(skip)] |
| 22 | + Pull { |
| 23 | + #[command(flatten)] |
| 24 | + pull: Pull, |
| 25 | + }, |
| 26 | +} |
| 27 | + |
| 28 | +impl Artifact { |
| 29 | + /// Name suitable for use as the filename of the generated Quadlet file. |
| 30 | + pub fn name(&self) -> &str { |
| 31 | + let Self::Pull { |
| 32 | + pull: Pull { source, .. }, |
| 33 | + } = self; |
| 34 | + |
| 35 | + image_to_name(source) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +impl From<Artifact> for quadlet::Artifact { |
| 40 | + fn from(value: Artifact) -> Self { |
| 41 | + let Artifact::Pull { pull } = value; |
| 42 | + pull.into() |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +impl From<Artifact> for quadlet::Resource { |
| 47 | + fn from(value: Artifact) -> Self { |
| 48 | + quadlet::Artifact::from(value).into() |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +/// [`Args`] for `podman artifact pull` |
| 53 | +#[derive(Args, Default, Debug, Clone, PartialEq)] |
| 54 | +pub struct Pull { |
| 55 | + /// Path of the authentication file. |
| 56 | + /// |
| 57 | + /// Converts to "AuthFile=PATH". |
| 58 | + #[arg(long, value_name = "PATH")] |
| 59 | + pub authfile: Option<PathBuf>, |
| 60 | + |
| 61 | + /// Use certificates at path (*.crt, *.cert, *.key) to connect to the registry. |
| 62 | + /// |
| 63 | + /// Converts to "CertDir=PATH". |
| 64 | + #[arg(long, value_name = "PATH")] |
| 65 | + pub cert_dir: Option<PathBuf>, |
| 66 | + |
| 67 | + /// The username and/or password to use to authenticate with the registry, if required. |
| 68 | + /// |
| 69 | + /// Converts to "Creds=[USERNAME][:PASSWORD]". |
| 70 | + #[arg(long, value_name = "[USERNAME][:PASSWORD]")] |
| 71 | + pub creds: Option<String>, |
| 72 | + |
| 73 | + /// The key and optional passphrase to be used for decryption of artifacts. |
| 74 | + /// |
| 75 | + /// Converts to "DecryptionKey=KEY[:PASSPHRASE]" |
| 76 | + #[arg(long, value_name = "KEY[:PASSPHRASE]")] |
| 77 | + pub decryption_key: Option<DecryptionKey>, |
| 78 | + |
| 79 | + /// Suppress output information when pulling artifacts. |
| 80 | + #[arg(short, long)] |
| 81 | + pub quiet: bool, |
| 82 | + |
| 83 | + /// Number of times to retry pulling artifacts. |
| 84 | + /// |
| 85 | + /// Converts to "Retry=ATTEMPTS". |
| 86 | + /// |
| 87 | + /// Default is 3. |
| 88 | + #[arg(long, value_name = "ATTEMPTS")] |
| 89 | + #[arg(long)] |
| 90 | + pub retry: Option<u64>, |
| 91 | + |
| 92 | + /// Duration of delay between retry attempts when pulling artifacts. |
| 93 | + /// |
| 94 | + /// Converts to "RetryDelay=DURATION". |
| 95 | + /// |
| 96 | + /// Default is to start at two seconds and then exponentially back off. |
| 97 | + #[arg(long, value_name = "DURATION")] |
| 98 | + pub retry_delay: Option<String>, |
| 99 | + |
| 100 | + /// Require HTTPS and verify certificates when contacting registries. |
| 101 | + /// |
| 102 | + /// Converts to "TLSVerify=TLS_VERIFY". |
| 103 | + #[expect(clippy::doc_markdown, reason = "Quadlet option")] |
| 104 | + #[arg(long, num_args = 0..=1, require_equals = true, default_missing_value = "true")] |
| 105 | + pub tls_verify: Option<bool>, |
| 106 | + |
| 107 | + /// The location from which the artifact image is obtained. |
| 108 | + pub source: String, |
| 109 | +} |
| 110 | + |
| 111 | +impl From<Pull> for quadlet::Artifact { |
| 112 | + fn from( |
| 113 | + Pull { |
| 114 | + authfile, |
| 115 | + cert_dir, |
| 116 | + creds, |
| 117 | + decryption_key, |
| 118 | + quiet, |
| 119 | + retry, |
| 120 | + retry_delay, |
| 121 | + tls_verify, |
| 122 | + source, |
| 123 | + }: Pull, |
| 124 | + ) -> Self { |
| 125 | + Self { |
| 126 | + artifact: source, |
| 127 | + auth_file: authfile, |
| 128 | + cert_dir, |
| 129 | + creds, |
| 130 | + decryption_key, |
| 131 | + podman_args: None, |
| 132 | + quiet, |
| 133 | + retry, |
| 134 | + retry_delay, |
| 135 | + tls_verify, |
| 136 | + } |
| 137 | + } |
| 138 | +} |
0 commit comments