Skip to content

Commit 173f43d

Browse files
committed
feat: [#615] authorization layer implemented for the proxy service
1 parent 4f6ea18 commit 173f43d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/app.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ pub async fn run(configuration: Configuration, api_version: &Version) -> Running
101101
authorization_service.clone(),
102102
));
103103
let tag_service = Arc::new(tag::Service::new(tag_repository.clone(), authorization_service.clone()));
104-
let proxy_service = Arc::new(proxy::Service::new(image_cache_service.clone(), user_repository.clone()));
104+
let proxy_service = Arc::new(proxy::Service::new(
105+
image_cache_service.clone(),
106+
authorization_service.clone(),
107+
));
105108
let settings_service = Arc::new(settings::Service::new(configuration.clone(), authorization_service.clone()));
106109
let torrent_index = Arc::new(torrent::Index::new(
107110
configuration.clone(),

src/services/proxy.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ use std::sync::Arc;
1010

1111
use bytes::Bytes;
1212

13+
use super::authorization::{self, ACTION};
1314
use crate::cache::image::manager::{Error, ImageCacheService};
1415
use crate::models::user::UserId;
15-
use crate::services::user::Repository;
1616

1717
pub struct Service {
1818
image_cache_service: Arc<ImageCacheService>,
19-
user_repository: Arc<Box<dyn Repository>>,
19+
authorization_service: Arc<authorization::Service>,
2020
}
2121

2222
impl Service {
2323
#[must_use]
24-
pub fn new(image_cache_service: Arc<ImageCacheService>, user_repository: Arc<Box<dyn Repository>>) -> Self {
24+
pub fn new(image_cache_service: Arc<ImageCacheService>, authorization_service: Arc<authorization::Service>) -> Self {
2525
Self {
2626
image_cache_service,
27-
user_repository,
27+
authorization_service,
2828
}
2929
}
3030

@@ -39,8 +39,11 @@ impl Service {
3939
/// * The image is too big.
4040
/// * The user quota is met.
4141
pub async fn get_image_by_url(&self, url: &str, user_id: &UserId) -> Result<Bytes, Error> {
42-
let user = self.user_repository.get_compact(user_id).await.ok();
42+
self.authorization_service
43+
.authorize(ACTION::GetImageByUrl, Some(*user_id))
44+
.await
45+
.map_err(|_| Error::Unauthenticated)?;
4346

44-
self.image_cache_service.get_image_by_url(url, user).await
47+
self.image_cache_service.get_image_by_url(url, *user_id).await
4548
}
4649
}

0 commit comments

Comments
 (0)