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

ambee/giterated

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

Base protocol refactor complete

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨079d544

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