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

ambee/giterated

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

Fix rev

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨088af7f

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨4437⁩ 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 Commit, IssueLabel, Repository, RepositoryCommitBeforeRequest, RepositoryDiff,
20 RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest,
21 RepositoryFileInspectRequest, RepositoryIssue, RepositoryIssueLabelsRequest,
22 RepositoryIssuesCountRequest, RepositoryIssuesRequest, RepositorySummary, RepositoryTreeEntry,
23 };
24 use giterated_models::settings::AnySetting;
25 use giterated_models::user::User;
26 use giterated_models::value::AnyValue;
27
28 #[async_trait]
29 pub trait RepositoryBackend {
30 async fn create_repository(
31 &mut self,
32 user: &User,
33 request: &RepositoryCreateRequest,
34 ) -> Result<Repository, GitBackendError>;
35 async fn repository_file_inspect(
36 &mut self,
37 requester: Option<&User>,
38 repository: &Repository,
39 request: &RepositoryFileInspectRequest,
40 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
41 async fn repository_file_from_id(
42 &mut self,
43 requester: Option<&User>,
44 repository: &Repository,
45 request: &RepositoryFileFromIdRequest,
46 ) -> Result<RepositoryFile, Error>;
47 async fn repository_diff(
48 &mut self,
49 requester: Option<&User>,
50 repository: &Repository,
51 request: &RepositoryDiffRequest,
52 ) -> Result<RepositoryDiff, Error>;
53 async fn repository_commit_before(
54 &mut self,
55 requester: Option<&User>,
56 repository: &Repository,
57 request: &RepositoryCommitBeforeRequest,
58 ) -> Result<Commit, Error>;
59 async fn get_value(
60 &mut self,
61 user: &Repository,
62 name: &str,
63 ) -> Result<AnyValue<Repository>, Error>;
64 async fn get_setting(&mut self, user: &Repository, name: &str) -> Result<AnySetting, Error>;
65 async fn write_setting(
66 &mut self,
67 user: &Repository,
68 name: &str,
69 setting: &Value,
70 ) -> Result<(), Error>;
71 async fn exists(&mut self, repository: &Repository) -> Result<bool, Error>;
72 }
73
74 pub trait IssuesBackend {
75 fn issues_count(
76 &mut self,
77 requester: Option<&User>,
78 request: &RepositoryIssuesCountRequest,
79 ) -> Result<u64, Error>;
80 fn issue_labels(
81 &mut self,
82 requester: Option<&User>,
83 request: &RepositoryIssueLabelsRequest,
84 ) -> Result<Vec<IssueLabel>, Error>;
85 fn issues(
86 &mut self,
87 requester: Option<&User>,
88 request: &RepositoryIssuesRequest,
89 ) -> Result<Vec<RepositoryIssue>, Error>;
90 }
91
92 #[async_trait::async_trait]
93 pub trait AuthBackend {
94 async fn register(
95 &mut self,
96 request: RegisterAccountRequest,
97 ) -> Result<UserAuthenticationToken, Error>;
98
99 async fn login(
100 &mut self,
101 source: &Instance,
102 request: AuthenticationTokenRequest,
103 ) -> Result<UserAuthenticationToken, Error>;
104 }
105
106 #[async_trait::async_trait]
107 pub trait UserBackend: AuthBackend {
108 async fn get_value(&mut self, user: &User, name: &str) -> Result<AnyValue<User>, Error>;
109 async fn get_setting(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
110 async fn write_setting(
111 &mut self,
112 user: &User,
113 name: &str,
114 setting: &Value,
115 ) -> Result<(), Error>;
116 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
117 async fn repositories_for_user(
118 &mut self,
119 requester: Option<&User>,
120 user: &User,
121 ) -> Result<Vec<RepositorySummary>, Error>;
122 }
123
124 #[async_trait::async_trait]
125 pub trait MetadataBackend {
126 async fn user_get(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
127 async fn user_write(
128 &mut self,
129 user: &User,
130 name: &str,
131 setting: AnySetting,
132 ) -> Result<(), Error>;
133 async fn repository_get(
134 &mut self,
135 repository: &Repository,
136 name: &str,
137 ) -> Result<AnySetting, Error>;
138 async fn repository_write(
139 &mut self,
140 repository: &Repository,
141 name: &str,
142 setting: AnySetting,
143 ) -> Result<(), Error>;
144 }
145