mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-01 04:14:45 +03:00
validate preferred key on the backend
This commit is contained in:
parent
74c495bc2a
commit
cc17805694
@ -13,6 +13,12 @@ use super::controller::{self, Controller};
|
||||
impl From<controller::UpdateError> for Error {
|
||||
fn from(value: controller::UpdateError) -> Self {
|
||||
match value {
|
||||
controller::UpdateError::Validation(
|
||||
controller::UpdateValidationError::KeyNotFound(path)
|
||||
) => Error::UserError {
|
||||
code: Code::Projects,
|
||||
message: format!("key '{}' not found", path.display()),
|
||||
},
|
||||
controller::UpdateError::NotFound => Error::UserError {
|
||||
code: Code::Projects,
|
||||
message: "Project not found".into(),
|
||||
|
@ -92,6 +92,16 @@ impl Controller {
|
||||
}
|
||||
|
||||
pub async fn update(&self, project: &UpdateRequest) -> Result<Project, UpdateError> {
|
||||
if let Some(super::AuthKey::Local { private_key_path, .. }) = &project.preferred_key {
|
||||
use resolve_path::PathResolveExt;
|
||||
let private_key_path = private_key_path.resolve();
|
||||
if !private_key_path.exists() {
|
||||
return Err(UpdateError::Validation(
|
||||
UpdateValidationError::KeyNotFound(private_key_path.to_path_buf()),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let updated = self
|
||||
.projects_storage
|
||||
.update(project)
|
||||
@ -203,9 +213,17 @@ pub enum UpdateError {
|
||||
#[error("project not found")]
|
||||
NotFound,
|
||||
#[error(transparent)]
|
||||
Validation(UpdateValidationError),
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum UpdateValidationError {
|
||||
#[error("{0} not found")]
|
||||
KeyNotFound(path::PathBuf),
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AddError {
|
||||
#[error("not a directory")]
|
||||
|
Loading…
Reference in New Issue
Block a user