Skip to content

Commit

Permalink
refactor(resolver): support optional preface name
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo committed May 17, 2024
1 parent 3a75153 commit a53b2b8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.8.26"
version = "0.9.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/amphitheatre-app/amphitheatre"
Expand All @@ -22,7 +22,7 @@ members = [
# https://doc.rust-lang.org/cargo/reference/workspaces.html#the-workspacedependencies-table
[workspace.dependencies]
amp-builder = { path = "builder" }
amp-common = { git = "https://github.com/amphitheatre-app/common", tag = "v0.8.3" }
amp-common = { git = "https://github.com/amphitheatre-app/common", tag = "v0.9.0" }
amp-resolver = { path = "resolver" }
amp-resources = { path = "resources" }
amp-workflow = { path = "workflow" }
Expand Down
3 changes: 3 additions & 0 deletions resolver/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub enum ResolveError {

#[error("SourceNotSet")]
SourceNotSet,

#[error("NameNotSet")]
NameNotSet,
}

pub type Result<T, E = ResolveError> = std::result::Result<T, E>;
5 changes: 3 additions & 2 deletions resolver/src/preface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ use kube::Client as KubeClient;
/// Load manifest from different sources and return the actor spec.
pub async fn load(client: &KubeClient, credentials: &Credentials, preface: &Preface) -> Result<CharacterSpec> {
if let Some(p) = &preface.registry {
let name = preface.name.as_ref().ok_or(ResolveError::NameNotSet)?;
let registry = p.registry.clone().unwrap_or_else(|| "catalog".to_string());
return match registry.as_str() {
"catalog" => load_from_catalog(credentials, &preface.name, &p.version),
"hub" => load_from_cluster(client, &preface.name).await,
"catalog" => load_from_catalog(credentials, name, &p.version),
"hub" => load_from_cluster(client, name).await,
x => Err(ResolveError::UnknownCharacterRegistry(x.to_string())),
};
}
Expand Down

0 comments on commit a53b2b8

Please sign in to comment.