wasmcloud_host/
registry.rs

1use anyhow::Result;
2use tracing::warn;
3use wasmcloud_control_interface::RegistryCredential;
4use wasmcloud_core::{RegistryAuth, RegistryConfig, RegistryType};
5
6/// Extension trait to enable converting between registry credentials
7pub trait RegistryCredentialExt {
8    /// Convert a [`RegistryCredential`] to a [`RegistryConfig`]
9    fn into_registry_config(self) -> Result<RegistryConfig>;
10}
11
12impl RegistryCredentialExt for RegistryCredential {
13    fn into_registry_config(self) -> Result<RegistryConfig> {
14        RegistryConfig::builder()
15            .reg_type(match self.registry_type() {
16                "oci" => RegistryType::Oci,
17                registry_type => {
18                    warn!(%registry_type, "unknown registry type, defaulting to OCI");
19                    RegistryType::Oci
20                }
21            })
22            .auth(match (self.username(), self.password(), self.token()) {
23                (Some(username), Some(password), _) => RegistryAuth::Basic(username.into(), password.into()),
24                (None, None, Some(token)) => RegistryAuth::Token(token.into()),
25                (None, None, None) => RegistryAuth::Anonymous,
26                (_, _, _) => {
27                    warn!("invalid combination of registry credentials, defaulting to no authentication");
28                    RegistryAuth::Anonymous
29                }
30            })
31            .allow_latest(false)
32            .allow_insecure(false)
33            .additional_ca_paths(Vec::new())
34            .build()
35    }
36}