Skip to content

Commit

Permalink
Merge pull request #61 from itsparser/v3
Browse files Browse the repository at this point in the history
🪶  -  Added Storage support for the Application
  • Loading branch information
itsparser authored Mar 16, 2024
2 parents 924e56f + 7e7bae6 commit e9e9536
Show file tree
Hide file tree
Showing 179 changed files with 32,215 additions and 306 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,29 @@
## Ignore File for backend service
.cargo/config.toml

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
**/node_modules
**/.pnp
**.pnp.js

# testing
**/coverage

# production
**/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
**.vscode


5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ members=[
"crates/libs/entity",
"crates/libs/migration",
"crates/services/engine",
"crates/services/api", "crates/workshop/webdriver",
"crates/services/api", "crates/workshop/webdriver", "crates/workshop/chrome",
"crates/macro/entity-macro",
]

[workspace.package]
Expand All @@ -27,6 +28,8 @@ entity = { path = "crates/libs/entity", default-features = true }
migration = { path = "crates/libs/migration", default-features = true }
engine = { path = "crates/services/engine", default-features = true }
api = { path = "crates/services/api", default-features = true }
chrome = { path = "crates/workshop/chrome", default-features = true }
entity_macro = { path = "crates/macro/entity-macro", default-features = true }

thiserror = "1.0.31"
jsonwebtoken = "9.2.0"
Expand Down
8 changes: 0 additions & 8 deletions config/default.toml

This file was deleted.

Empty file removed config/development.toml
Empty file.
5 changes: 5 additions & 0 deletions crates/libs/cerium/src/client/driver/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl WebDriver {
/// fn main() -> CeriumResult<()> {
/// let _driver = WD::default();
/// let driver = WebDriver::new(_driver)?;
/// Ok(())
/// }
/// ```
///
Expand All @@ -29,6 +30,10 @@ impl WebDriver {
let helper = WebDriver { driver };
Ok(helper)
}

pub async fn session_id(&self) -> CeriumResult<String> {
Ok(self.driver.session_id().await?.clone().to_string())
}

pub async fn default() -> CeriumResult<Self> {
let mut caps = DesiredCapabilities::firefox();
Expand Down
168 changes: 55 additions & 113 deletions crates/libs/cerium/src/client/storage/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,151 +8,93 @@ use crate::error::CeriumResult;
#[derive(Debug, Clone)]
pub struct S3Client {
credentials: Credentials,
region: Region
region: Region,
}


/// S3Client represents a client for interacting with Amazon S3 storage.
impl S3Client {
/// Creates a new S3Client instance.
///
/// # Arguments
///
/// * `access_key` - The access key for authenticating with Amazon S3.
/// * `secret_key` - The secret key for authenticating with Amazon S3.
/// * `base_url` - The base URL for the Amazon S3 endpoint.
///
/// # Returns
///
/// A CeriumResult containing the new S3Client instance if successful, or an error if the creation fails.
pub fn new(access_key: &str, secret_key: &str, base_url: &str) -> CeriumResult<Self> {
let region = Region::Custom { region: "orca".to_string(), endpoint: base_url.to_string() };
let region = Region::Custom {
region: "orca".to_string(),
endpoint: base_url.to_string(),
};

let credentials = Credentials::new(Some(access_key), Some(secret_key), None, None, None)?;

Ok(Self {
credentials,
region
region,
})


// let response_data = bucket.put_object(format!("{id}.png").as_str(), content.as_slice()).await.expect("Got error");
//
// let base_url = base_url.parse::<BaseUrl>()?;
// let static_provider = StaticProvider::new(access_key, secret_key, None);
// let client = Client::new(base_url.clone(), Some(Box::new(static_provider)), None, None)?;
// Ok(Self {
// client,
// })
}

/// Get Bucket will return the Bucket object for the Any bucket based action
/// Get Bucket will return the Bucket object for the Any bucket based action.
///
/// # Arguments
///
/// * `bucket_name` - The name of the bucket.
///
/// # Returns
///
/// A CeriumResult containing the Bucket object if successful, or an error if the retrieval fails.
pub fn get_bucket(&self, bucket_name: &str) -> CeriumResult<Bucket> {
let mut bucket = Bucket::new(bucket_name, self.region.clone(), self.credentials.clone())?;
bucket.set_path_style();
Ok(bucket)
}

/// Asynchronously lists the buckets.
///
/// # Returns
///
/// A CeriumResult indicating success or failure.
pub async fn list_bucket(&self) -> CeriumResult<()> {
// let _bucket_obj = self.get_bucket(bucket)?
// let buckets =self.client.list_buckets(&args).await?;
Ok(())
}

/// Asynchronously creates a new object in the specified bucket.
///
/// # Arguments
///
/// * `bucket` - The name of the bucket.
/// * `key` - The key of the object.
/// * `data` - The data of the object.
///
/// # Returns
///
/// A CeriumResult indicating success or failure.
pub async fn create(&self, bucket: &str, key: &str, data: &[u8]) -> CeriumResult<()> {
let _bucket_obj = self.get_bucket(bucket)?;
let result = _bucket_obj.put_object(key, data).await?;
let result = _bucket_obj.put_object(key, data).await?;
Ok(())
}

/// Asynchronously deletes an object from the specified bucket.
///
/// # Arguments
///
/// * `bucket` - The name of the bucket.
/// * `key` - The key of the object.
///
/// # Returns
///
/// A CeriumResult indicating success or failure.
pub async fn delete(&self, bucket: &String, key: &String) -> CeriumResult<()> {
let _bucket_obj = self.get_bucket(bucket)?;
let response = _bucket_obj.delete_object(key).await?;
let response = _bucket_obj.delete_object(key).await?;
info!("Deleted Object for {key} - Response {:?}", response);
Ok(())
}

}
//
// #[cfg(test)]
// mod tests {
// use crate::client::storage::s3::S3Client;
//
// // S3Client can be created with valid access_key, secret_key, and base_url
// #[tokio::test]
// async fn test_s3client_creation_with_valid_credentials() {
// let access_key = "minioadmin";
// let secret_key = "minioadmin";
// let base_url = "http://localhost:9000";
//
// let result = S3Client::new(access_key, secret_key, base_url);
//
//
// assert!(result.is_ok());
// // let r = result.unwrap().list_bucket().await;
// let r = result.unwrap().create("orca", "id.png", "jj").await;
// assert!(r.is_ok());
// }
//
// // S3Client can delete an object from a bucket with a valid key
// #[tokio::test]
// async fn test_s3client_delete_object_with_valid_key() {
// let access_key = "valid_access_key";
// let secret_key = "valid_secret_key";
// let base_url = "valid_base_url";
// let bucket = String::from("valid_bucket");
// let key = String::from("valid_key");
//
// let s3_client = S3Client::new(access_key, secret_key, base_url).unwrap();
// let result = s3_client.delete(&bucket, &key).await;
//
// assert!(result.is_ok());
// }
//
// // S3Client cannot be created with invalid access_key, secret_key, or base_url
// #[test]
// fn test_s3client_creation_with_invalid_credentials() {
// let access_key = "invalid_access_key";
// let secret_key = "invalid_secret_key";
// let base_url = "invalid_base_url";
//
// let result = S3Client::new(access_key, secret_key, base_url);
//
// assert!(result.is_err());
// }
//
// // S3Client cannot delete an object from a non-existent bucket
// #[tokio::test]
// async fn test_s3client_delete_object_from_nonexistent_bucket() {
// let access_key = "valid_access_key";
// let secret_key = "valid_secret_key";
// let base_url = "valid_base_url";
// let bucket = String::from("nonexistent_bucket");
// let key = String::from("valid_key");
//
// let s3_client = S3Client::new(access_key, secret_key, base_url).unwrap();
// let result = s3_client.delete(&bucket, &key).await;
//
// assert!(result.is_err());
// }
//
// // S3Client cannot delete a non-existent object from a bucket
// #[tokio::test]
// async fn test_s3client_delete_nonexistent_object_from_bucket() {
// let access_key = "valid_access_key";
// let secret_key = "valid_secret_key";
// let base_url = "valid_base_url";
// let bucket = String::from("valid_bucket");
// let key = String::from("nonexistent_key");
//
// let s3_client = S3Client::new(access_key, secret_key, base_url).unwrap();
// let result = s3_client.delete(&bucket, &key).await;
//
// assert!(result.is_err());
// }
//
// // S3Client can handle errors returned by the S3 service
// #[tokio::test]
// async fn test_s3client_handle_s3_service_errors() {
// let access_key = "valid_access_key";
// let secret_key = "valid_secret_key";
// let base_url = "valid_base_url";
// let bucket = String::from("valid_bucket");
// let key = String::from("valid_key");
//
// let s3_client = S3Client::new(access_key, secret_key, base_url).unwrap();
// let result = s3_client.delete(&bucket, &key).await;
//
// assert!(result.is_err());
// }
//
//
// }
2 changes: 1 addition & 1 deletion crates/libs/cerium/src/server/request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing::info;
pub struct OrcaRequestId;

impl MakeRequestId for OrcaRequestId {
fn make_request_id<B>(&mut self, request: &axum::http::Request<B>) -> Option<RequestId> {
fn make_request_id<B>(&mut self, _request: &axum::http::Request<B>) -> Option<RequestId> {
let id = Uuid::new_v4();
info!("Request ID - {:?}", id);
Some(RequestId::new(id.to_string().parse().unwrap()))
Expand Down
3 changes: 2 additions & 1 deletion crates/libs/entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ serde.workspace = true
serde_json.workspace = true
sea-orm.workspace=true
sea-query.workspace=true
chrono.workspace=true
chrono.workspace=true
entity_macro.workspace = true
22 changes: 22 additions & 0 deletions crates/libs/entity/src/account/accounts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.6.0
use sea_orm::entity::prelude::*;
use sea_orm::EntityTrait;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "account")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Uuid,
pub name: String,
pub domain: String,
pub email: String,
pub owner: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
1 change: 1 addition & 0 deletions crates/libs/entity/src/account/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod accounts;
Loading

0 comments on commit e9e9536

Please sign in to comment.