Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make better use of namespace storage #263

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions crates/client/src/api.rs
Original file line number Diff line number Diff line change
@@ -159,11 +159,11 @@ async fn into_result<T: DeserializeOwned, E: DeserializeOwned + Into<ClientError
}

trait WithWargHeader {
fn warg_header(self, registry_header: &Option<RegistryDomain>) -> Result<RequestBuilder>;
fn warg_header(self, registry_header: Option<&RegistryDomain>) -> Result<RequestBuilder>;
}

impl WithWargHeader for RequestBuilder {
fn warg_header(self, registry_header: &Option<RegistryDomain>) -> Result<RequestBuilder> {
fn warg_header(self, registry_header: Option<&RegistryDomain>) -> Result<RequestBuilder> {
if let Some(reg) = registry_header {
Ok(self.header(REGISTRY_HEADER_NAME, HeaderValue::try_from(reg.clone())?))
} else {
@@ -219,13 +219,14 @@ impl Client {
/// Gets the latest checkpoint from the registry.
pub async fn latest_checkpoint(
&self,
reg_domain: Option<&RegistryDomain>,
) -> Result<SerdeEnvelope<TimestampedCheckpoint>, ClientError> {
let url = self.url.join(paths::fetch_checkpoint());
tracing::debug!("getting latest checkpoint at `{url}`");
into_result::<_, FetchError>(
self.client
.get(url)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?,
@@ -260,6 +261,7 @@ impl Client {
/// Verify checkpoint of the registry.
pub async fn verify_checkpoint(
&self,
reg_domain: Option<&RegistryDomain>,
request: SerdeEnvelope<TimestampedCheckpoint>,
) -> Result<CheckpointVerificationResponse, ClientError> {
let url = self.url.join(paths::verify_checkpoint());
@@ -269,7 +271,7 @@ impl Client {
.client
.post(url)
.json(&request)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?;
@@ -279,6 +281,7 @@ impl Client {
/// Fetches package log entries from the registry.
pub async fn fetch_logs(
&self,
reg_domain: Option<&RegistryDomain>,
request: FetchLogsRequest<'_>,
) -> Result<FetchLogsResponse, ClientError> {
let url = self.url.join(paths::fetch_logs());
@@ -287,7 +290,7 @@ impl Client {
.client
.post(&url)
.json(&request)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?;
@@ -306,6 +309,7 @@ impl Client {
/// Fetches package names from the registry.
pub async fn fetch_package_names(
&self,
reg_domain: Option<&RegistryDomain>,
request: FetchPackageNamesRequest<'_>,
) -> Result<FetchPackageNamesResponse, ClientError> {
let url = self.url.join(paths::fetch_package_names());
@@ -314,7 +318,7 @@ impl Client {
let response = self
.client
.post(url)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.json(&request)
.send()
@@ -323,14 +327,17 @@ impl Client {
}

/// Gets ledger sources from the registry.
pub async fn ledger_sources(&self) -> Result<LedgerSourcesResponse, ClientError> {
pub async fn ledger_sources(
&self,
reg_domain: Option<&RegistryDomain>,
) -> Result<LedgerSourcesResponse, ClientError> {
let url = self.url.join(paths::ledger_sources());
tracing::debug!("getting ledger sources at `{url}`");

into_result::<_, LedgerError>(
self.client
.get(url)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?,
@@ -341,6 +348,7 @@ impl Client {
/// Publish a new record to a package log.
pub async fn publish_package_record(
&self,
reg_domain: Option<&RegistryDomain>,
log_id: &LogId,
request: PublishRecordRequest<'_>,
) -> Result<PackageRecord, ClientError> {
@@ -354,7 +362,7 @@ impl Client {
.client
.post(url)
.json(&request)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?;
@@ -364,6 +372,7 @@ impl Client {
/// Gets a package record from the registry.
pub async fn get_package_record(
&self,
reg_domain: Option<&RegistryDomain>,
log_id: &LogId,
record_id: &RecordId,
) -> Result<PackageRecord, ClientError> {
@@ -373,7 +382,7 @@ impl Client {
into_result::<_, PackageError>(
self.client
.get(url)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?,
@@ -384,6 +393,7 @@ impl Client {
/// Gets a content sources from the registry.
pub async fn content_sources(
&self,
reg_domain: Option<&RegistryDomain>,
digest: &AnyHash,
) -> Result<ContentSourcesResponse, ClientError> {
let url = self.url.join(&paths::content_sources(digest));
@@ -392,7 +402,7 @@ impl Client {
into_result::<_, ContentError>(
self.client
.get(url)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?,
@@ -403,11 +413,13 @@ impl Client {
/// Downloads the content associated with a given record.
pub async fn download_content(
&self,
registry_domain: Option<&RegistryDomain>,
digest: &AnyHash,
) -> Result<impl Stream<Item = Result<Bytes>>, ClientError> {
tracing::debug!("requesting content download for digest `{digest}`");

let ContentSourcesResponse { content_sources } = self.content_sources(digest).await?;
let ContentSourcesResponse { content_sources } =
self.content_sources(registry_domain, digest).await?;

let sources = content_sources
.get(digest)
@@ -438,14 +450,10 @@ impl Client {
self.warg_registry_header = registry;
}

/// Get warg-registry header value
pub fn get_warg_registry(&self) -> &Option<RegistryDomain> {
&self.warg_registry_header
}

/// Proves the inclusion of the given package log heads in the registry.
pub async fn prove_inclusion(
&self,
reg_domain: Option<&RegistryDomain>,
request: InclusionRequest,
checkpoint: &Checkpoint,
leafs: &[LogLeaf],
@@ -457,7 +465,7 @@ impl Client {
self.client
.post(url)
.json(&request)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?,
@@ -470,6 +478,7 @@ impl Client {
/// Proves consistency between two log roots.
pub async fn prove_log_consistency(
&self,
reg_domain: Option<&RegistryDomain>,
request: ConsistencyRequest,
from_log_root: Cow<'_, AnyHash>,
to_log_root: Cow<'_, AnyHash>,
@@ -479,7 +488,7 @@ impl Client {
self.client
.post(url)
.json(&request)
.warg_header(self.get_warg_registry())?
.warg_header(reg_domain)?
.auth(self.auth_token())
.send()
.await?,
20 changes: 16 additions & 4 deletions crates/client/src/depsolve.rs
Original file line number Diff line number Diff line change
@@ -101,9 +101,10 @@ impl LockListBuilder {
match import.kind {
ImportKind::Locked(_) | ImportKind::Unlocked => {
let id = PackageName::new(import.name.clone())?;
let registry_domain = client.get_warg_registry(id.namespace()).await?;
if let Some(info) = client
.registry()
.load_package(client.api.get_warg_registry(), &id)
.load_package(registry_domain.as_ref(), &id)
.await?
{
let release = info.state.releases().last();
@@ -114,10 +115,15 @@ impl LockListBuilder {
}
self.lock_list.insert(import);
} else {
client.download(&id, &VersionReq::STAR).await?;
client
.download(registry_domain.as_ref(), &id, &VersionReq::STAR)
.await?;
if let Some(info) = client
.registry()
.load_package(client.api.get_warg_registry(), &id)
.load_package(
client.get_warg_registry(id.namespace()).await?.as_ref(),
&id,
)
.await?
{
let release = info.state.releases().last();
@@ -213,7 +219,13 @@ where
if let Some(info) = self
.client
.registry()
.load_package(self.client.api.get_warg_registry(), &pkg_id)
.load_package(
self.client
.get_warg_registry(pkg_id.namespace())
.await?
.as_ref(),
&pkg_id,
)
.await?
{
let release = if parsed_imp.req != VersionReq::STAR {
Loading
Loading