Skip to content

Commit

Permalink
Merge pull request #28 from 0xBLCKLPTN/alice_database-dev
Browse files Browse the repository at this point in the history
Alice database dev
  • Loading branch information
0xBLCKLPTN authored Oct 25, 2024
2 parents 7cd5047 + f2ddf13 commit 5521237
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 337 deletions.
24 changes: 23 additions & 1 deletion Plugins/Alice-Database/src/engines.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
/* MIT License
Copyright (c) 2024 Daniil Ermolaev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */

use crate::json_engine::JSONEngine;

#[derive(Debug, Clone)]
pub enum Engines {
JSONEngine(JSONEngine),
}
}
119 changes: 119 additions & 0 deletions Plugins/Alice-Database/src/grpc_server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* MIT License
Copyright (c) 2024 Daniil Ermolaev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */

pub use tonic::{ transport::Server, Request, Response, Status };

pub mod grpc_proto {
tonic::include_proto!("instance");
}

pub use grpc_proto:: {
CreateInstanceRequest ,CreateInstanceResponse,
GetInstanceRequest ,GetInstanceResponse,
GetAllInstancesRequest ,GetAllInstancesResponse,
SignUpRequest ,SignUpResponse,
Token,
};

pub use grpc_proto::instance_service_server::InstanceServiceServer;
pub use grpc_proto::instance_service_server::InstanceService;


use crate::json_engine::*;
use crate::instance::InstanceManager;

use std::sync::{ Arc, Mutex };


#[derive(Debug, Default)]
pub struct GRPCInstanceManager {
pub instance_manager: Arc<Mutex<InstanceManager>>,
}

#[tonic::async_trait]
impl InstanceService for GRPCInstanceManager
{
async fn create_instance(
&self, request: Request<CreateInstanceRequest>,
) -> Result<Response<CreateInstanceResponse>, Status> {

let engine_type = request.into_inner().engine_type;
let mut im = self.instance_manager.lock().unwrap();
let id = im.create_instance(&engine_type);

Ok(
Response::new( CreateInstanceResponse { instance: id } )
)
}

async fn get_instance(
&self, request: Request<GetInstanceRequest>,
) -> Result<Response<GetInstanceResponse>, Status> {

let instance_name = request.into_inner().instance_name;
let im = self.instance_manager.lock().unwrap();

if let Some(instance) = im.get_instance(&instance_name) {
return Ok( Response::new(GetInstanceResponse { instance: instance.name.clone(), }));
}
Err( Status::not_found("Instance not found") )
}

async fn get_all_instances(
&self, request: Request<GetAllInstancesRequest>,
) -> Result<Response<GetAllInstancesResponse>, Status> {

let im = self.instance_manager.lock().unwrap();
let mut re_instances: Vec<grpc_proto::Instance> = vec![];

for instance in &im.instances {
re_instances.push(
grpc_proto::Instance {
name: instance.name.clone(),
engine: "not implemented".into(),
}
)
}
let response = GetAllInstancesResponse { instances: re_instances };
Ok( Response::new( response ))
}

async fn sign_up(
&self, request: Request<SignUpRequest>,
) -> Result<Response<SignUpResponse>, Status> {

let inner = request.into_inner();
let mut im = self.instance_manager.lock().unwrap();

let mut key: String = String::new();

if !im.authenticated_apps.contains_key(&inner.app_name) {
key = im.sign_up(inner.app_name);
} else {
key = "whoops...".to_string();
}
let response = SignUpResponse { secret_key: key };
im.get_all_apps();
Ok( Response::new(response) )
}
}

24 changes: 23 additions & 1 deletion Plugins/Alice-Database/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/* MIT License
Copyright (c) 2024 Daniil Ermolaev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */

use crate::Engines;
use uuid::Uuid;
use std::path::PathBuf;
Expand Down Expand Up @@ -67,4 +89,4 @@ impl InstanceManager {
pub fn get_all_apps(&self) {
println!("{:#?}", self.authenticated_apps);
}
}
}
22 changes: 22 additions & 0 deletions Plugins/Alice-Database/src/json_engine.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/* MIT License
Copyright (c) 2024 Daniil Ermolaev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */

use std::fs;
use std::io::{self, Read, Write};
use std::env;
Expand Down
23 changes: 23 additions & 0 deletions Plugins/Alice-Database/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/* MIT License
Copyright (c) 2024 Daniil Ermolaev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */


use std::fs;
use std::io::{self, Read, Write};
use std::path::{PathBuf, Path};
Expand Down
Loading

0 comments on commit 5521237

Please sign in to comment.