use crate::{BuildContext, BuildContextProvider, ContextLocation, Error, Result};
use async_trait::async_trait;
pub struct RemoteUriSource {
pub(crate) uri: String,
}
impl RemoteUriSource {
pub fn new(uri: impl AsRef<str>) -> Result<Self> {
let uri = url::Url::parse(uri.as_ref()).map_err(|e| Error::InvalidInput(e.to_string()))?;
if !matches!(uri.scheme(), "http" | "https")
|| uri.host_str().is_none()
|| !uri.username().is_empty()
|| uri.password().is_some()
{
return Err(Error::InvalidInput(
"use an HTTP(S) URI without embedded credentials".into(),
));
}
Ok(Self { uri: uri.into() })
}
}
#[async_trait]
impl BuildContextProvider for RemoteUriSource {
async fn resolve(&self) -> Result<BuildContext> {
Ok(BuildContext::new(ContextLocation::Remote(self.uri.clone())))
}
}