server: Rename RemoteFileError to StorageError
Already renamed everywhere else.
This commit is contained in:
parent
49c7cca94b
commit
27836028f4
|
@ -269,7 +269,7 @@ async fn upload_path_new(
|
||||||
backend
|
backend
|
||||||
.upload_file(key, stream.stream())
|
.upload_file(key, stream.stream())
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
// Confirm that the NAR Hash and Size are correct
|
// Confirm that the NAR Hash and Size are correct
|
||||||
// FIXME: errors
|
// FIXME: errors
|
||||||
|
|
|
@ -42,8 +42,8 @@ pub enum ServerError {
|
||||||
/// Database error: {0}
|
/// Database error: {0}
|
||||||
DatabaseError(AnyError),
|
DatabaseError(AnyError),
|
||||||
|
|
||||||
/// Remote file error: {0}
|
/// Storage error: {0}
|
||||||
RemoteFileError(AnyError),
|
StorageError(AnyError),
|
||||||
|
|
||||||
/// Manifest serialization error: {0}
|
/// Manifest serialization error: {0}
|
||||||
ManifestSerializationError(super::nix_manifest::Error),
|
ManifestSerializationError(super::nix_manifest::Error),
|
||||||
|
@ -70,8 +70,8 @@ impl ServerError {
|
||||||
Self::DatabaseError(AnyError::new(error))
|
Self::DatabaseError(AnyError::new(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remote_file_error(error: impl StdError + Send + Sync + 'static) -> Self {
|
pub fn storage_error(error: impl StdError + Send + Sync + 'static) -> Self {
|
||||||
Self::RemoteFileError(AnyError::new(error))
|
Self::StorageError(AnyError::new(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_error(error: impl StdError + Send + Sync + 'static) -> Self {
|
pub fn request_error(error: impl StdError + Send + Sync + 'static) -> Self {
|
||||||
|
@ -90,7 +90,7 @@ impl ServerError {
|
||||||
Self::InvalidCompressionType { .. } => "InvalidCompressionType",
|
Self::InvalidCompressionType { .. } => "InvalidCompressionType",
|
||||||
Self::AtticError(e) => e.name(),
|
Self::AtticError(e) => e.name(),
|
||||||
Self::DatabaseError(_) => "DatabaseError",
|
Self::DatabaseError(_) => "DatabaseError",
|
||||||
Self::RemoteFileError(_) => "RemoteFileError",
|
Self::StorageError(_) => "StorageError",
|
||||||
Self::ManifestSerializationError(_) => "ManifestSerializationError",
|
Self::ManifestSerializationError(_) => "ManifestSerializationError",
|
||||||
Self::AccessError(_) => "AccessError",
|
Self::AccessError(_) => "AccessError",
|
||||||
Self::RequestError(_) => "RequestError",
|
Self::RequestError(_) => "RequestError",
|
||||||
|
@ -115,7 +115,7 @@ impl ServerError {
|
||||||
Self::AccessError(super::access::Error::NoDiscoveryPermission) => Self::Unauthorized,
|
Self::AccessError(super::access::Error::NoDiscoveryPermission) => Self::Unauthorized,
|
||||||
|
|
||||||
Self::DatabaseError(_) => Self::InternalServerError,
|
Self::DatabaseError(_) => Self::InternalServerError,
|
||||||
Self::RemoteFileError(_) => Self::InternalServerError,
|
Self::StorageError(_) => Self::InternalServerError,
|
||||||
Self::ManifestSerializationError(_) => Self::InternalServerError,
|
Self::ManifestSerializationError(_) => Self::InternalServerError,
|
||||||
|
|
||||||
_ => self,
|
_ => self,
|
||||||
|
@ -157,7 +157,7 @@ impl From<super::access::Error> for ServerError {
|
||||||
impl IntoResponse for ServerError {
|
impl IntoResponse for ServerError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
// TODO: Better logging control
|
// TODO: Better logging control
|
||||||
if matches!(self, Self::DatabaseError(_) | Self::RemoteFileError(_) | Self::ManifestSerializationError(_) | Self::AtticError(_)) {
|
if matches!(self, Self::DatabaseError(_) | Self::StorageError(_) | Self::ManifestSerializationError(_) | Self::AtticError(_)) {
|
||||||
tracing::error!("{:?}", self);
|
tracing::error!("{:?}", self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl LocalBackend {
|
||||||
pub async fn new(config: LocalStorageConfig) -> ServerResult<Self> {
|
pub async fn new(config: LocalStorageConfig) -> ServerResult<Self> {
|
||||||
fs::create_dir_all(&config.path)
|
fs::create_dir_all(&config.path)
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
Ok(Self { config })
|
Ok(Self { config })
|
||||||
}
|
}
|
||||||
|
@ -53,11 +53,11 @@ impl StorageBackend for LocalBackend {
|
||||||
) -> ServerResult<RemoteFile> {
|
) -> ServerResult<RemoteFile> {
|
||||||
let mut file = File::create(self.get_path(&name))
|
let mut file = File::create(self.get_path(&name))
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
io::copy(&mut stream, &mut file)
|
io::copy(&mut stream, &mut file)
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
Ok(RemoteFile::Local(LocalRemoteFile { name }))
|
Ok(RemoteFile::Local(LocalRemoteFile { name }))
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ impl StorageBackend for LocalBackend {
|
||||||
async fn delete_file(&self, name: String) -> ServerResult<()> {
|
async fn delete_file(&self, name: String) -> ServerResult<()> {
|
||||||
fs::remove_file(self.get_path(&name))
|
fs::remove_file(self.get_path(&name))
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,14 @@ impl StorageBackend for LocalBackend {
|
||||||
let file = if let RemoteFile::Local(file) = file {
|
let file = if let RemoteFile::Local(file) = file {
|
||||||
file
|
file
|
||||||
} else {
|
} else {
|
||||||
return Err(ServerError::RemoteFileError(anyhow::anyhow!(
|
return Err(ServerError::StorageError(anyhow::anyhow!(
|
||||||
"Does not understand the remote file reference"
|
"Does not understand the remote file reference"
|
||||||
)));
|
)));
|
||||||
};
|
};
|
||||||
|
|
||||||
fs::remove_file(self.get_path(&file.name))
|
fs::remove_file(self.get_path(&file.name))
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ impl StorageBackend for LocalBackend {
|
||||||
async fn download_file(&self, name: String) -> ServerResult<Download> {
|
async fn download_file(&self, name: String) -> ServerResult<Download> {
|
||||||
let file = File::open(self.get_path(&name))
|
let file = File::open(self.get_path(&name))
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
Ok(Download::Stream(Box::new(file)))
|
Ok(Download::Stream(Box::new(file)))
|
||||||
}
|
}
|
||||||
|
@ -98,14 +98,14 @@ impl StorageBackend for LocalBackend {
|
||||||
let file = if let RemoteFile::Local(file) = file {
|
let file = if let RemoteFile::Local(file) = file {
|
||||||
file
|
file
|
||||||
} else {
|
} else {
|
||||||
return Err(ServerError::RemoteFileError(anyhow::anyhow!(
|
return Err(ServerError::StorageError(anyhow::anyhow!(
|
||||||
"Does not understand the remote file reference"
|
"Does not understand the remote file reference"
|
||||||
)));
|
)));
|
||||||
};
|
};
|
||||||
|
|
||||||
let file = File::open(self.get_path(&file.name))
|
let file = File::open(self.get_path(&file.name))
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
Ok(Download::Stream(Box::new(file)))
|
Ok(Download::Stream(Box::new(file)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl S3Backend {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(endpoint) = &config.endpoint {
|
if let Some(endpoint) = &config.endpoint {
|
||||||
let endpoint = Endpoint::immutable(endpoint).map_err(ServerError::remote_file_error)?;
|
let endpoint = Endpoint::immutable(endpoint).map_err(ServerError::storage_error)?;
|
||||||
builder = builder.endpoint_resolver(endpoint);
|
builder = builder.endpoint_resolver(endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ impl S3Backend {
|
||||||
let file = if let RemoteFile::S3(file) = file {
|
let file = if let RemoteFile::S3(file) = file {
|
||||||
file
|
file
|
||||||
} else {
|
} else {
|
||||||
return Err(ServerError::RemoteFileError(anyhow::anyhow!(
|
return Err(ServerError::StorageError(anyhow::anyhow!(
|
||||||
"Does not understand the remote file reference"
|
"Does not understand the remote file reference"
|
||||||
)));
|
)));
|
||||||
};
|
};
|
||||||
|
@ -152,7 +152,7 @@ impl StorageBackend for S3Backend {
|
||||||
.body(first_chunk.into())
|
.body(first_chunk.into())
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
tracing::debug!("put_object -> {:#?}", put_object);
|
tracing::debug!("put_object -> {:#?}", put_object);
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ impl StorageBackend for S3Backend {
|
||||||
.key(&name)
|
.key(&name)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
let upload_id = multipart.upload_id().unwrap();
|
let upload_id = multipart.upload_id().unwrap();
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ impl StorageBackend for S3Backend {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|join_result| join_result.unwrap())
|
.map(|join_result| join_result.unwrap())
|
||||||
.collect::<std::result::Result<Vec<_>, _>>()
|
.collect::<std::result::Result<Vec<_>, _>>()
|
||||||
.map_err(ServerError::remote_file_error)?
|
.map_err(ServerError::storage_error)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, part)| {
|
.map(|(idx, part)| {
|
||||||
|
@ -262,7 +262,7 @@ impl StorageBackend for S3Backend {
|
||||||
.multipart_upload(completed_multipart_upload)
|
.multipart_upload(completed_multipart_upload)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
tracing::debug!("complete_multipart_upload -> {:#?}", completion);
|
tracing::debug!("complete_multipart_upload -> {:#?}", completion);
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ impl StorageBackend for S3Backend {
|
||||||
.key(&name)
|
.key(&name)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
tracing::debug!("delete_file -> {:#?}", deletion);
|
tracing::debug!("delete_file -> {:#?}", deletion);
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ impl StorageBackend for S3Backend {
|
||||||
.key(&file.key)
|
.key(&file.key)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
tracing::debug!("delete_file -> {:#?}", deletion);
|
tracing::debug!("delete_file -> {:#?}", deletion);
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ impl StorageBackend for S3Backend {
|
||||||
async fn download_file(&self, name: String) -> ServerResult<Download> {
|
async fn download_file(&self, name: String) -> ServerResult<Download> {
|
||||||
// FIXME: Configurable expiration
|
// FIXME: Configurable expiration
|
||||||
let presign_config = PresigningConfig::expires_in(Duration::from_secs(10))
|
let presign_config = PresigningConfig::expires_in(Duration::from_secs(10))
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
let presigned = self
|
let presigned = self
|
||||||
.client
|
.client
|
||||||
|
@ -318,7 +318,7 @@ impl StorageBackend for S3Backend {
|
||||||
.key(&name)
|
.key(&name)
|
||||||
.presigned(presign_config)
|
.presigned(presign_config)
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
Ok(Download::Redirect(presigned.uri().to_string()))
|
Ok(Download::Redirect(presigned.uri().to_string()))
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,7 @@ impl StorageBackend for S3Backend {
|
||||||
let (client, file) = self.get_client_from_db_ref(file).await?;
|
let (client, file) = self.get_client_from_db_ref(file).await?;
|
||||||
|
|
||||||
let presign_config = PresigningConfig::expires_in(Duration::from_secs(600))
|
let presign_config = PresigningConfig::expires_in(Duration::from_secs(600))
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
let presigned = client
|
let presigned = client
|
||||||
.get_object()
|
.get_object()
|
||||||
|
@ -335,7 +335,7 @@ impl StorageBackend for S3Backend {
|
||||||
.key(&file.key)
|
.key(&file.key)
|
||||||
.presigned(presign_config)
|
.presigned(presign_config)
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
Ok(Download::Redirect(presigned.uri().to_string()))
|
Ok(Download::Redirect(presigned.uri().to_string()))
|
||||||
}
|
}
|
||||||
|
@ -359,7 +359,7 @@ async fn read_chunk_async<S: AsyncRead + Unpin + Send>(stream: &mut S) -> Server
|
||||||
let read = stream
|
let read = stream
|
||||||
.read(buf)
|
.read(buf)
|
||||||
.await
|
.await
|
||||||
.map_err(ServerError::remote_file_error)?;
|
.map_err(ServerError::storage_error)?;
|
||||||
|
|
||||||
if read == 0 {
|
if read == 0 {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue