diff --git a/.sqlx/query-5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2.json b/.sqlx/query-5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2.json new file mode 100644 index 0000000..dbceeba --- /dev/null +++ b/.sqlx/query-5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2.json @@ -0,0 +1,63 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT instance_url, username, name, description, visibility as \"visibility: _\", default_branch FROM repositories WHERE name = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "instance_url", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "visibility: _", + "type_info": { + "Custom": { + "name": "visibility", + "kind": { + "Enum": [ + "public", + "unlisted", + "private" + ] + } + } + } + }, + { + "ordinal": 5, + "name": "default_branch", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + false, + false + ] + }, + "hash": "5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2" +} diff --git a/.sqlx/query-d1acde0376963cada7e008d45c99e953b8f5540743e1a12ee919b74e24e752bd.json b/.sqlx/query-d1acde0376963cada7e008d45c99e953b8f5540743e1a12ee919b74e24e752bd.json deleted file mode 100644 index 31fb059..0000000 --- a/.sqlx/query-d1acde0376963cada7e008d45c99e953b8f5540743e1a12ee919b74e24e752bd.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT username, instance_url, name, description, visibility as \"visibility: _\", default_branch FROM repositories WHERE instance_url = $1 AND username = $2 AND name = $3", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "username", - "type_info": "Text" - }, - { - "ordinal": 1, - "name": "instance_url", - "type_info": "Text" - }, - { - "ordinal": 2, - "name": "name", - "type_info": "Text" - }, - { - "ordinal": 3, - "name": "description", - "type_info": "Text" - }, - { - "ordinal": 4, - "name": "visibility: _", - "type_info": { - "Custom": { - "name": "visibility", - "kind": { - "Enum": [ - "public", - "unlisted", - "private" - ] - } - } - } - }, - { - "ordinal": 5, - "name": "default_branch", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "Text", - "Text", - "Text" - ] - }, - "nullable": [ - false, - false, - false, - true, - false, - false - ] - }, - "hash": "d1acde0376963cada7e008d45c99e953b8f5540743e1a12ee919b74e24e752bd" -} diff --git a/src/authentication.rs b/src/authentication.rs index 7bcd358..47a0a11 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -112,8 +112,6 @@ impl AuthenticationTokenGranter { .await .unwrap(); - println!("Our Public Key:\n{}", server_public_key); - let verification_key = DecodingKey::from_rsa_pem(server_public_key.as_bytes()).unwrap(); let data: TokenData = decode( diff --git a/src/backend/git.rs b/src/backend/git.rs index 7575e40..6ca26ad 100644 --- a/src/backend/git.rs +++ b/src/backend/git.rs @@ -73,10 +73,11 @@ pub enum GitBackendError { FailedCreatingRepository(git2::Error), #[error("Failed inserting into the database")] FailedInsertingIntoDatabase(sqlx::Error), - #[error("Failed finding repository {instance_url:?}/{username:?}/{name:?}")] + #[error("")] + // #[error("Failed finding repository {instance_url:?}/{username:?}/{name:?}")] RepositoryNotFound { - instance_url: String, - username: String, + // instance_url: String, + // username: String, name: String, }, #[error("Repository {instance_url:?}/{username:?}/{name:?} already exists")] @@ -114,20 +115,20 @@ impl GitBackend { pub async fn find_by_instance_username_name( &self, - instance_url: &str, - username: &str, + // instance_url: &str, + // username: &str, repository_name: &str, ) -> Result { if let Ok(repository) = sqlx::query_as!(GitRepository, - r#"SELECT username, instance_url, name, description, visibility as "visibility: _", default_branch FROM repositories WHERE instance_url = $1 AND username = $2 AND name = $3"#, - instance_url, username, repository_name) + r#"SELECT instance_url, username, name, description, visibility as "visibility: _", default_branch FROM repositories WHERE name = $1"#, + /*instance_url, username,*/ repository_name) .fetch_one(&self.pg_pool.clone()) .await { Ok(repository) } else { Err(GitBackendError::RepositoryNotFound { - instance_url: instance_url.to_string(), - username: username.to_string(), + // instance_url: instance_url.to_string(), + // username: username.to_string(), name: repository_name.to_string(), }) } @@ -237,9 +238,9 @@ impl RepositoryBackend for GitBackend { // Check if repository already exists in the database if let Ok(_repository) = self .find_by_instance_username_name( - request.owner.instance.url.as_str(), - request.owner.username.as_str(), - request.name.as_str(), + // request.owner.instance.url.as_str(), + // request.owner.username.as_str(), + &request.name, ) .await { @@ -312,9 +313,9 @@ impl RepositoryBackend for GitBackend { ) -> Result> { let repository = match self .find_by_instance_username_name( - &request.owner.instance.url, - &request.owner.username, - &request.name, + // &request.owner.instance.url, + // &request.owner.username, + &request.repository.name, ) .await { @@ -322,16 +323,16 @@ impl RepositoryBackend for GitBackend { Err(err) => return Err(Box::new(err)), }; - if !repository.can_user_view_repository( - request.owner.instance.url.as_str(), - Some(request.owner.username.as_str()), - ) { - return Err(Box::new(GitBackendError::RepositoryNotFound { - instance_url: request.owner.instance.url.clone(), - username: request.owner.username.clone(), - name: request.name.clone(), - })); - } + // if !repository.can_user_view_repository( + // request.owner.instance.url.as_str(), + // Some(request.owner.username.as_str()), + // ) { + // return Err(Box::new(GitBackendError::RepositoryNotFound { + // instance_url: request.owner.instance.url.clone(), + // username: request.owner.username.clone(), + // name: request.name.clone(), + // })); + // } let git = match repository.open_git2_repository(&self.repository_folder) { Ok(git) => git, @@ -412,27 +413,27 @@ impl RepositoryBackend for GitBackend { let mut tree_entry = RepositoryTreeEntry::new(entry.name().unwrap(), object_type, entry.filemode()); - if request.extra_metadata { - // Get the file size if It's a blob - let object = entry.to_object(&git).unwrap(); - if let Some(blob) = object.as_blob() { - tree_entry.size = Some(blob.size()); - } - - // Could possibly be done better - let path = if let Some(path) = current_path.split_once('/') { - format!("{}/{}", path.1, entry.name().unwrap()) - } else { - entry.name().unwrap().to_string() - }; - - // Get the last commit made to the entry - if let Ok(last_commit) = - GitBackend::get_last_commit_of_file(&path, &git, commit) - { - tree_entry.last_commit = Some(last_commit); - } - } + // if request.extra_metadata { + // // Get the file size if It's a blob + // let object = entry.to_object(&git).unwrap(); + // if let Some(blob) = object.as_blob() { + // tree_entry.size = Some(blob.size()); + // } + + // // Could possibly be done better + // let path = if let Some(path) = current_path.split_once('/') { + // format!("{}/{}", path.1, entry.name().unwrap()) + // } else { + // entry.name().unwrap().to_string() + // }; + + // // Get the last commit made to the entry + // if let Ok(last_commit) = + // GitBackend::get_last_commit_of_file(&path, &git, commit) + // { + // tree_entry.last_commit = Some(last_commit); + // } + // } tree_entry }) diff --git a/src/connection.rs b/src/connection.rs index 0b307e2..96a09ca 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -94,7 +94,7 @@ pub async fn connection_worker( } }; - info!("Read payload: {}", std::str::from_utf8(&payload).unwrap()); + // info!("Read payload: {}", std::str::from_utf8(&payload).unwrap()); if let MessageKind::Handshake(handshake) = message { match handshake { diff --git a/src/main.rs b/src/main.rs index f691d42..3674cba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,11 @@ async fn main() -> Result<(), Box> { let repository_backend: Arc> = Arc::new(Mutex::new({ let foo: GitBackend = GitBackend { pg_pool: db_pool, - repository_folder: String::from("/tmp/foo"), + repository_folder: String::from( + config["repository"]["backend"]["git"]["root"] + .as_str() + .unwrap(), + ), }; foo })); diff --git a/src/messages/repository.rs b/src/messages/repository.rs index cd9f4c0..ac667e6 100644 --- a/src/messages/repository.rs +++ b/src/messages/repository.rs @@ -115,9 +115,7 @@ pub struct RepositoryIssue { #[derive(Clone, Serialize, Deserialize)] pub struct RepositoryInfoRequest { - pub name: String, - pub owner: User, + pub repository: Repository, pub rev: Option, pub path: Option, - pub extra_metadata: bool, }