Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Definition transformations WIP
Browse files Browse the repository at this point in the history
michaelklishin committed Sep 24, 2024
1 parent e4bc12a commit 40d6349
Showing 6 changed files with 56 additions and 4 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,7 +8,8 @@ clap = { version = "4.5", features = ["derive", "help", "color", "cargo"] }
url = "2"
thiserror = "1"
sysexits = "0.8.1"
rabbitmq_http_client = { git = "https://github.com/michaelklishin/rabbitmq-http-api-rs", features = ["core", "tabled"] }
# rabbitmq_http_client = { git = "https://github.com/michaelklishin/rabbitmq-http-api-rs", features = ["core", "tabled"] }
rabbitmq_http_client = { path = "/Users/antares/Development/RabbitMQ/rabbitmq-http-api-client-rs.git", features = ["core", "tabled"] }
serde = { version = "1.0", features = ["derive", "std"] }
serde_json = "1"
tabled = "0.16"
18 changes: 16 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -861,7 +861,7 @@ fn close_subcommands() -> [Command; 1] {
)]
}

fn definitions_subcommands() -> [Command; 2] {
fn definitions_subcommands() -> [Command; 3] {
let export_cmd = Command::new("export")
.about("export all definitions (queues, exchanges, bindings, users, etc)")
.after_long_help(color_print::cstr!(
@@ -885,7 +885,21 @@ fn definitions_subcommands() -> [Command; 2] {
.help("JSON file with definitions")
.required(true));

[export_cmd, import_cmd]
let transform_cmd = Command::new("transform")
.about("exports and transforms (post-processes) definitions")
.after_long_help(color_print::cstr!(
"<bold>Doc guide</bold>: https://rabbitmq.com/docs/definitions/"
)).arg(
Arg::new("file")
.long("file")
.help("JSON file with definitions")
.required(true))
.arg(Arg::new("transformations")
.required(true)
.long("transformations")
.help("command-separated names of transformations to apply"));

[export_cmd, import_cmd, transform_cmd]
}

fn export_subcommands() -> [Command; 1] {
13 changes: 13 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ use rabbitmq_http_client::commons::VirtualHostLimitTarget;
use std::fs;
use std::process;

use serde_json::json;

use rabbitmq_http_client::blocking::Client as APIClient;
use rabbitmq_http_client::blocking::Result as ClientResult;
use rabbitmq_http_client::requests::EnforcedLimitParams;
@@ -543,6 +545,17 @@ pub fn import_definitions(client: APIClient, command_args: &ArgMatches) -> Clien
}
}

pub fn transform_definitions(client: APIClient, command_args: &ArgMatches) -> ClientResult<()> {
let transformation_names = command_args.get_one::<String>("transformations").unwrap();
match client.export_definitions_as_data() {
Ok(definitions) => {
println!("Definitions: {:?}", json!(definitions));
Ok(())
}
Err(err) => Err(err),
}
}

pub fn publish_message(
client: APIClient,
vhost: &str,
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ use tabled::{Table, Tabled};
mod cli;
mod commands;
mod constants;
mod transformations;

use crate::cli::SharedFlags;
use crate::constants::DEFAULT_VHOST;
@@ -229,6 +230,10 @@ fn main() {
let result = commands::import_definitions(client, command_args);
print_nothing_or_fail(result);
}
("definitions", "transform") => {
let result = commands::transform_definitions(client, command_args);
print_nothing_or_fail(result);
}
("export", "definitions") => {
let result = commands::export_definitions(client, command_args);
print_nothing_or_fail(result);
20 changes: 20 additions & 0 deletions src/transformations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use rabbitmq_http_client::blocking::Error;
use rabbitmq_http_client::responses::DefinitionSet;

pub type Result<T> = std::result::Result<T, Error>;



pub trait Tranformation {
fn transform(&self: Self, &defs: &mut DefinitionSet) -> Result<&DefinitionSet>;
}

pub struct RemoveClassicQueueMirroringTransformation<'a> {
pub definition_set: &'a DefinitionSet
}

impl Tranformation for RemoveClassicQueueMirroringTransformation {
fn transform(defs: &mut DefinitionSet) -> Result<&DefinitionSet> {
todo!()
}
}

0 comments on commit 40d6349

Please sign in to comment.