Skip to content

Commit

Permalink
Deprecate merge-node-identities and merge-service-identities flags
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodingenthusiast committed Mar 6, 2023
1 parent fc23232 commit 04a7185
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
84 changes: 59 additions & 25 deletions command/acl/token/update/token_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,35 @@ type cmd struct {
http *flags.HTTPFlags
help string

tokenAccessorID string
policyIDs []string
appendPolicyIDs []string
policyNames []string
appendPolicyNames []string
roleIDs []string
appendRoleIDs []string
roleNames []string
appendRoleNames []string
serviceIdents []string
nodeIdents []string
description string
mergeServiceIdents bool
mergeNodeIdents bool
showMeta bool
format string
tokenAccessorID string
policyIDs []string
appendPolicyIDs []string
policyNames []string
appendPolicyNames []string
roleIDs []string
appendRoleIDs []string
roleNames []string
appendRoleNames []string
serviceIdents []string
nodeIdents []string
appendNodeIdents []string
appendServiceIdents []string
description string
showMeta bool
format string

// DEPRECATED
mergeRoles bool
mergePolicies bool
tokenID string
mergeServiceIdents bool
mergeNodeIdents bool
mergeRoles bool
mergePolicies bool
tokenID string
}

func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.flags.BoolVar(&c.showMeta, "meta", false, "Indicates that token metadata such "+
"as the content hash and raft indices should be shown for each entry")
c.flags.BoolVar(&c.mergeServiceIdents, "merge-service-identities", false, "Merge the new service identities "+
"with the existing service identities")
c.flags.BoolVar(&c.mergeNodeIdents, "merge-node-identities", false, "Merge the new node identities "+
"with the existing node identities")
c.flags.StringVar(&c.tokenAccessorID, "accessor-id", "", "The Accessor ID of the token to update. "+
"It may be specified as a unique ID prefix but will error if the prefix "+
"matches multiple token Accessor IDs")
Expand All @@ -79,9 +77,15 @@ func (c *cmd) init() {
c.flags.Var((*flags.AppendSliceValue)(&c.serviceIdents), "service-identity", "Name of a "+
"service identity to use for this token. May be specified multiple times. Format is "+
"the SERVICENAME or SERVICENAME:DATACENTER1,DATACENTER2,...")
c.flags.Var((*flags.AppendSliceValue)(&c.appendServiceIdents), "append-service-identity", "Name of a "+
"service identity to use for this token. This token retains existing service identities. May be specified"+
"multiple times. Format is the SERVICENAME or SERVICENAME:DATACENTER1,DATACENTER2,...")
c.flags.Var((*flags.AppendSliceValue)(&c.nodeIdents), "node-identity", "Name of a "+
"node identity to use for this token. May be specified multiple times. Format is "+
"NODENAME:DATACENTER")
c.flags.Var((*flags.AppendSliceValue)(&c.appendNodeIdents), "append-node-identity", "Name of a "+
"node identity to use for this token. This token retains existing node identities. May be "+
"specified multiple times. Format is NODENAME:DATACENTER")
c.flags.StringVar(
&c.format,
"format",
Expand All @@ -101,6 +105,10 @@ func (c *cmd) init() {
"Use -append-policy-id or -append-policy-name instead.")
c.flags.BoolVar(&c.mergeRoles, "merge-roles", false, "DEPRECATED. "+
"Use -append-role-id or -append-role-name instead.")
c.flags.BoolVar(&c.mergeServiceIdents, "merge-service-identities", false, "DEPRECATED. "+
"Use -append-service-identity instead.")
c.flags.BoolVar(&c.mergeNodeIdents, "merge-node-identities", false, "DEPRECATED. "+
"Use -append-node-identity instead.")
}

func (c *cmd) Run(args []string) int {
Expand Down Expand Up @@ -147,13 +155,39 @@ func (c *cmd) Run(args []string) int {
t.Description = c.description
}

hasAppendServiceFields := len(c.appendServiceIdents) > 0
hasServiceFields := len(c.serviceIdents) > 0
parsedServiceIdents, err := acl.ExtractServiceIdentities(c.serviceIdents)
if hasAppendServiceFields {
parsedServiceIdents, err = acl.ExtractServiceIdentities(c.serviceIdents)
}

if hasAppendServiceFields && hasServiceFields {
c.UI.Error("Cannot combine the use of service-identity flag with append-service-identity. " +
"To set or overwrite existing service identities, use -service-identity. " +
"To append to existing service identities, use -append-service-identity.")
return 1
}

if err != nil {
c.UI.Error(err.Error())
return 1
}

hasAppendNodeFields := len(c.appendNodeIdents) > 0
hasNodeFields := len(c.nodeIdents) > 0

if hasAppendNodeFields && hasNodeFields {
c.UI.Error("Cannot combine the use of node-identity flag with append-node-identity. " +
"To set or overwrite existing node identities, use -node-identity. " +
"To append to existing node identities, use -append-node-identity.")
return 1
}

parsedNodeIdents, err := acl.ExtractNodeIdentities(c.nodeIdents)
if hasAppendNodeFields {
parsedNodeIdents, err = acl.ExtractNodeIdentities(c.appendNodeIdents)
}
if err != nil {
c.UI.Error(err.Error())
return 1
Expand Down Expand Up @@ -310,7 +344,7 @@ func (c *cmd) Run(args []string) int {
}
}

if c.mergeServiceIdents {
if c.mergeServiceIdents || hasAppendServiceFields {
for _, svcid := range parsedServiceIdents {
found := -1
for i, link := range t.ServiceIdentities {
Expand All @@ -330,7 +364,7 @@ func (c *cmd) Run(args []string) int {
t.ServiceIdentities = parsedServiceIdents
}

if c.mergeNodeIdents {
if c.mergeNodeIdents || hasAppendNodeFields {
for _, nodeid := range parsedNodeIdents {
found := false
for _, link := range t.NodeIdentities {
Expand Down
2 changes: 2 additions & 0 deletions website/content/commands/acl/policy/update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ 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.

~> Specifying `-rules` will overwrite existing rules.

- `-valid-datacenter=<value>` - Datacenter that the policy should be valid within.
This flag may be specified multiple times.

Expand Down
2 changes: 1 addition & 1 deletion website/content/commands/acl/token/update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Usage: `consul acl token update [options]`
- `-id=<string>` - The Accessor ID of the token to read. It may be specified as a
unique ID prefix but will error if the prefix matches multiple token Accessor IDs

- `merge-node-identities` - Merge the new node identities with the existing node
- `-merge-node-identities` - Merge the new node identities with the existing node
identities.

- `-merge-policies` - Deprecated. Merge the new policies with the existing policies.
Expand Down

0 comments on commit 04a7185

Please sign in to comment.