Skip to content

Commit 5cd6f43

Browse files
New command group: operator_policies
1 parent 8d35a1f commit 5cd6f43

File tree

5 files changed

+962
-0
lines changed

5 files changed

+962
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* `connections` is a new command group for operations on connections
88
* `channels` is a new command group for operations on channels
9+
* `operator_policies` is a new command group for working with operator policies.
10+
It matches the `policies` group but acts on [operator policies](https://www.rabbitmq.com/docs/policies#operator-policies)
911
* `policies set` and `policies update` are two new aliases for `policies declare`. The former follows the naming
1012
used by `rabbitmqctl` and the latter reflects the fact that the command can be used to update an existing policy,
1113
in particular, to override its definition

src/cli.rs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ pub fn parser(pre_flight_settings: PreFlightSettings) -> Command {
190190
.infer_subcommands(pre_flight_settings.infer_subcommands)
191191
.infer_long_args(pre_flight_settings.infer_long_options)
192192
.subcommands(nodes_subcommands(pre_flight_settings.clone()));
193+
let operator_policies_group = Command::new("operator_policies")
194+
.about("Operations on operator policies")
195+
.infer_subcommands(pre_flight_settings.infer_subcommands)
196+
.infer_long_args(pre_flight_settings.infer_long_options)
197+
.after_help(color_print::cformat!(
198+
"<bold>Doc guide</bold>: {}",
199+
POLICY_GUIDE_URL
200+
))
201+
.subcommand_value_name("operator policy")
202+
.subcommands(operator_policies_subcommands(pre_flight_settings.clone()));
193203
let parameters_group = Command::new("parameters")
194204
.about("Operations on runtime parameters")
195205
.infer_subcommands(pre_flight_settings.infer_subcommands)
@@ -309,6 +319,7 @@ pub fn parser(pre_flight_settings: PreFlightSettings) -> Command {
309319
import_group,
310320
list_group,
311321
nodes_group,
322+
operator_policies_group,
312323
parameters_group,
313324
policies_group,
314325
publish_group,
@@ -1597,6 +1608,173 @@ fn global_parameters_subcommands(pre_flight_settings: PreFlightSettings) -> [Com
15971608
.map(|cmd| cmd.infer_long_args(pre_flight_settings.infer_long_options))
15981609
}
15991610

1611+
fn operator_policies_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 10] {
1612+
let declare_cmd = Command::new("declare")
1613+
.visible_aliases(vec!["update", "set"])
1614+
.about("Creates or updates an operator policy")
1615+
.after_help(color_print::cformat!("<bold>Doc guide:</bold>: {}", POLICY_GUIDE_URL))
1616+
.arg(
1617+
Arg::new("name")
1618+
.long("name")
1619+
.help("operator policy name")
1620+
.required(true),
1621+
)
1622+
.arg(
1623+
Arg::new("pattern")
1624+
.long("pattern")
1625+
.help("the pattern that is used to match entity (queue, stream, exchange) names")
1626+
.required(true),
1627+
)
1628+
.arg(
1629+
Arg::new("apply_to")
1630+
.long("apply-to")
1631+
.alias("applies-to")
1632+
.help("entities to apply to (queues, classic_queues, quorum_queues, streams, exchanges, all)")
1633+
.value_parser(value_parser!(PolicyTarget))
1634+
.required(true),
1635+
)
1636+
.arg(
1637+
Arg::new("priority")
1638+
.long("priority")
1639+
.help("operator policy priority (only the policy with the highest priority is effective)")
1640+
.required(false)
1641+
.default_value("0"),
1642+
)
1643+
.arg(
1644+
Arg::new("definition")
1645+
.long("definition")
1646+
.help("operator policy definition")
1647+
.required(true),
1648+
);
1649+
1650+
let list_cmd = Command::new("list")
1651+
.long_about("Lists operator policies")
1652+
.after_help(color_print::cformat!(
1653+
"<bold>Doc guide</bold>: {}",
1654+
POLICY_GUIDE_URL
1655+
));
1656+
1657+
let delete_cmd = Command::new("delete")
1658+
.about("Deletes an operator policy")
1659+
.arg(
1660+
Arg::new("name")
1661+
.long("name")
1662+
.help("policy name")
1663+
.required(true),
1664+
);
1665+
1666+
let delete_definition_key_cmd = Command::new("delete_definition_key")
1667+
.about("Deletes a definition key from an operator policy, unless it is the only key")
1668+
.arg(
1669+
Arg::new("name")
1670+
.long("name")
1671+
.help("operator policy name")
1672+
.required(true),
1673+
)
1674+
.arg(
1675+
Arg::new("definition_key")
1676+
.long("definition-key")
1677+
.help("definition key"),
1678+
);
1679+
1680+
let delete_definition_key_from_all_in_cmd = Command::new("delete_definition_key_from_all_in")
1681+
.about("Deletes a definition key from all operator policies in a virtual host, unless it is the only key")
1682+
.arg(
1683+
Arg::new("definition_key")
1684+
.long("definition-key")
1685+
.help("definition key")
1686+
);
1687+
1688+
let list_in_cmd = Command::new("list_in")
1689+
.about("Lists operator policies in a specific virtual host")
1690+
.arg(
1691+
Arg::new("apply_to")
1692+
.long("apply-to")
1693+
.alias("applies-to")
1694+
.value_parser(value_parser!(PolicyTarget)),
1695+
);
1696+
1697+
let list_matching_cmd = Command::new("list_matching_object")
1698+
.about("Lists operator policies that match an object (queue, stream, exchange) name")
1699+
.arg(
1700+
Arg::new("name")
1701+
.long("name")
1702+
.help("name to verify")
1703+
.required(true),
1704+
)
1705+
.arg(
1706+
Arg::new("type")
1707+
.long("type")
1708+
.value_parser(value_parser!(PolicyTarget))
1709+
.required(true)
1710+
.help("target type, one of 'queues', 'streams', 'exchanges'"),
1711+
);
1712+
1713+
let patch_cmd = Command::new("patch")
1714+
.about("Merges a set of keys into existing operator policy definitions")
1715+
.arg(
1716+
Arg::new("name")
1717+
.long("name")
1718+
.help("operator policy name")
1719+
.required(true),
1720+
)
1721+
.arg(
1722+
Arg::new("definition")
1723+
.long("definition")
1724+
.help("operator policy definition changes to merge into the existing ones"),
1725+
);
1726+
1727+
let update_cmd = Command::new("update_definition")
1728+
.about("Updates an operator policy definition key")
1729+
.arg(
1730+
Arg::new("name")
1731+
.long("name")
1732+
.help("operator policy name")
1733+
.required(true),
1734+
)
1735+
.arg(
1736+
Arg::new("definition_key")
1737+
.long("definition-key")
1738+
.help("operator policy definition key to update")
1739+
.required(true),
1740+
)
1741+
.arg(
1742+
Arg::new("definition_value")
1743+
.long("new-value")
1744+
.help("new definition value to set")
1745+
.required(true),
1746+
);
1747+
1748+
let update_all_in_cmd = Command::new("update_definitions_of_all_in")
1749+
.about("Updates a definition key in all operator policies in a virtual host")
1750+
.arg(
1751+
Arg::new("definition_key")
1752+
.long("definition-key")
1753+
.help("operator policy definition key to update")
1754+
.required(true),
1755+
)
1756+
.arg(
1757+
Arg::new("definition_value")
1758+
.long("new-value")
1759+
.help("new operator definition value to set")
1760+
.required(true),
1761+
);
1762+
1763+
[
1764+
declare_cmd,
1765+
delete_cmd,
1766+
delete_definition_key_cmd,
1767+
delete_definition_key_from_all_in_cmd,
1768+
list_cmd,
1769+
list_in_cmd,
1770+
list_matching_cmd,
1771+
patch_cmd,
1772+
update_cmd,
1773+
update_all_in_cmd,
1774+
]
1775+
.map(|cmd| cmd.infer_long_args(pre_flight_settings.infer_long_options))
1776+
}
1777+
16001778
fn policies_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 10] {
16011779
let declare_cmd = Command::new("declare")
16021780
.visible_aliases(vec!["update", "set"])

0 commit comments

Comments
 (0)