Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
moved registry cli things to registry cli
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <brooks@cosmonic.com>
  • Loading branch information
brooksmtownsend committed Jun 13, 2023
1 parent f48daa0 commit 1172806
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 108 deletions.
1 change: 1 addition & 0 deletions crates/wash-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub mod get;
pub mod inspect;
pub mod link;
pub mod output;
pub mod registry;
pub mod spy;
pub mod start;
pub mod stop;
Expand Down
97 changes: 97 additions & 0 deletions crates/wash-lib/src/cli/registry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use clap::{Parser, Subcommand};

#[derive(Parser, Debug, Clone)]
pub struct AuthOpts {
/// OCI username, if omitted anonymous authentication will be used
#[clap(
short = 'u',
long = "user",
env = "WASH_REG_USER",
hide_env_values = true
)]
pub user: Option<String>,

/// OCI password, if omitted anonymous authentication will be used
#[clap(
short = 'p',
long = "password",
env = "WASH_REG_PASSWORD",
hide_env_values = true
)]
pub password: Option<String>,

/// Allow insecure (HTTP) registry connections
#[clap(long = "insecure")]
pub insecure: bool,
}

#[derive(Debug, Clone, Subcommand)]
pub enum RegistryCommand {
/// Pull an artifact from an OCI compliant registry
#[clap(name = "pull")]
Pull(RegistryPullCommand),
/// Push an artifact to an OCI compliant registry
#[clap(name = "push")]
Push(RegistryPushCommand),
/// Ping (test url) to see if the OCI url has an artifact
#[clap(name = "ping")]
Ping(RegistryPingCommand),
}

#[derive(Parser, Debug, Clone)]
pub struct RegistryPullCommand {
/// URL of artifact
#[clap(name = "url")]
pub url: String,

/// File destination of artifact
#[clap(long = "destination")]
pub destination: Option<String>,

/// Digest to verify artifact against
#[clap(short = 'd', long = "digest")]
pub digest: Option<String>,

/// Allow latest artifact tags
#[clap(long = "allow-latest")]
pub allow_latest: bool,

#[clap(flatten)]
pub opts: AuthOpts,
}

#[derive(Parser, Debug, Clone)]
pub struct RegistryPushCommand {
/// URL to push artifact to
#[clap(name = "url")]
pub url: String,

/// Path to artifact to push
#[clap(name = "artifact")]
pub artifact: String,

/// Path to config file, if omitted will default to a blank configuration
#[clap(short = 'c', long = "config")]
pub config: Option<String>,

/// Allow latest artifact tags
#[clap(long = "allow-latest")]
pub allow_latest: bool,

/// Optional set of annotations to apply to the OCI artifact manifest
#[clap(short = 'a', long = "annotation", name = "annotations")]
pub annotations: Option<Vec<String>>,

#[clap(flatten)]
pub opts: AuthOpts,
}

#[derive(Parser, Debug, Clone)]
pub struct RegistryPingCommand {
/// URL of artifact
#[clap(name = "url")]
pub url: String,

#[clap(flatten)]
pub opts: AuthOpts,
}
103 changes: 0 additions & 103 deletions crates/wash-lib/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,109 +27,6 @@ const OCI_MEDIA_TYPE: &str = "application/vnd.oci.image.layer.v1.tar";
// straight up stolen from oci_distribution::Reference
pub const REFERENCE_REGEXP: &str = r"^((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?/)?[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?:(?:/[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?)+)?)(?::([\w][\w.-]{0,127}))?(?:@([A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[:xdigit:]]{32,}))?$";

#[cfg(feature = "cli")]
mod cli {
use clap::{Parser, Subcommand};

#[derive(Parser, Debug, Clone)]
pub struct AuthOpts {
/// OCI username, if omitted anonymous authentication will be used
#[clap(
short = 'u',
long = "user",
env = "WASH_REG_USER",
hide_env_values = true
)]
pub user: Option<String>,

/// OCI password, if omitted anonymous authentication will be used
#[clap(
short = 'p',
long = "password",
env = "WASH_REG_PASSWORD",
hide_env_values = true
)]
pub password: Option<String>,

/// Allow insecure (HTTP) registry connections
#[clap(long = "insecure")]
pub insecure: bool,
}

#[derive(Debug, Clone, Subcommand)]
pub enum RegistryCommand {
/// Pull an artifact from an OCI compliant registry
#[clap(name = "pull")]
Pull(RegistryPullCommand),
/// Push an artifact to an OCI compliant registry
#[clap(name = "push")]
Push(RegistryPushCommand),
/// Ping (test url) to see if the OCI url has an artifact
#[clap(name = "ping")]
Ping(RegistryPingCommand),
}

#[derive(Parser, Debug, Clone)]
pub struct RegistryPullCommand {
/// URL of artifact
#[clap(name = "url")]
pub url: String,

/// File destination of artifact
#[clap(long = "destination")]
pub destination: Option<String>,

/// Digest to verify artifact against
#[clap(short = 'd', long = "digest")]
pub digest: Option<String>,

/// Allow latest artifact tags
#[clap(long = "allow-latest")]
pub allow_latest: bool,

#[clap(flatten)]
pub opts: AuthOpts,
}

#[derive(Parser, Debug, Clone)]
pub struct RegistryPushCommand {
/// URL to push artifact to
#[clap(name = "url")]
pub url: String,

/// Path to artifact to push
#[clap(name = "artifact")]
pub artifact: String,

/// Path to config file, if omitted will default to a blank configuration
#[clap(short = 'c', long = "config")]
pub config: Option<String>,

/// Allow latest artifact tags
#[clap(long = "allow-latest")]
pub allow_latest: bool,

/// Optional set of annotations to apply to the OCI artifact manifest
#[clap(short = 'a', long = "annotation", name = "annotations")]
pub annotations: Option<Vec<String>>,

#[clap(flatten)]
pub opts: AuthOpts,
}

#[derive(Parser, Debug, Clone)]
pub struct RegistryPingCommand {
/// URL of artifact
#[clap(name = "url")]
pub url: String,

#[clap(flatten)]
pub opts: AuthOpts,
}
}
#[cfg(feature = "cli")]
pub use cli::*;

/// Additional options for pulling an OCI artifact
#[derive(Default)]
pub struct OciPullOptions {
Expand Down
9 changes: 5 additions & 4 deletions src/common/registry_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ use oci_distribution::{
use serde_json::json;
use tokio::fs::File;
use tokio::io::AsyncWriteExt;
use wash_lib::cli::{
labels_vec_to_hashmap,
registry::{RegistryCommand, RegistryPingCommand, RegistryPullCommand, RegistryPushCommand},
CommandOutput, OutputKind,
};
use wash_lib::registry::{
pull_oci_artifact, push_oci_artifact, validate_artifact, OciPullOptions, OciPushOptions,
SupportedArtifacts,
};
use wash_lib::{
cli::{labels_vec_to_hashmap, CommandOutput, OutputKind},
registry::{RegistryCommand, RegistryPingCommand, RegistryPullCommand, RegistryPushCommand},
};

use crate::appearance::spinner::Spinner;

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use wash_lib::{
get::GetCommand,
inspect::InspectCliCommand,
link::LinkCommand,
registry::{RegistryCommand, RegistryPullCommand, RegistryPushCommand},
spy::SpyCommand,
start::StartCommand,
stop::StopCommand,
CommandOutput, OutputKind,
},
drain::Drain as DrainSelection,
registry::{RegistryCommand, RegistryPullCommand, RegistryPushCommand},
};

use app::AppCliCommand;
Expand Down

0 comments on commit 1172806

Please sign in to comment.