Showing 8 changed files with 38 insertions and 35 deletions
giterated-daemon/src/connection/forwarded.rs
@@ -1,13 +1,13 @@ | ||
1 | 1 | use futures_util::{SinkExt, StreamExt}; |
2 | 2 | use giterated_api::DaemonConnectionPool; |
3 | use giterated_models::{messages::error::ConnectionError, model::authenticated::{Authenticated, AuthenticatedPayload}}; | |
3 | use giterated_models::{ | |
4 | messages::error::ConnectionError, | |
5 | model::authenticated::{Authenticated, AuthenticatedPayload}, | |
6 | }; | |
4 | 7 | use serde::Serialize; |
5 | 8 | use tokio_tungstenite::tungstenite::Message; |
6 | 9 | |
7 | pub async fn wrap_forwarded( | |
8 | pool: &DaemonConnectionPool, | |
9 | message: AuthenticatedPayload, | |
10 | ) -> Message { | |
10 | pub async fn wrap_forwarded(pool: &DaemonConnectionPool, message: AuthenticatedPayload) -> Message { | |
11 | 11 | let connection = pool.get().await; |
12 | 12 | |
13 | 13 | let mut connection = match connection { |
giterated-daemon/src/connection/handshake.rs
@@ -8,7 +8,7 @@ use semver::Version; | ||
8 | 8 | |
9 | 9 | use crate::{ |
10 | 10 | connection::ConnectionError, |
11 | message::{Message, MessageHandler, NetworkMessage, State, HandshakeMessage}, | |
11 | message::{HandshakeMessage, Message, MessageHandler, NetworkMessage, State}, | |
12 | 12 | validate_version, version, |
13 | 13 | }; |
14 | 14 |
giterated-daemon/src/connection/wrapper.rs
@@ -11,7 +11,10 @@ use anyhow::Error; | ||
11 | 11 | use futures_util::{SinkExt, StreamExt}; |
12 | 12 | use giterated_models::{ |
13 | 13 | messages::error::ConnectionError, |
14 | model::{authenticated::{Authenticated, AuthenticatedPayload}, instance::Instance}, | |
14 | model::{ | |
15 | authenticated::{Authenticated, AuthenticatedPayload}, | |
16 | instance::Instance, | |
17 | }, | |
15 | 18 | }; |
16 | 19 | use rsa::RsaPublicKey; |
17 | 20 | use serde::Serialize; |
giterated-daemon/src/message.rs
@@ -3,7 +3,7 @@ use std::{collections::HashMap, ops::Deref}; | ||
3 | 3 | use anyhow::Error; |
4 | 4 | use futures_util::Future; |
5 | 5 | use giterated_models::model::{ |
6 | authenticated::{Authenticated, AuthenticationSource, UserTokenMetadata, AuthenticatedPayload}, | |
6 | authenticated::{Authenticated, AuthenticatedPayload, AuthenticationSource, UserTokenMetadata}, | |
7 | 7 | instance::Instance, |
8 | 8 | user::User, |
9 | 9 | }; |
@@ -110,7 +110,7 @@ impl FromMessage<ConnectionState> for AuthenticatedInstance { | ||
110 | 110 | ) -> Result<Self, Error> { |
111 | 111 | let message: AuthenticatedPayload = |
112 | 112 | serde_json::from_slice(&network_message).map_err(|e| Error::from(e))?; |
113 | ||
113 | ||
114 | 114 | let (instance, signature) = message |
115 | 115 | .source |
116 | 116 | .iter() |
@@ -261,7 +261,7 @@ async fn public_key(instance: &Instance) -> Result<String, Error> { | ||
261 | 261 | } |
262 | 262 | |
263 | 263 | /// Handshake-specific message type. |
264 | /// | |
264 | /// | |
265 | 265 | /// Uses basic serde_json-based deserialization to maintain the highest |
266 | 266 | /// level of compatibility across versions. |
267 | 267 | pub struct HandshakeMessage<T: Serialize + DeserializeOwned>(pub T); |
@@ -275,4 +275,4 @@ where | ||
275 | 275 | async fn from_message(message: &NetworkMessage, _: &S) -> Result<Self, Error> { |
276 | 276 | Ok(HandshakeMessage(serde_json::from_slice(&message.0)?)) |
277 | 277 | } |
278 | } | |
278 | \ No newline at end of file | |
278 | } |
giterated-models/src/messages/authentication.rs
@@ -7,7 +7,7 @@ use crate::model::authenticated::UserAuthenticationToken; | ||
7 | 7 | /// # Authentication |
8 | 8 | /// - Instance Authentication |
9 | 9 | /// - **ONLY ACCEPTED WHEN SAME-INSTANCE** |
10 | #[derive(Clone, Serialize, Deserialize)] | |
10 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
11 | 11 | pub struct RegisterAccountRequest { |
12 | 12 | pub username: String, |
13 | 13 | pub email: Option<String>, |
@@ -30,13 +30,13 @@ pub struct RegisterAccountResponse { | ||
30 | 30 | /// - Credentials ([`crate::backend::AuthBackend`]-based) |
31 | 31 | /// - Identifies the User account to issue a token for |
32 | 32 | /// - Decrypts user private key to issue to |
33 | #[derive(Clone, Serialize, Deserialize)] | |
33 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
34 | 34 | pub struct AuthenticationTokenRequest { |
35 | 35 | pub username: String, |
36 | 36 | pub password: String, |
37 | 37 | } |
38 | 38 | |
39 | #[derive(Clone, Serialize, Deserialize)] | |
39 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
40 | 40 | pub struct AuthenticationTokenResponse { |
41 | 41 | pub token: UserAuthenticationToken, |
42 | 42 | } |
@@ -51,12 +51,12 @@ pub struct AuthenticationTokenResponse { | ||
51 | 51 | /// # Authorization |
52 | 52 | /// - Token-based |
53 | 53 | /// - Validates authorization using token's authenticity |
54 | #[derive(Clone, Serialize, Deserialize)] | |
54 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
55 | 55 | pub struct TokenExtensionRequest { |
56 | 56 | pub token: UserAuthenticationToken, |
57 | 57 | } |
58 | 58 | |
59 | #[derive(Clone, Serialize, Deserialize)] | |
59 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
60 | 60 | pub struct TokenExtensionResponse { |
61 | 61 | pub new_token: Option<String>, |
62 | 62 | } |
giterated-models/src/messages/handshake.rs
@@ -4,19 +4,19 @@ use serde::{Deserialize, Serialize}; | ||
4 | 4 | use crate::model::instance::Instance; |
5 | 5 | |
6 | 6 | /// Sent by the initiator of a new inter-daemon connection. |
7 | #[derive(Clone, Serialize, Deserialize)] | |
7 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
8 | 8 | pub struct InitiateHandshake { |
9 | 9 | pub version: Version, |
10 | 10 | } |
11 | 11 | |
12 | 12 | /// Sent in response to [`InitiateHandshake`] |
13 | #[derive(Clone, Serialize, Deserialize)] | |
13 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
14 | 14 | pub struct HandshakeResponse { |
15 | 15 | pub identity: Instance, |
16 | 16 | pub version: Version, |
17 | 17 | } |
18 | 18 | |
19 | #[derive(Clone, Serialize, Deserialize)] | |
19 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
20 | 20 | pub struct HandshakeFinalize { |
21 | 21 | pub success: bool, |
22 | 22 | } |
giterated-models/src/messages/issues.rs
@@ -2,17 +2,17 @@ use serde::{Deserialize, Serialize}; | ||
2 | 2 | |
3 | 3 | use crate::model::repository::Repository; |
4 | 4 | |
5 | #[derive(Clone)] | |
5 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
6 | 6 | pub struct IssuesCountCommand { |
7 | 7 | pub respository: Repository, |
8 | 8 | } |
9 | 9 | |
10 | #[derive(Clone, Serialize, Deserialize)] | |
10 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
11 | 11 | pub struct IssuesCountResponse { |
12 | 12 | pub count: u64, |
13 | 13 | } |
14 | 14 | |
15 | #[derive(Clone)] | |
15 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
16 | 16 | pub struct IssuesLabelsCommand { |
17 | 17 | pub repository: Repository, |
18 | 18 | } |
giterated-models/src/messages/repository.rs
@@ -19,7 +19,7 @@ use crate::model::{ | ||
19 | 19 | /// - Used to authorize action using User token requiring a correct `issued_for` and valid issuance from user's instance |
20 | 20 | /// - User Authorization |
21 | 21 | /// - Potential User permissions checks |
22 | #[derive(Clone, Serialize, Deserialize)] | |
22 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
23 | 23 | pub struct RepositoryCreateRequest { |
24 | 24 | pub name: String, |
25 | 25 | pub description: Option<String>, |
@@ -28,7 +28,7 @@ pub struct RepositoryCreateRequest { | ||
28 | 28 | pub owner: User, |
29 | 29 | } |
30 | 30 | |
31 | #[derive(Clone, Serialize, Deserialize)] | |
31 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
32 | 32 | pub struct RepositoryCreateResponse; |
33 | 33 | |
34 | 34 | /// A request to inspect the tree of a repository. |
@@ -40,12 +40,12 @@ pub struct RepositoryCreateResponse; | ||
40 | 40 | /// # Authorization |
41 | 41 | /// - User Authorization |
42 | 42 | /// - Potential User permissions checks |
43 | #[derive(Clone, Serialize, Deserialize)] | |
43 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
44 | 44 | pub struct RepositoryFileInspectRequest { |
45 | 45 | pub path: RepositoryTreeEntry, |
46 | 46 | } |
47 | 47 | |
48 | #[derive(Clone, Serialize, Deserialize)] | |
48 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
49 | 49 | pub enum RepositoryFileInspectionResponse { |
50 | 50 | File { |
51 | 51 | commit_metadata: Commit, |
@@ -68,10 +68,10 @@ pub enum RepositoryFileInspectionResponse { | ||
68 | 68 | /// # Authorization |
69 | 69 | /// - User Authorization |
70 | 70 | /// - Potential User permissions checks |
71 | #[derive(Clone, Serialize, Deserialize)] | |
71 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
72 | 72 | pub struct RepositoryIssuesCountRequest; |
73 | 73 | |
74 | #[derive(Clone, Serialize, Deserialize)] | |
74 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
75 | 75 | pub struct RepositoryIssuesCountResponse { |
76 | 76 | pub count: u64, |
77 | 77 | } |
@@ -85,15 +85,15 @@ pub struct RepositoryIssuesCountResponse { | ||
85 | 85 | /// # Authorization |
86 | 86 | /// - User Authorization |
87 | 87 | /// - Potential User permissions checks |
88 | #[derive(Clone, Serialize, Deserialize)] | |
88 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
89 | 89 | pub struct RepositoryIssueLabelsRequest; |
90 | 90 | |
91 | #[derive(Clone, Serialize, Deserialize)] | |
91 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
92 | 92 | pub struct RepositoryIssueLabelsResponse { |
93 | 93 | pub labels: Vec<IssueLabel>, |
94 | 94 | } |
95 | 95 | |
96 | #[derive(Clone, Serialize, Deserialize)] | |
96 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
97 | 97 | pub struct IssueLabel { |
98 | 98 | pub name: String, |
99 | 99 | pub color: String, |
@@ -108,10 +108,10 @@ pub struct IssueLabel { | ||
108 | 108 | /// # Authorization |
109 | 109 | /// - User Authorization |
110 | 110 | /// - Potential User permissions checks |
111 | #[derive(Clone, Serialize, Deserialize)] | |
111 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
112 | 112 | pub struct RepositoryIssuesRequest; |
113 | 113 | |
114 | #[derive(Clone, Serialize, Deserialize)] | |
114 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
115 | 115 | pub struct RepositoryIssuesResponse { |
116 | 116 | pub issues: Vec<RepositoryIssue>, |
117 | 117 | } |
@@ -125,7 +125,7 @@ pub struct RepositoryIssuesResponse { | ||
125 | 125 | /// # Authorization |
126 | 126 | /// - User Authorization |
127 | 127 | /// - Potential User permissions checks |
128 | #[derive(Clone, Serialize, Deserialize)] | |
128 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
129 | 129 | pub struct RepositoryIssue { |
130 | 130 | pub author: User, |
131 | 131 | pub id: u64, |
@@ -134,7 +134,7 @@ pub struct RepositoryIssue { | ||
134 | 134 | pub labels: Vec<IssueLabel>, |
135 | 135 | } |
136 | 136 | |
137 | #[derive(Clone, Serialize, Deserialize)] | |
137 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
138 | 138 | pub struct RepositoryInfoRequest { |
139 | 139 | pub repository: Repository, |
140 | 140 | /// Whether to fetch extra metadata like the last commit made to file or size |