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

Simplifying the client API and refactoring federation #268

Merged
merged 6 commits into from
May 3, 2024
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
12 changes: 0 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ jobs:
- name: Install Rust
run: rustup update stable --no-self-update && rustup default stable && rustup target add wasm32-wasi && rustup target add wasm32-unknown-unknown
shell: bash
- name: Install Protobuf Compiler
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build all crates
run: cargo build --all --features warg-server/debug
- name: Run all tests
Expand All @@ -41,10 +37,6 @@ jobs:
- name: Install Rust
run: rustup update stable --no-self-update && rustup default stable && rustup target add wasm32-wasi && rustup target add wasm32-unknown-unknown
shell: bash
- name: Install Protobuf Compiler
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install diesel-cli
run: cargo install diesel_cli
- name: Build all crates
Expand All @@ -59,10 +51,6 @@ jobs:
- uses: actions/checkout@v3
- name: Install Rust
run: rustup update stable --no-self-update && rustup default stable
- name: Install Protobuf Compiler
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install warg CLI
run: cargo install --locked --path .

Expand Down
66 changes: 50 additions & 16 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ indexmap.workspace = true
semver.workspace = true
wat = "1.0.85"
wasmprinter = "0.2.78"
dialoguer = "0.11.0"
dialoguer = { workspace = true }
itertools = "0.12.1"
secrecy= { workspace = true }
secrecy = { workspace = true }

[dev-dependencies]
reqwest = { workspace = true }
Expand Down Expand Up @@ -72,6 +72,7 @@ homepage = "https://warg.io/"
repository = "https://github.com/bytecodealliance/registry"

[workspace.dependencies]
dialoguer = "0.11.0"
ptree = "0.4.0"
warg-api = { path = "crates/api", version = "0.5.0-dev" }
warg-credentials = { path = "crates/credentials", version = "0.5.0-dev" }
Expand Down Expand Up @@ -141,5 +142,5 @@ regex = "1"
wasm-encoder = "0.41.0"
wasm-compose = "0.5.2"
wasmparser = "0.121.0"
protox = "0.5.1"
protox = "0.6.0"
toml = "0.8.2"
34 changes: 4 additions & 30 deletions crates/api/src/v1/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ pub enum PackageError {
/// The provided package's namespace is imported from another registry.
#[error("namespace `{0}` is an imported namespace from another registry")]
NamespaceImported(String),
/// The provided package's namespace conflicts with an existing namespace where the name only differs by case.
#[error("namespace conflicts with existing namespace `{0}`; package namespaces must be unique in a case insensitive way")]
NamespaceConflict(String),
/// The provided package name conflicts with an existing package where the name only differs by case.
#[error("the package conflicts with existing package name `{0}`; package names must be unique in a case insensitive way")]
PackageNameConflict(PackageName),
/// The operation was not authorized by the registry.
#[error("unauthorized operation: {0}")]
Unauthorized(String),
Expand All @@ -156,13 +150,9 @@ impl PackageError {
/// Returns the HTTP status code of the error.
pub fn status(&self) -> u16 {
match self {
// Note: this is 403 and not a 401 as the registry does not use
// HTTP authentication.
Self::Unauthorized { .. } => 403,
Self::Unauthorized { .. } => 401,
Self::LogNotFound(_) | Self::RecordNotFound(_) | Self::NamespaceNotDefined(_) => 404,
Self::NamespaceImported(_)
| Self::NamespaceConflict(_)
| Self::PackageNameConflict(_) => 409,
Self::NamespaceImported(_) => 409,
Self::RecordNotSourcing => 405,
Self::Rejection(_) => 422,
Self::NotSupported(_) => 501,
Expand All @@ -189,7 +179,7 @@ where
<T as ToOwned>::Owned: Serialize + for<'b> Deserialize<'b>,
{
Unauthorized {
status: Status<403>,
status: Status<401>,
message: Cow<'a, str>,
},
NotFound {
Expand Down Expand Up @@ -225,7 +215,7 @@ impl Serialize for PackageError {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
Self::Unauthorized(message) => RawError::Unauthorized::<()> {
status: Status::<403>,
status: Status::<401>,
message: Cow::Borrowed(message),
}
.serialize(serializer),
Expand Down Expand Up @@ -253,18 +243,6 @@ impl Serialize for PackageError {
id: Cow::Borrowed(namespace),
}
.serialize(serializer),
Self::NamespaceConflict(existing) => RawError::Conflict {
status: Status::<409>,
ty: EntityType::Namespace,
id: Cow::Borrowed(existing),
}
.serialize(serializer),
Self::PackageNameConflict(existing) => RawError::Conflict {
status: Status::<409>,
ty: EntityType::Name,
id: Cow::Borrowed(existing),
}
.serialize(serializer),
Self::RecordNotSourcing => RawError::RecordNotSourcing::<()> {
status: Status::<405>,
}
Expand Down Expand Up @@ -322,11 +300,7 @@ impl<'de> Deserialize<'de> for PackageError {
)),
},
RawError::Conflict { status: _, ty, id } => match ty {
EntityType::Namespace => Ok(Self::NamespaceConflict(id.into_owned())),
EntityType::NamespaceImport => Ok(Self::NamespaceImported(id.into_owned())),
EntityType::Name => Ok(Self::PackageNameConflict(
PackageName::new(id.into_owned()).unwrap(),
)),
_ => Err(serde::de::Error::invalid_value(
Unexpected::Enum,
&"a valid entity type",
Expand Down
1 change: 1 addition & 0 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ clap = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
dialoguer = { workspace = true }
tokio-util = { workspace = true }
tempfile = { workspace = true }
reqwest = { workspace = true }
Expand Down
Loading
Loading