Remove client-side validation when uploading package

This commit is contained in:
Felix Schütt
2022-12-16 23:55:57 +01:00
parent e1c42b5f90
commit 46a2d28f30

View File

@@ -9,7 +9,6 @@ use tar::Builder;
use thiserror::Error; use thiserror::Error;
use time::{self, OffsetDateTime}; use time::{self, OffsetDateTime};
use wasmer_registry::publish::SignArchiveResult; use wasmer_registry::publish::SignArchiveResult;
use wasmer_registry::Package;
use wasmer_registry::PartialWapmConfig; use wasmer_registry::PartialWapmConfig;
const CURRENT_DATA_VERSION: i32 = 3; const CURRENT_DATA_VERSION: i32 = 3;
@@ -86,40 +85,14 @@ impl Publish {
manifest.package.version = version.clone(); manifest.package.version = version.clone();
} }
// See if a user is logged in. The backend should check for authorization on uploading let registry = match self.registry.as_deref() {
let (registry, username) = Some(s) => wasmer_registry::format_graphql(s),
wasmer_registry::whoami(self.registry.as_deref(), self.token.as_deref()).with_context( None => {
|| { let config = PartialWapmConfig::from_file()
anyhow::anyhow!( .map_err(|e| anyhow::anyhow!("could not load config {e}"))?;
"could not find username / registry for registry = {:?}, token = {}", config.registry.get_current_registry()
self.registry, }
self.token.as_deref().unwrap_or_default() };
)
},
)?;
let registry_present =
wasmer_registry::test_if_registry_present(&registry).unwrap_or(false);
if !registry_present {
return Err(anyhow::anyhow!(
"registry {} is currently unavailable",
registry
));
}
// If the package name is not a "/", try to prefix it with the current logged in user
if !Package::validate_package_name(&manifest.package.name) {
manifest.package.name = format!("{username}/{}", manifest.package.name);
}
// Validate the name again
if !Package::validate_package_name(&manifest.package.name) {
return Err(anyhow::anyhow!(
"Invalid package name {:?}",
manifest.package.name
));
}
if !self.no_validate { if !self.no_validate {
validate::validate_directory(&manifest, &registry, cwd.clone())?; validate::validate_directory(&manifest, &registry, cwd.clone())?;
@@ -167,7 +140,7 @@ impl Publish {
} }
wasmer_registry::publish::try_chunked_uploading( wasmer_registry::publish::try_chunked_uploading(
self.registry.clone(), Some(registry),
self.token.clone(), self.token.clone(),
&manifest.package, &manifest.package,
&manifest_string, &manifest_string,