WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ use crate::monitoring::{ list_features, monitor_identity_events, MonitorArgs, Mo
use crate::service::{ ServiceCommands, ServiceArgs, describe_service, list_services };
use crate::status::{ StatusArgs, status_command };
use crate::uninstall::uninstall;
use crate::policies::{ PoliciesCommands, PoliciesArgs, create_blocklist, check_blocklist };
use crate::policies::{
PoliciesCommands,
PoliciesArgs,
create_blocklist,
check_blocklist,
remove_ip,
};

use crate::essential::GeneralData;

Expand Down Expand Up @@ -164,7 +170,7 @@ async fn args_parser() -> Result<(), Error> {
// pass the ip as a monitoring flag
match policies_args.flags {
None => {
println!("Insert at least one ip to create a blocklist");
println!("{}","Insert at least one ip to create a blocklist".red());
Ok(())
}
Some(exclude_flag) => {
Expand All @@ -174,6 +180,19 @@ async fn args_parser() -> Result<(), Error> {
}
}
}
PoliciesCommands::RemoveIpFromBlocklist => {
match policies_args.flags {
None => {
println!("{}","Insert at least one ip to remove from the blocklist".red());
Ok(())
}
Some(ip) => {
println!("Inserted ip: {}", ip);
let _ = remove_ip(&ip).await;
Ok(())
}
}
}
}
}
None => {
Expand Down
34 changes: 34 additions & 0 deletions cli/src/policies.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(warnings)]
use std::result::Result::Ok;
use colored::Colorize;
use agent_api::requests::send_check_blocklist_request;
use agent_api::requests::send_create_blocklist_request;
use agent_api::requests::remove_ip_from_blocklist_request;
use anyhow::Error;
use clap::{ Args, Parser, Subcommand };
use agent_api::client::{ connect_to_client, connect_to_server_reflection };
Expand All @@ -13,6 +15,8 @@ pub enum PoliciesCommands {
CreateBlocklist,
#[command(name = "check-blocklist", about = "Check current ip blocklist")]
CheckBlocklist,
#[command(name="remove-ip",about ="Remove an ip from the blocklist")]
RemoveIpFromBlocklist
}

// cfcli policies <args>
Expand Down Expand Up @@ -87,3 +91,33 @@ pub async fn check_blocklist() -> Result<(), Error> {
}
Ok(())
}
pub async fn remove_ip(ip:&str) -> Result<(), Error> {
println!("{} {}", "=====>".blue().bold(), "Connecting to cortexflow Client".white());
match connect_to_client().await {
Ok(client) => {
println!("{} {}", "=====>".blue().bold(), "Connected to CortexFlow Client".green());
match remove_ip_from_blocklist_request(client,ip).await {
Ok(response) => {
println!("{:?}", response.into_inner().events);
}
Err(e) => {
println!(
"{} {} {} {}",
"=====>".blue().bold(),
"An error occured".red(),
"Error:",
e
);
}
}
}
Err(_) => {
println!(
"{} {}",
"=====>".blue().bold(),
"Failed to connect to CortexFlow Client".red()
);
}
}
Ok(())
}
123 changes: 3 additions & 120 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tracing-subscriber = "0.3.19"
tokio-stream = "0.1.17"
bytemuck = {version ="1.23.0"}
bytemuck_derive = "1.10.1"
cortexflow_identity = "0.1.1-beta.0"
cortexflow_identity = {path = "../src/components/identity"}
chrono = "0.4.42"

[build-dependencies]
Expand Down
17 changes: 15 additions & 2 deletions core/api/protos/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ message ActiveConnectionResponse{

//declare agent api
service Agent{
//active connections endpoint

// active connections endpoint
rpc ActiveConnections(RequestActiveConnections) returns (ActiveConnectionResponse);
//create blocklist endpoint

// create blocklist endpoint
rpc AddIpToBlocklist(AddIpToBlocklistRequest) returns (BlocklistResponse);
rpc CheckBlocklist(google.protobuf.Empty) returns (BlocklistResponse);

// remove ip from blocklist endpoint
rpc RmIpFromBlocklist(RmIpFromBlocklistRequest) returns (RmIpFromBlocklistResponse);

}

message AddIpToBlocklistRequest{
Expand All @@ -38,3 +44,10 @@ message BlocklistResponse{
string status = 1 ;
map<string,string> events = 2 ;
}
message RmIpFromBlocklistRequest{
string ip = 1 ;
}
message RmIpFromBlocklistResponse{
string status = 1;
map<string,string> events = 2 ;
}
Loading