Skip to content

Commit

Permalink
Updates to the default config (#300)
Browse files Browse the repository at this point in the history
Change the default config to auto accept federation registry hints and
automatically try to init packages that do not exist.

The integration with https://github.com/bytecodealliance/wasm-pkg-tools/
and feedback from usage suggests we should have config defaults that
work better out of the box.

This will also help resolve
bytecodealliance/wac#139
  • Loading branch information
calvinrp authored Sep 4, 2024
1 parent edb43a0 commit 102b8ce
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 45 deletions.
10 changes: 8 additions & 2 deletions crates/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ pub struct Config {

/// Auto accept registry hint or ask the user to confirm
#[serde(default)]
pub auto_accept_federation_hints: bool,
pub disable_auto_accept_federation_hints: bool,

/// Automatically attempt package initialize if does not exist
/// or ask the user to confirm first
#[serde(default)]
pub disable_auto_package_init: bool,

/// Disable interactive prompts.
#[serde(default)]
Expand Down Expand Up @@ -209,7 +214,8 @@ impl Config {
keys: self.keys.clone(),
keyring_auth: self.keyring_auth,
ignore_federation_hints: self.ignore_federation_hints,
auto_accept_federation_hints: self.auto_accept_federation_hints,
disable_auto_accept_federation_hints: self.disable_auto_accept_federation_hints,
disable_auto_package_init: self.disable_auto_package_init,
disable_interactive: self.disable_interactive,
keyring_backend: self.keyring_backend.clone(),
};
Expand Down
79 changes: 45 additions & 34 deletions crates/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ where
namespace_map: N,
api: api::Client,
ignore_federation_hints: bool,
auto_accept_federation_hints: bool,
disable_auto_accept_federation_hints: bool,
disable_auto_package_init: bool,
disable_interactive: bool,
keyring_backend: Option<String>,
keys: IndexSet<String>,
Expand All @@ -90,7 +91,8 @@ impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C,
namespace_map: N,
auth_token: Option<Secret<String>>,
ignore_federation_hints: bool,
auto_accept_federation_hints: bool,
disable_auto_accept_federation_hints: bool,
disable_auto_package_init: bool,
disable_interactive: bool,
keyring_backend: Option<String>,
keys: IndexSet<String>,
Expand All @@ -102,7 +104,8 @@ impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C,
namespace_map,
api,
ignore_federation_hints,
auto_accept_federation_hints,
disable_auto_accept_federation_hints,
disable_auto_package_init,
disable_interactive,
keyring_backend,
keys,
Expand Down Expand Up @@ -419,39 +422,45 @@ impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C,
has_auth_token,
}) => {
if !initializing {
if self.disable_interactive || cfg!(not(feature = "cli-interactive")) {
return Err(ClientError::MustInitializePackage {
name,
has_auth_token,
});
}

#[cfg(feature = "cli-interactive")]
{
use crate::storage::PublishEntry;
use dialoguer::{theme::ColorfulTheme, Confirm};

if accepted_prompt_to_initialize
|| Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(format!(
"Package `{package_name}` was not found.
If it exists, you may not have access.
Attempt to create `{package_name}` and publish the release y/N\n",
package_name = &info.name,
))
.default(false)
.interact()
.unwrap()
{
info.entries.insert(0, PublishEntry::Init);
initializing = true;
accepted_prompt_to_initialize = true;
} else {
if !self.disable_auto_package_init {
info.entries.insert(0, crate::storage::PublishEntry::Init);
initializing = true;
accepted_prompt_to_initialize = true;
} else {
if self.disable_interactive || cfg!(not(feature = "cli-interactive")) {
return Err(ClientError::MustInitializePackage {
name,
has_auth_token,
});
}

#[cfg(feature = "cli-interactive")]
{
use crate::storage::PublishEntry;
use dialoguer::{theme::ColorfulTheme, Confirm};

if accepted_prompt_to_initialize
|| Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(format!(
"Package `{package_name}` was not found.
If it exists, you may not have access.
Attempt to create `{package_name}` and publish the release y/N\n",
package_name = &info.name,
))
.default(false)
.interact()
.unwrap()
{
info.entries.insert(0, PublishEntry::Init);
initializing = true;
accepted_prompt_to_initialize = true;
} else {
return Err(ClientError::MustInitializePackage {
name,
has_auth_token,
});
}
}
}
}
PackageInfo::new(info.name.clone())
Expand Down Expand Up @@ -936,7 +945,7 @@ Attempt to create `{package_name}` and publish the release y/N\n",

let package_name = &packages.get(log_id).unwrap().name;

if self.auto_accept_federation_hints
if !self.disable_auto_accept_federation_hints
|| Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(format!(
"Package `{package_name}` is not in `{current_registry}` registry.
Expand Down Expand Up @@ -1446,7 +1455,8 @@ impl FileSystemClient {
namespace_map,
auth_token,
config.ignore_federation_hints,
config.auto_accept_federation_hints,
config.disable_auto_accept_federation_hints,
config.disable_auto_package_init,
disable_interactive,
keyring_backend,
keys,
Expand Down Expand Up @@ -1510,7 +1520,8 @@ impl FileSystemClient {
FileSystemNamespaceMapStorage::new(namespace_map_path),
auth_token,
config.ignore_federation_hints,
config.auto_accept_federation_hints,
config.disable_auto_accept_federation_hints,
config.disable_auto_package_init,
disable_interactive,
keyring_backend,
keys,
Expand Down
1 change: 1 addition & 0 deletions crates/transparency/src/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//!
//! Implementations:
//! * [`InOrderLog`] -
//!
//! The only implementation in this module is ,
//! which is a [`VerifiableLog`] whose contents are structured
//! using binary in-order interval numbering as described in
Expand Down
23 changes: 18 additions & 5 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ pub struct ConfigCommand {
#[clap(long)]
pub ignore_federation_hints: Option<bool>,

/// Auto accept federation hints.
/// Disable auto accept federation hints.
#[clap(long)]
pub auto_accept_federation_hints: Option<bool>,
pub disable_auto_accept_federation_hints: Option<bool>,

/// Automatically attempt package initialize if does not exist
/// or ask the user to confirm first.
#[clap(long)]
pub disable_auto_package_init: Option<bool>,

/// Overwrite the existing configuration file.
#[clap(long)]
Expand Down Expand Up @@ -86,7 +91,10 @@ impl ConfigCommand {
keys: self.common.read_config()?.keys,
keyring_auth: false,
ignore_federation_hints: self.ignore_federation_hints.unwrap_or_default(),
auto_accept_federation_hints: self.auto_accept_federation_hints.unwrap_or_default(),
disable_auto_accept_federation_hints: self
.disable_auto_accept_federation_hints
.unwrap_or_default(),
disable_auto_package_init: self.disable_auto_package_init.unwrap_or_default(),
disable_interactive: false,
keyring_backend: self.keyring_backend,
}
Expand Down Expand Up @@ -120,8 +128,13 @@ impl ConfigCommand {
if let Some(ignore_federation_hints) = self.ignore_federation_hints {
config.ignore_federation_hints = ignore_federation_hints;
}
if let Some(auto_accept_federation_hints) = self.auto_accept_federation_hints {
config.auto_accept_federation_hints = auto_accept_federation_hints;
if let Some(disable_auto_accept_federation_hints) =
self.disable_auto_accept_federation_hints
{
config.disable_auto_accept_federation_hints = disable_auto_accept_federation_hints;
}
if let Some(disable_auto_package_init) = self.disable_auto_package_init {
config.disable_auto_package_init = disable_auto_package_init;
}
if self.keyring_backend.is_some() {
config.keyring_backend = self.keyring_backend;
Expand Down
12 changes: 9 additions & 3 deletions src/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ pub struct LoginCommand {
#[clap(long)]
pub ignore_federation_hints: bool,

/// Auto accept federation hints.
/// Disable auto accept federation hints.
#[clap(long)]
pub auto_accept_federation_hints: bool,
pub disable_auto_accept_federation_hints: bool,

/// Automatically attempt package initialize if does not exist
/// or ask the user to confirm first.
#[clap(long)]
pub disable_auto_package_init: bool,

/// The backend to use for keyring access
#[clap(long, value_name = "KEYRING_BACKEND", value_parser = keyring_backend_parser, long_help = keyring_backend_help())]
Expand All @@ -52,7 +57,8 @@ impl LoginCommand {
.transpose()?
.map(|u| u.to_string());
config.ignore_federation_hints = self.ignore_federation_hints;
config.auto_accept_federation_hints = self.auto_accept_federation_hints;
config.disable_auto_accept_federation_hints = self.disable_auto_accept_federation_hints;
config.disable_auto_package_init = self.disable_auto_package_init;

// set keyring backend, if specified
if self.keyring_backend.is_some() {
Expand Down
3 changes: 2 additions & 1 deletion tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ pub async fn spawn_server(
keys: IndexSet::new(),
keyring_auth: false,
ignore_federation_hints: false,
auto_accept_federation_hints: false,
disable_auto_accept_federation_hints: false,
disable_auto_package_init: true,
disable_interactive: true,
keyring_backend: None,
};
Expand Down

0 comments on commit 102b8ce

Please sign in to comment.