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

ambee/giterated

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

Giterated Stack `ObjectValue` and `Setting` refactor.

This refactor adds value and setting update events, as well as value getters. Additionally, the stack is now the owner of the ability to write settings into storage. This is accomplished with the `MetadataProvider` trait. This sets up the ground work for push federation, cache, and basically everything else. commit 7befc583cb3e0c6719506c550ed66ac76293413c Author: Amber <[email protected]> Date: Fri Sep 29 15:46:48 2023 -0500 Finish value and settings refactor in the stack. commit 3ac09994a0caafd1a0b95d9a781c7f202f20e75b Author: Amber <[email protected]> Date: Fri Sep 29 09:46:32 2023 -0500 Add set_setting handling back in commit 84fd31e3eae85d98fa68a28b333dbb32cde3bdb8 Author: Amber <[email protected]> Date: Wed Sep 27 06:36:31 2023 -0500 Remove some allocations from meta types commit 16c310ce3680c4a14ed35083b6a230aaecd43152 Author: Amber <[email protected]> Date: Wed Sep 27 05:35:03 2023 -0500 Add cargo metadata commit eb2520a20001bac7b21c6c3d34f62db32f0ada80 Author: Amber <[email protected]> Date: Wed Sep 27 05:26:27 2023 -0500 Refactor setting and value management to use the unified stack. Allows for tight management, inspection, and eventing of setting and value management. commit 901fe103da0fce4b40f33b0a8b64404049ae03cf Author: Amber <[email protected]> Date: Wed Sep 27 02:38:33 2023 -0500 Set up ground work for value / settings refactor

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨c377e4d

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