feat(registry): add more info in auth & storage logs

This commit is contained in:
daimond113 2025-01-09 22:31:20 +01:00
parent 9bab997992
commit e61aeb5da0
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
5 changed files with 32 additions and 31 deletions

View file

@ -72,7 +72,7 @@ impl AuthImpl for GitHubAuth {
impl Display for GitHubAuth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "GitHub")
write!(f, "GitHub (client id: {})", self.client_id)
}
}

View file

@ -12,7 +12,7 @@ use async_compression::Level;
use convert_case::{Case, Casing};
use fs_err::tokio as fs;
use pesde::{
manifest::Manifest,
manifest::{DependencyType, Manifest},
source::{
git_index::GitBasedSource,
ids::VersionId,
@ -283,7 +283,12 @@ pub async fn publish_package(
RegistryError::InvalidArchive(format!("manifest has invalid dependencies: {e}"))
})?;
for (specifier, _) in dependencies.values() {
for (specifier, ty) in dependencies.values() {
// we need not verify dev dependencies, as they won't be installed
if *ty == DependencyType::Dev {
continue;
}
match specifier {
DependencySpecifiers::Pesde(specifier) => {
if specifier

View file

@ -124,6 +124,6 @@ impl StorageImpl for FSStorage {
impl Display for FSStorage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "FS")
write!(f, "FS ({})", self.root.display())
}
}

View file

@ -19,31 +19,27 @@ pub trait StorageImpl: Display {
package_name: &PackageName,
version: &VersionId,
contents: Vec<u8>,
) -> Result<(), crate::error::RegistryError>;
) -> Result<(), RegistryError>;
async fn get_package(
&self,
package_name: &PackageName,
version: &VersionId,
) -> Result<HttpResponse, crate::error::RegistryError>;
) -> Result<HttpResponse, RegistryError>;
async fn store_readme(
&self,
package_name: &PackageName,
version: &VersionId,
contents: Vec<u8>,
) -> Result<(), crate::error::RegistryError>;
) -> Result<(), RegistryError>;
async fn get_readme(
&self,
package_name: &PackageName,
version: &VersionId,
) -> Result<HttpResponse, crate::error::RegistryError>;
) -> Result<HttpResponse, RegistryError>;
async fn store_doc(
&self,
doc_hash: String,
contents: Vec<u8>,
) -> Result<(), crate::error::RegistryError>;
async fn get_doc(&self, doc_hash: &str) -> Result<HttpResponse, crate::error::RegistryError>;
async fn store_doc(&self, doc_hash: String, contents: Vec<u8>) -> Result<(), RegistryError>;
async fn get_doc(&self, doc_hash: &str) -> Result<HttpResponse, RegistryError>;
}
impl StorageImpl for Storage {
@ -120,14 +116,14 @@ impl Display for Storage {
pub fn get_storage_from_env() -> Storage {
if let Ok(endpoint) = benv!(parse "S3_ENDPOINT") {
Storage::S3(s3::S3Storage {
s3_bucket: Bucket::new(
bucket: Bucket::new(
endpoint,
UrlStyle::Path,
benv!(required "S3_BUCKET_NAME"),
benv!(required "S3_REGION"),
)
.unwrap(),
s3_credentials: Credentials::new(
credentials: Credentials::new(
benv!(required "S3_ACCESS_KEY"),
benv!(required "S3_SECRET_KEY"),
),

View file

@ -13,8 +13,8 @@ use std::{fmt::Display, time::Duration};
#[derive(Debug)]
pub struct S3Storage {
pub s3_bucket: Bucket,
pub s3_credentials: Credentials,
pub bucket: Bucket,
pub credentials: Credentials,
pub reqwest_client: reqwest::Client,
}
@ -28,8 +28,8 @@ impl StorageImpl for S3Storage {
contents: Vec<u8>,
) -> Result<(), RegistryError> {
let object_url = PutObject::new(
&self.s3_bucket,
Some(&self.s3_credentials),
&self.bucket,
Some(&self.credentials),
&format!(
"{package_name}/{}/{}/pkg.tar.gz",
version.version(),
@ -57,8 +57,8 @@ impl StorageImpl for S3Storage {
version: &VersionId,
) -> Result<HttpResponse, RegistryError> {
let object_url = GetObject::new(
&self.s3_bucket,
Some(&self.s3_credentials),
&self.bucket,
Some(&self.credentials),
&format!(
"{package_name}/{}/{}/pkg.tar.gz",
version.version(),
@ -79,8 +79,8 @@ impl StorageImpl for S3Storage {
contents: Vec<u8>,
) -> Result<(), RegistryError> {
let object_url = PutObject::new(
&self.s3_bucket,
Some(&self.s3_credentials),
&self.bucket,
Some(&self.credentials),
&format!(
"{package_name}/{}/{}/readme.gz",
version.version(),
@ -108,8 +108,8 @@ impl StorageImpl for S3Storage {
version: &VersionId,
) -> Result<HttpResponse, RegistryError> {
let object_url = GetObject::new(
&self.s3_bucket,
Some(&self.s3_credentials),
&self.bucket,
Some(&self.credentials),
&format!(
"{package_name}/{}/{}/readme.gz",
version.version(),
@ -125,8 +125,8 @@ impl StorageImpl for S3Storage {
async fn store_doc(&self, doc_hash: String, contents: Vec<u8>) -> Result<(), RegistryError> {
let object_url = PutObject::new(
&self.s3_bucket,
Some(&self.s3_credentials),
&self.bucket,
Some(&self.credentials),
// capitalize Doc to prevent conflicts with scope names
&format!("Doc/{}.gz", doc_hash),
)
@ -147,8 +147,8 @@ impl StorageImpl for S3Storage {
async fn get_doc(&self, doc_hash: &str) -> Result<HttpResponse, RegistryError> {
let object_url = GetObject::new(
&self.s3_bucket,
Some(&self.s3_credentials),
&self.bucket,
Some(&self.credentials),
&format!("Doc/{}.gz", doc_hash),
)
.sign(S3_SIGN_DURATION);
@ -161,6 +161,6 @@ impl StorageImpl for S3Storage {
impl Display for S3Storage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "S3")
write!(f, "S3 (bucket name: {})", self.bucket.name())
}
}