JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Fix handling stack

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨c53b026

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨3696⁩ bytes
Raw
1 pub mod discovery;
2 pub mod git;
3 pub mod github;
4 pub mod settings;
5 pub mod user;
6
7 use anyhow::Error;
8 use async_trait::async_trait;
9 use serde_json::Value;
10
11 use crate::backend::git::GitBackendError;
12 use giterated_models::authenticated::UserAuthenticationToken;
13
14 use giterated_models::instance::{
15 AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest,
16 };
17
18 use giterated_models::repository::{
19 IssueLabel, Repository, RepositoryFileInspectRequest, RepositoryIssue,
20 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
21 RepositorySummary, RepositoryTreeEntry,
22 };
23 use giterated_models::settings::AnySetting;
24 use giterated_models::user::User;
25 use giterated_models::value::AnyValue;
26
27 #[async_trait]
28 pub trait RepositoryBackend {
29 async fn create_repository(
30 &mut self,
31 user: &User,
32 request: &RepositoryCreateRequest,
33 ) -> Result<Repository, GitBackendError>;
34 async fn repository_file_inspect(
35 &mut self,
36 requester: Option<&User>,
37 repository: &Repository,
38 request: &RepositoryFileInspectRequest,
39 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
40 async fn get_value(
41 &mut self,
42 user: &Repository,
43 name: &str,
44 ) -> Result<AnyValue<Repository>, Error>;
45 async fn get_setting(&mut self, user: &Repository, name: &str) -> Result<AnySetting, Error>;
46 async fn write_setting(
47 &mut self,
48 user: &Repository,
49 name: &str,
50 setting: &Value,
51 ) -> Result<(), Error>;
52 async fn exists(&mut self, repository: &Repository) -> Result<bool, Error>;
53 }
54
55 pub trait IssuesBackend {
56 fn issues_count(
57 &mut self,
58 requester: Option<&User>,
59 request: &RepositoryIssuesCountRequest,
60 ) -> Result<u64, Error>;
61 fn issue_labels(
62 &mut self,
63 requester: Option<&User>,
64 request: &RepositoryIssueLabelsRequest,
65 ) -> Result<Vec<IssueLabel>, Error>;
66 fn issues(
67 &mut self,
68 requester: Option<&User>,
69 request: &RepositoryIssuesRequest,
70 ) -> Result<Vec<RepositoryIssue>, Error>;
71 }
72
73 #[async_trait::async_trait]
74 pub trait AuthBackend {
75 async fn register(
76 &mut self,
77 request: RegisterAccountRequest,
78 ) -> Result<UserAuthenticationToken, Error>;
79
80 async fn login(
81 &mut self,
82 source: &Instance,
83 request: AuthenticationTokenRequest,
84 ) -> Result<UserAuthenticationToken, Error>;
85 }
86
87 #[async_trait::async_trait]
88 pub trait UserBackend: AuthBackend {
89 async fn get_value(&mut self, user: &User, name: &str) -> Result<AnyValue<User>, Error>;
90 async fn get_setting(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
91 async fn write_setting(
92 &mut self,
93 user: &User,
94 name: &str,
95 setting: &Value,
96 ) -> Result<(), Error>;
97 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
98 async fn repositories_for_user(
99 &mut self,
100 requester: Option<&User>,
101 user: &User,
102 ) -> Result<Vec<RepositorySummary>, Error>;
103 }
104
105 #[async_trait::async_trait]
106 pub trait MetadataBackend {
107 async fn user_get(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
108 async fn user_write(
109 &mut self,
110 user: &User,
111 name: &str,
112 setting: AnySetting,
113 ) -> Result<(), Error>;
114 async fn repository_get(
115 &mut self,
116 repository: &Repository,
117 name: &str,
118 ) -> Result<AnySetting, Error>;
119 async fn repository_write(
120 &mut self,
121 repository: &Repository,
122 name: &str,
123 setting: AnySetting,
124 ) -> Result<(), Error>;
125 }
126