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

ambee/giterated

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

Add authentication back into the operation states

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨97a26fd

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