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

ambee/giterated

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

Revert authentication payload change

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨16b4bc2

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨3825⁩ 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 messages::{
14 authentication::{
15 AuthenticationTokenRequest, AuthenticationTokenResponse, RegisterAccountRequest,
16 RegisterAccountResponse,
17 },
18 repository::{
19 RepositoryCreateRequest, RepositoryCreateResponse, RepositoryFileInspectRequest,
20 RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest,
21 RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest,
22 RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse,
23 },
24 user::{
25 UserBioRequest, UserBioResponse, UserDisplayImageRequest, UserDisplayImageResponse,
26 UserDisplayNameRequest, UserDisplayNameResponse,
27 },
28 },
29 model::{
30 instance::Instance,
31 repository::{Repository, RepositorySummary, RepositoryView},
32 user::User,
33 },
34 };
35
36 #[async_trait]
37 pub trait RepositoryBackend: IssuesBackend {
38 async fn create_repository(
39 &mut self,
40 user: &User,
41 request: &RepositoryCreateRequest,
42 ) -> Result<RepositoryCreateResponse, GitBackendError>;
43 async fn repository_info(
44 &mut self,
45 requester: Option<&User>,
46 request: &RepositoryInfoRequest,
47 ) -> Result<RepositoryView, Error>;
48 async fn repository_file_inspect(
49 &mut self,
50 requester: Option<&User>,
51 request: &RepositoryFileInspectRequest,
52 ) -> Result<RepositoryFileInspectionResponse, Error>;
53 async fn repositories_for_user(
54 &mut self,
55 requester: Option<&User>,
56 user: &User,
57 ) -> Result<Vec<RepositorySummary>, Error>;
58 }
59
60 pub trait IssuesBackend {
61 fn issues_count(
62 &mut self,
63 requester: Option<&User>,
64 request: &RepositoryIssuesCountRequest,
65 ) -> Result<RepositoryIssuesCountResponse, Error>;
66 fn issue_labels(
67 &mut self,
68 requester: Option<&User>,
69 request: &RepositoryIssueLabelsRequest,
70 ) -> Result<RepositoryIssueLabelsResponse, Error>;
71 fn issues(
72 &mut self,
73 requester: Option<&User>,
74 request: &RepositoryIssuesRequest,
75 ) -> Result<RepositoryIssuesResponse, Error>;
76 }
77
78 #[async_trait::async_trait]
79 pub trait AuthBackend {
80 async fn register(
81 &mut self,
82 request: RegisterAccountRequest,
83 ) -> Result<RegisterAccountResponse, Error>;
84
85 async fn login(
86 &mut self,
87 source: &Instance,
88 request: AuthenticationTokenRequest,
89 ) -> Result<AuthenticationTokenResponse, Error>;
90 }
91
92 #[async_trait::async_trait]
93 pub trait UserBackend: AuthBackend {
94 async fn display_name(
95 &mut self,
96 request: UserDisplayNameRequest,
97 ) -> Result<UserDisplayNameResponse, Error>;
98
99 async fn display_image(
100 &mut self,
101 request: UserDisplayImageRequest,
102 ) -> Result<UserDisplayImageResponse, Error>;
103
104 async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error>;
105 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
106 }
107
108 #[async_trait::async_trait]
109 pub trait SettingsBackend: Send + Sync {
110 async fn user_get(&mut self, user: &User) -> Result<Vec<(String, Value)>, Error>;
111 async fn user_write(&mut self, user: &User, settings: &[(String, String)])
112 -> Result<(), Error>;
113
114 async fn repository_get(
115 &mut self,
116 repository: &Repository,
117 ) -> Result<Vec<(String, Value)>, Error>;
118 async fn repository_write(
119 &mut self,
120 repository: &Repository,
121 settings: &[(String, String)],
122 ) -> Result<(), Error>;
123 }
124