diff --git a/federate/federate-core/Cargo.toml b/federate/federate-core/Cargo.toml new file mode 100644 index 0000000..fdac303 --- /dev/null +++ b/federate/federate-core/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "federate-core" +version = "0.1.0" +authors = ["realaravinth "] +description = "ForgeFlux StarChart - Federated forge spider" +documentation = "https://forgeflux.org/" +edition = "2021" +license = "AGPLv3 or later version" + + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +async-trait = "0.1.51" +thiserror = "1.0.30" +serde = { version = "1", features = ["derive"]} +url = { version = "2.2.2", features = ["serde"] } + +[dependencies.db-core] +path = "../../db/db-core" + +[features] +default = [] +test = [] diff --git a/federate/federate-core/src/errors.rs b/federate/federate-core/src/errors.rs new file mode 100644 index 0000000..a02566e --- /dev/null +++ b/federate/federate-core/src/errors.rs @@ -0,0 +1,17 @@ +/* + * ForgeFlux StarChart - A federated software forge spider + * Copyright (C) 2022 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ diff --git a/federate/federate-core/src/lib.rs b/federate/federate-core/src/lib.rs new file mode 100644 index 0000000..67d8f2d --- /dev/null +++ b/federate/federate-core/src/lib.rs @@ -0,0 +1,68 @@ +/* + * ForgeFlux StarChart - A federated software forge spider + * Copyright (C) 2022 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +use std::path::Path; +use std::result::Result; + +use async_trait::async_trait; +use serde::Serialize; + +use db_core::prelude::*; + +#[cfg(feature = "test")] +pub mod tests; + +#[async_trait] +pub trait Federate: Sync + Send + Clone { + type Error: std::error::Error + std::fmt::Debug; + + /// utility method to create dir if not exists + async fn create_dir_if_not_exists(&self, path: &Path) -> Result<(), Self::Error>; + + /// utility method to write data + async fn write_util( + &self, + data: &S, + path: &Path, + ) -> Result<(), Self::Error>; + + /// utility method to remove file/dir + async fn rm_util(&self, path: &Path) -> Result<(), Self::Error>; + + /// create forge isntance + async fn create_forge_isntance(&self, f: &CreateForge<'_>) -> Result<(), Self::Error>; + + /// delete forge isntance + async fn delete_forge_instance(&self, hostname: &str) -> Result<(), Self::Error>; + + /// create user isntance + async fn create_user(&self, f: &AddUser<'_>) -> Result<(), Self::Error>; + + /// add repository isntance + async fn create_repository(&self, f: &AddRepository<'_>) -> Result<(), Self::Error>; + + /// delete user + async fn delete_user(&self, username: &str, hostname: &str) -> Result<(), Self::Error>; + + /// delete repository + async fn delete_repository( + &self, + owner: &str, + name: &str, + hostname: &str, + ) -> Result<(), Self::Error>; +} diff --git a/federate/federate-core/src/tests.rs b/federate/federate-core/src/tests.rs new file mode 100644 index 0000000..0455eb4 --- /dev/null +++ b/federate/federate-core/src/tests.rs @@ -0,0 +1,49 @@ +/* + * ForgeFlux StarChart - A federated software forge spider + * Copyright (C) 2022 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +//! Test utilities +use crate::*; + +/// adding forge works +pub async fn adding_forge_works<'a, T: Federate>( + ff: &T, + create_forge_msg: CreateForge<'a>, + create_user_msg: AddUser<'a>, + add_repo_msg: AddRepository<'a>, +) { + let _ = ff.delete_forge_instance(create_forge_msg.hostname).await; + ff.create_forge_isntance(&create_forge_msg).await.unwrap(); + // add user + ff.create_user(&create_user_msg).await.unwrap(); + + // add repository + ff.create_repository(&add_repo_msg).await.unwrap(); + // delete repository + ff.delete_repository(add_repo_msg.owner, add_repo_msg.name, add_repo_msg.hostname) + .await + .unwrap(); + + // delete user + ff.delete_user(create_user_msg.username, create_user_msg.hostname) + .await + .unwrap(); + + // delete user + ff.delete_forge_instance(create_forge_msg.hostname) + .await + .unwrap(); +}