Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
69 changes: 6 additions & 63 deletions Cargo.lock

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

6 changes: 1 addition & 5 deletions crates/core/tests/group_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ use sqlx::PgPool;
/// NuGet, the built-in format plugin, as the `Format` the repository code
/// works with.
fn nuget() -> forge_plugin::PluginFormat {
let plugin = forge_plugin::Plugin::builtin(
forge_format_nuget::PLUGIN_TOML,
forge_format_nuget::Nuget::default(),
)
.expect("crates/formats/nuget/plugin.toml is valid");
let plugin = forge_plugin::Plugin::builtin(forge_format_nuget::Nuget::default());
forge_plugin::PluginFormat::new(&plugin)
}

Expand Down
6 changes: 1 addition & 5 deletions crates/core/tests/hosted_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ use sqlx::PgPool;
/// NuGet, the built-in format plugin, as the `Format` the repository code
/// works with.
fn nuget() -> forge_plugin::PluginFormat {
let plugin = forge_plugin::Plugin::builtin(
forge_format_nuget::PLUGIN_TOML,
forge_format_nuget::Nuget::default(),
)
.expect("crates/formats/nuget/plugin.toml is valid");
let plugin = forge_plugin::Plugin::builtin(forge_format_nuget::Nuget::default());
forge_plugin::PluginFormat::new(&plugin)
}

Expand Down
6 changes: 1 addition & 5 deletions crates/core/tests/hosted_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ use tokio::sync::Mutex;
/// NuGet, the built-in format plugin, as the `Format` the repository code
/// works with.
fn nuget() -> forge_plugin::PluginFormat {
let plugin = forge_plugin::Plugin::builtin(
forge_format_nuget::PLUGIN_TOML,
forge_format_nuget::Nuget::default(),
)
.expect("crates/formats/nuget/plugin.toml is valid");
let plugin = forge_plugin::Plugin::builtin(forge_format_nuget::Nuget::default());
forge_plugin::PluginFormat::new(&plugin)
}

Expand Down
6 changes: 1 addition & 5 deletions crates/core/tests/proxy_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ use tokio::sync::Notify;
/// NuGet, the built-in format plugin, as the `Format` the repository code
/// works with.
fn nuget() -> forge_plugin::PluginFormat {
let plugin = forge_plugin::Plugin::builtin(
forge_format_nuget::PLUGIN_TOML,
forge_format_nuget::Nuget::default(),
)
.expect("crates/formats/nuget/plugin.toml is valid");
let plugin = forge_plugin::Plugin::builtin(forge_format_nuget::Nuget::default());
forge_plugin::PluginFormat::new(&plugin)
}

Expand Down
6 changes: 1 addition & 5 deletions crates/core/tests/retention_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ use common::{pool, unique};
/// NuGet, the built-in format plugin, as the `Format` the repository code
/// works with.
fn nuget() -> forge_plugin::PluginFormat {
let plugin = forge_plugin::Plugin::builtin(
forge_format_nuget::PLUGIN_TOML,
forge_format_nuget::Nuget::default(),
)
.expect("crates/formats/nuget/plugin.toml is valid");
let plugin = forge_plugin::Plugin::builtin(forge_format_nuget::Nuget::default());
forge_plugin::PluginFormat::new(&plugin)
}

Expand Down
18 changes: 9 additions & 9 deletions crates/formats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ the design, the contract and how to write one.

A plugin directory holds:

- `Cargo.toml`: a member of the workspace;
- `plugin.toml`: the format id (also the directory's name), display name,
version, the `forge:format` contract version it targets (`api`), and
optionally its mount, repository kinds (`proxy` when it implements
`upstream`), its `storage` (`packages`, or `files` for a files format such
as raw) and `[assets]` names;
- `src/`: `impl FormatPlugin`, and `pub const PLUGIN_TOML: &str =
forge_plugin_api::plugin_toml!();`.
- `Cargo.toml`: a member of the workspace; its `version` is the plugin's;
- `src/`: `impl FormatPlugin`, and the format's `pub const DESCRIPTOR:
Descriptor` that its `descriptor()` returns: the format id (also the
directory's name), display name, version (`env!("CARGO_PKG_VERSION")`),
description, mount, repository kinds (`Proxy` when it implements
`upstream`), its `storage` (`Packages`, or `Files` for a files format such
as raw) and its asset names.

The server installs it in `plugins::builtin()`
([`crates/server/src/plugins.rs`](../server/src/plugins.rs)). The
([`crates/server/src/plugins.rs`](../server/src/plugins.rs)), whose tests
check every built-in format's descriptor (`forge_plugin::descriptor`). The
workspace builds, lints and tests the plugins like every other crate.
2 changes: 1 addition & 1 deletion crates/formats/nuget/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "forge-format-nuget"
# The plugin's own version: keep it equal to `version` in plugin.toml.
# The plugin's own version, its descriptor's.
version = "1.0.0"
edition.workspace = true
rust-version.workspace = true
Expand Down
17 changes: 0 additions & 17 deletions crates/formats/nuget/plugin.toml

This file was deleted.

52 changes: 31 additions & 21 deletions crates/formats/nuget/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! NuGet V3 feeds for Forge, as a format plugin.
//!
//! Served under `/v3/{repository}` (its `plugin.toml` names the mount):
//! Served under `/v3/{repository}` (its [`DESCRIPTOR`] names the mount):
//!
//! * `GET /index.json` — the service index;
//! * `GET /flat/{id}/index.json`, `/flat/{id}/{version}/{file}` — the flat
Expand All @@ -17,7 +17,7 @@
//! Ids are matched case-insensitively (`ToLowerInvariant`); versions are
//! NuGet versions, normalized (`1.0` → `1.0.0`).
//!
//! Forge links this plugin in ([`Nuget`], [`PLUGIN_TOML`]).
//! Forge links this plugin in ([`Nuget`], [`DESCRIPTOR`]).

pub mod model;
pub mod nuspec;
Expand All @@ -28,14 +28,35 @@ pub mod version;
use std::cmp::Ordering;

use forge_plugin_api::{
Action, FetchResult, FormatError, FormatPlugin, Loaded, PackageSource, ParsedPackage, Remote,
Repository, Request, UpstreamOp, UpstreamStep,
Action, Assets, Descriptor, FetchResult, FormatError, FormatPlugin, Loaded, PackageSource,
ParsedPackage, Remote, Repository, RepositoryKind, Request, Storage, UpstreamOp, UpstreamStep,
};

pub use model::NupkgLimits;

/// This plugin's `plugin.toml`: its format id, name, version and mount.
pub const PLUGIN_TOML: &str = forge_plugin_api::plugin_toml!();
/// What NuGet says about itself: its format id, name, version and mount.
pub const DESCRIPTOR: Descriptor = Descriptor {
id: "nuget",
name: "NuGet",
version: env!("CARGO_PKG_VERSION"),
description: "NuGet V3 feeds: push, restore and search with dotnet, nuget.exe and Visual \
Studio; proxies of nuget.org and other V3 feeds.",
mount: "/v3",
// Proxies mirror another V3 feed through the plugin's upstream side.
kinds: &[
RepositoryKind::Hosted,
RepositoryKind::Proxy,
RepositoryKind::Group,
],
storage: Storage::Packages,
// The asset names and content types NuGet has always stored.
assets: Assets {
package: "package.nupkg",
package_type: "application/octet-stream",
manifest: "package.nuspec",
manifest_type: "application/xml",
},
};

/// The NuGet format, with the zip-bomb limits applied while parsing packages.
#[derive(Debug, Clone, Default)]
Expand All @@ -51,6 +72,10 @@ impl Nuget {
}

impl FormatPlugin for Nuget {
fn descriptor(&self) -> &'static Descriptor {
&DESCRIPTOR
}

fn canonical_id(&self, id: &str) -> String {
nuspec::lower_id(id)
}
Expand Down Expand Up @@ -100,21 +125,6 @@ impl FormatPlugin for Nuget {
mod tests {
use super::*;

#[test]
fn plugin_toml_names_this_crate() {
let value = |key: &str| {
PLUGIN_TOML
.lines()
.filter_map(|line| line.split_once('='))
.find(|(k, _)| k.trim() == key)
.map(|(_, v)| v.trim().trim_matches('"').to_string())
};
assert_eq!(value("id").as_deref(), Some("nuget"));
assert_eq!(value("version").as_deref(), Some(env!("CARGO_PKG_VERSION")));
assert_eq!(value("api").as_deref(), Some(forge_plugin_api::API));
assert_eq!(value("mount").as_deref(), Some("/v3"));
}

#[test]
fn the_rules_are_nugets() {
let nuget = Nuget::default();
Expand Down
2 changes: 1 addition & 1 deletion crates/formats/raw/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "forge-format-raw"
# The plugin's own version: keep it equal to `version` in plugin.toml.
# The plugin's own version, its descriptor's.
version = "1.0.0"
edition.workspace = true
rust-version.workspace = true
Expand Down
13 changes: 0 additions & 13 deletions crates/formats/raw/plugin.toml

This file was deleted.

Loading
Loading