Skip to content

Commit b0bd824

Browse files
Implement 'definitions import_into_vhost'
1 parent b8e8510 commit b0bd824

File tree

8 files changed

+131
-8
lines changed

8 files changed

+131
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
# rabbitmqadmin-ng Change Log
22

3-
## v0.24.0 (in development)
3+
## v0.25.0 (in development)
4+
5+
No (documented) changes yet.
6+
7+
8+
## v0.24.0 (Feb 8, 2025)
49

510
### Enhancements
611

712
* `definitions export_from_vhost` is a new command that exports definitions from a single virtual host
8-
instead of the entire cluster
13+
(as opposed to definitions for the entire cluster)
14+
15+
* `definitions import_into_vhost` is a new command that imports virtual host-specific definitions
16+
(as opposed to definitions for the entire cluster)
917

1018

1119
## v0.23.0 (Feb 2, 2025)

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ reqwest = { version = "0.12.12", features = [
1717
"__rustls",
1818
"rustls-tls-native-roots"
1919
]}
20-
rabbitmq_http_client = { version = "0.21.0", features = [
20+
rabbitmq_http_client = { version = "0.22.0", features = [
2121
"core",
2222
"blocking",
2323
"tabled"

src/commands.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,28 @@ pub fn import_definitions(client: APIClient, command_args: &ArgMatches) -> Clien
745745
}
746746
}
747747

748+
pub fn import_vhost_definitions(
749+
client: APIClient,
750+
vhost: &str,
751+
command_args: &ArgMatches,
752+
) -> ClientResult<()> {
753+
let file = command_args.get_one::<String>("file").unwrap();
754+
let definitions = fs::read_to_string(file);
755+
match definitions {
756+
Ok(defs) => {
757+
let defs_json = serde_json::from_str(defs.as_str()).unwrap_or_else(|err| {
758+
eprintln!("`{}` is not a valid JSON file: {}", file, err);
759+
process::exit(1)
760+
});
761+
client.import_vhost_definitions(vhost, defs_json)
762+
}
763+
Err(err) => {
764+
eprintln!("`{}` could not be read: {}", file, err);
765+
process::exit(1)
766+
}
767+
}
768+
}
769+
748770
pub fn publish_message(
749771
client: APIClient,
750772
vhost: &str,

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,14 @@ fn dispatch_common_subcommand(
505505
let result = commands::export_vhost_definitions(client, &vhost, second_level_args);
506506
res_handler.no_output_on_success(result);
507507
}
508-
509508
("definitions", "import") => {
510509
let result = commands::import_definitions(client, second_level_args);
511510
res_handler.no_output_on_success(result);
512511
}
512+
("definitions", "import_into_vhost") => {
513+
let result = commands::import_vhost_definitions(client, &vhost, second_level_args);
514+
res_handler.no_output_on_success(result);
515+
}
513516
("export", "definitions") => {
514517
let result = commands::export_cluster_wide_definitions(client, second_level_args);
515518
res_handler.no_output_on_success(result);

tests/definitions_import_tests.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,38 @@
1313
// limitations under the License.
1414

1515
mod test_helpers;
16+
use crate::test_helpers::delete_vhost;
1617
use test_helpers::run_succeeds;
18+
1719
#[test]
18-
fn test_import_definitions() -> Result<(), Box<dyn std::error::Error>> {
20+
fn test_import_cluster_definitions() -> Result<(), Box<dyn std::error::Error>> {
1921
run_succeeds([
2022
"definitions",
2123
"import",
2224
"--file",
23-
"tests/fixtures/definitions/definitions1.json",
25+
"tests/fixtures/definitions/cluster.definitions.1.json",
2426
]);
2527

2628
Ok(())
2729
}
30+
31+
#[test]
32+
fn test_import_vhost_definitions() -> Result<(), Box<dyn std::error::Error>> {
33+
let vh = "test_import_vhost_definitions.1";
34+
35+
delete_vhost(vh).expect("failed to delete a virtual host");
36+
run_succeeds(["declare", "vhost", "--name", vh]);
37+
38+
run_succeeds([
39+
"--vhost",
40+
vh,
41+
"definitions",
42+
"import_into_vhost",
43+
"--file",
44+
"tests/fixtures/definitions/vhost.definitions.1.json",
45+
]);
46+
47+
run_succeeds(["delete", "vhost", "--name", vh, "--idempotently"]);
48+
49+
Ok(())
50+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"rabbit_version": "4.0.5",
3+
"rabbitmq_version": "4.0.5",
4+
"product_name": "RabbitMQ",
5+
"product_version": "4.0.5",
6+
"rabbitmq_definition_format": "single_virtual_host",
7+
"original_vhost_name": "vh3",
8+
"explanation": "Definitions of virtual host 'vh3'",
9+
"metadata": {
10+
"description": "",
11+
"tags": [],
12+
"default_queue_type": "classic"
13+
},
14+
"description": "",
15+
"default_queue_type": "classic",
16+
"limits": {
17+
"max-connections": 9999
18+
},
19+
"parameters": [
20+
{
21+
"value": {
22+
"max-connections": 9999
23+
},
24+
"component": "vhost-limits",
25+
"name": "limits"
26+
}
27+
],
28+
"policies": [
29+
{
30+
"name": "cq.length.limit",
31+
"pattern": "^cq",
32+
"apply-to": "classic_queues",
33+
"definition": {
34+
"max-length": 9999
35+
},
36+
"priority": 0
37+
}
38+
],
39+
"queues": [
40+
{
41+
"name": "stream.1",
42+
"durable": true,
43+
"auto_delete": false,
44+
"arguments": {
45+
"x-queue-type": "stream"
46+
}
47+
},
48+
{
49+
"name": "qq.1",
50+
"durable": true,
51+
"auto_delete": false,
52+
"arguments": {
53+
"x-queue-type": "quorum"
54+
}
55+
},
56+
{
57+
"name": "cq.1",
58+
"durable": true,
59+
"auto_delete": false,
60+
"arguments": {
61+
"x-queue-type": "classic"
62+
}
63+
}
64+
],
65+
"exchanges": [],
66+
"bindings": []
67+
}

0 commit comments

Comments
 (0)