Skip to content

Commit

Permalink
refactor: update parsing from RegistryCredential to RegistryAuth
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed <ahmedtadde@gmail.com>
  • Loading branch information
ahmedtadde committed Dec 5, 2023
1 parent 63d95e5 commit b6095f8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/control-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ serde_json = { workspace = true }
tokio = { workspace = true, features = ["time"] }
tracing = { workspace = true }
tracing-opentelemetry = { workspace = true }
oci-distribution = { workspace = true, features = ["rustls-tls"] }
oci-distribution = { workspace = true, features = ["rustls-tls"] }
anyhow = { workspace = true }
28 changes: 15 additions & 13 deletions crates/control-interface/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(deprecated)]
use std::collections::HashMap;

use anyhow::bail;
use serde::{Deserialize, Serialize};

/// One of a potential list of responses to an actor auction
Expand Down Expand Up @@ -237,19 +238,24 @@ pub struct RegistryCredential {
pub registry_type: String,
}

impl RegistryCredential {
#[must_use]
pub fn as_oci_registry_auth(&self) -> Option<oci_distribution::secrets::RegistryAuth> {
if self.registry_type != "oci" {
return None;
fn default_registry_type() -> String {
"oci".to_string()
}

impl TryFrom<&RegistryCredential> for oci_distribution::secrets::RegistryAuth {
type Error = anyhow::Error;

fn try_from(cred: &RegistryCredential) -> Result<Self, Self::Error> {
if cred.registry_type != "oci" {
bail!("Only OCI registries are supported at this time");
}

match self {
match cred {
RegistryCredential {
username: Some(username),
password: Some(password),
..
} => Some(oci_distribution::secrets::RegistryAuth::Basic(
} => Ok(oci_distribution::secrets::RegistryAuth::Basic(
username.clone(),
password.clone(),
)),
Expand All @@ -259,19 +265,15 @@ impl RegistryCredential {
password: None,
token: Some(token),
..
} => Some(oci_distribution::secrets::RegistryAuth::Basic(
} => Ok(oci_distribution::secrets::RegistryAuth::Basic(
username.clone(),
token.clone(),
)),
_ => None,
_ => bail!("Invalid OCI registry credentials"),
}
}
}

fn default_registry_type() -> String {
"oci".to_string()
}

/// A set of credentials to be used for fetching from specific registries
pub type RegistryCredentialMap = std::collections::HashMap<String, RegistryCredential>;

Expand Down
3 changes: 2 additions & 1 deletion crates/wash-cli/src/common/registry_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::{bail, Context, Result};
use log::warn;
use oci_distribution::{
client::{Client, ClientConfig, ClientProtocol},
secrets::RegistryAuth,
Reference,
};
use serde_json::json;
Expand Down Expand Up @@ -92,7 +93,7 @@ pub async fn registry_ping(cmd: RegistryPingCommand) -> Result<CommandOutput> {
_ => resolve_registry_credentials(image.registry()).await,
}?;

let Some(credentials) = credentials.as_oci_registry_auth() else {
let Ok(credentials) = RegistryAuth::try_from(&credentials) else {
bail!("failed to resolve registry credentials")
};

Expand Down
2 changes: 1 addition & 1 deletion crates/wash-cli/tests/wash_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fn integration_reg_push_comprehensive() {
not(can_reach_wasmcloud_azurecr_io),
ignore = "wasmcloud.azurecr.io is not reachable"
)]
async fn intergration_reg_config() -> Result<()> {
async fn integration_reg_config() -> Result<()> {
//===== Inital project setup and build actor artifact
let test_setup = init(
/* actor_name= */ "hello", /* template_name= */ "hello",
Expand Down

0 comments on commit b6095f8

Please sign in to comment.