From a72b0759330850b6fe075454dc114b1a60231e55 Mon Sep 17 00:00:00 2001 From: Ronald Ekambi Date: Tue, 14 Feb 2023 10:39:30 -0500 Subject: [PATCH] Add append-rules option --- command/acl/policy/update/policy_update.go | 10 +++++++++- website/content/commands/acl/policy/update.mdx | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/command/acl/policy/update/policy_update.go b/command/acl/policy/update/policy_update.go index 5d0768a803..46b2ae741d 100644 --- a/command/acl/policy/update/policy_update.go +++ b/command/acl/policy/update/policy_update.go @@ -39,6 +39,7 @@ type cmd struct { showMeta bool format string testStdin io.Reader + appendRules bool } func (c *cmd) init() { @@ -58,6 +59,8 @@ func (c *cmd) init() { c.flags.BoolVar(&c.noMerge, "no-merge", false, "Do not merge the current policy "+ "information with what is provided to the command. Instead overwrite all fields "+ "with the exception of the policy ID which is immutable.") + c.flags.BoolVar(&c.appendRules, "append-rules", false, "Do not override the current policy's rules, "+ + "information provided is appended to the existing rules.") c.flags.StringVar( &c.format, "format", @@ -148,7 +151,12 @@ func (c *cmd) Run(args []string) int { updated.Description = c.description } if c.rulesSet { - updated.Rules = rules + if c.appendRules { + updated.Rules = rules + p.Rules + } else { + c.UI.Warn("Completely overriding rules, use `-append-rules` in case you want to append rules rather completely overriding them.") + updated.Rules = rules + } } if c.datacenters != nil { updated.Datacenters = c.datacenters diff --git a/website/content/commands/acl/policy/update.mdx b/website/content/commands/acl/policy/update.mdx index e62dfa72d9..bec3affbee 100644 --- a/website/content/commands/acl/policy/update.mdx +++ b/website/content/commands/acl/policy/update.mdx @@ -49,6 +49,9 @@ Usage: `consul acl policy update [options] [args]` the value is a file path to load the rules from. `-` may also be given to indicate that the rules are available on stdin. +- `-append-rules` - Append the policy rules provided to the command to the existing +policy rules rather than overwriting it. + - `-valid-datacenter=` - Datacenter that the policy should be valid within. This flag may be specified multiple times.