Skip to content

Commit

Permalink
Add warning field to fetch logs response.
Browse files Browse the repository at this point in the history
The intention of adding this field is to handle moved repositories.
When a repository is moved, Warg will use the new repository name
instead, but the users must be alerted so they can update their
dependency list.
  • Loading branch information
RobbieMcKinstry authored and lann committed Apr 5, 2024
1 parent 8087c66 commit 184c389
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/api/src/v1/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub struct FetchLogsResponse {
/// The package records appended since last known package record ids.
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub packages: IndexMap<LogId, Vec<PublishedRecord>>,
/// An optional list of warnings.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub warnings: Vec<FetchWarning>,
}

/// Represents a fetch package names request.
Expand All @@ -72,6 +75,13 @@ pub struct FetchPackageNamesResponse {
pub packages: IndexMap<LogId, Option<PackageName>>,
}

/// A warning message.
#[derive(Serialize, Deserialize, Debug)]
pub struct FetchWarning {
/// The warning message itself
pub message: String,
}

/// Represents a fetch API error.
#[non_exhaustive]
#[derive(Debug, Error)]
Expand Down
5 changes: 5 additions & 0 deletions crates/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,11 @@ impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C,
packages: Cow::Borrowed(&last_known),
})
.await
.inspect(|res| {
for warning in res.warnings.iter() {
tracing::warn!("WARNING: {}", warning.message);
}
})
.map_err(|e| {
ClientError::translate_log_not_found(e, |id| {
packages.get(id).map(|p| p.name.clone())
Expand Down
12 changes: 12 additions & 0 deletions crates/server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,12 @@ components:
maxItems: 1000
items:
$ref: "#/components/schemas/PublishedRecordEnvelope"
warnings:
type: array
description: An optional list of warnings.
maxItems: 1000
items:
$ref: "#/components/schemas/FetchWarning"
packages:
type: object
description: The map of package log identifier to package records.
Expand Down Expand Up @@ -1085,6 +1091,12 @@ components:
maxLength: 1048576
example: "ZXhhbXBsZQ=="
- $ref: "#/components/schemas/Signature"
FetchWarning:
description: A warning message
properties:
message:
description: The warning message itself.
type: string
PublishedRecordEnvelope:
description: A signed envelope body with the published registry log index.
allOf:
Expand Down
1 change: 1 addition & 0 deletions crates/server/src/api/v1/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ async fn fetch_logs(
more,
operator,
packages: map,
warnings: Vec::default(),
}))
}

Expand Down

0 comments on commit 184c389

Please sign in to comment.