diff --git a/api/namespace.go b/api/namespace.go index 96e26728c5..213cd8cf44 100644 --- a/api/namespace.go +++ b/api/namespace.go @@ -28,6 +28,9 @@ type Namespace struct { // This is nullable so that we can omit if empty when encoding in JSON DeletedAt *time.Time `json:"DeletedAt,omitempty" alias:"deleted_at"` + // Partition which contains the Namespace. + Partition string `json:"Partition,omitempty"` + // CreateIndex is the Raft index at which the Namespace was created CreateIndex uint64 `json:"CreateIndex,omitempty"` diff --git a/command/acl/authmethod/formatter.go b/command/acl/authmethod/formatter.go index 35b428c7fc..69bc4860c6 100644 --- a/command/acl/authmethod/formatter.go +++ b/command/acl/authmethod/formatter.go @@ -51,6 +51,9 @@ func (f *prettyFormatter) FormatAuthMethod(method *api.ACLAuthMethod) (string, e buffer.WriteString(fmt.Sprintf("Name: %s\n", method.Name)) buffer.WriteString(fmt.Sprintf("Type: %s\n", method.Type)) + if method.Partition != "" { + buffer.WriteString(fmt.Sprintf("Partition: %s\n", method.Partition)) + } if method.Namespace != "" { buffer.WriteString(fmt.Sprintf("Namespace: %s\n", method.Namespace)) } @@ -100,6 +103,9 @@ func (f *prettyFormatter) formatAuthMethodListEntry(method *api.ACLAuthMethodLis buffer.WriteString(fmt.Sprintf("%s:\n", method.Name)) buffer.WriteString(fmt.Sprintf(" Type: %s\n", method.Type)) + if method.Partition != "" { + buffer.WriteString(fmt.Sprintf(" Partition: %s\n", method.Partition)) + } if method.Namespace != "" { buffer.WriteString(fmt.Sprintf(" Namespace: %s\n", method.Namespace)) } diff --git a/command/acl/bindingrule/formatter.go b/command/acl/bindingrule/formatter.go index 92210dd3b3..65a3455e59 100644 --- a/command/acl/bindingrule/formatter.go +++ b/command/acl/bindingrule/formatter.go @@ -50,6 +50,9 @@ func (f *prettyFormatter) FormatBindingRule(rule *api.ACLBindingRule) (string, e var buffer bytes.Buffer buffer.WriteString(fmt.Sprintf("ID: %s\n", rule.ID)) + if rule.Partition != "" { + buffer.WriteString(fmt.Sprintf("Partition: %s\n", rule.Partition)) + } if rule.Namespace != "" { buffer.WriteString(fmt.Sprintf("Namespace: %s\n", rule.Namespace)) } @@ -80,6 +83,9 @@ func (f *prettyFormatter) formatBindingRuleListEntry(rule *api.ACLBindingRule) s var buffer bytes.Buffer buffer.WriteString(fmt.Sprintf("%s:\n", rule.ID)) + if rule.Partition != "" { + buffer.WriteString(fmt.Sprintf(" Partition: %s\n", rule.Partition)) + } if rule.Namespace != "" { buffer.WriteString(fmt.Sprintf(" Namespace: %s\n", rule.Namespace)) } diff --git a/command/acl/policy/formatter.go b/command/acl/policy/formatter.go index e385f2bccf..6bcee99f2c 100644 --- a/command/acl/policy/formatter.go +++ b/command/acl/policy/formatter.go @@ -52,6 +52,9 @@ func (f *prettyFormatter) FormatPolicy(policy *api.ACLPolicy) (string, error) { buffer.WriteString(fmt.Sprintf("ID: %s\n", policy.ID)) buffer.WriteString(fmt.Sprintf("Name: %s\n", policy.Name)) + if policy.Partition != "" { + buffer.WriteString(fmt.Sprintf("Partition: %s\n", policy.Partition)) + } if policy.Namespace != "" { buffer.WriteString(fmt.Sprintf("Namespace: %s\n", policy.Namespace)) } @@ -83,6 +86,9 @@ func (f *prettyFormatter) formatPolicyListEntry(policy *api.ACLPolicyListEntry) buffer.WriteString(fmt.Sprintf("%s:\n", policy.Name)) buffer.WriteString(fmt.Sprintf(" ID: %s\n", policy.ID)) + if policy.Partition != "" { + buffer.WriteString(fmt.Sprintf(" Partition: %s\n", policy.Partition)) + } if policy.Namespace != "" { buffer.WriteString(fmt.Sprintf(" Namespace: %s\n", policy.Namespace)) } diff --git a/command/acl/role/formatter.go b/command/acl/role/formatter.go index 37a77e896a..8f9b57cfe2 100644 --- a/command/acl/role/formatter.go +++ b/command/acl/role/formatter.go @@ -52,6 +52,9 @@ func (f *prettyFormatter) FormatRole(role *api.ACLRole) (string, error) { buffer.WriteString(fmt.Sprintf("ID: %s\n", role.ID)) buffer.WriteString(fmt.Sprintf("Name: %s\n", role.Name)) + if role.Partition != "" { + buffer.WriteString(fmt.Sprintf("Partition: %s\n", role.Partition)) + } if role.Namespace != "" { buffer.WriteString(fmt.Sprintf("Namespace: %s\n", role.Namespace)) } @@ -102,6 +105,9 @@ func (f *prettyFormatter) formatRoleListEntry(role *api.ACLRole) string { buffer.WriteString(fmt.Sprintf("%s:\n", role.Name)) buffer.WriteString(fmt.Sprintf(" ID: %s\n", role.ID)) + if role.Partition != "" { + buffer.WriteString(fmt.Sprintf(" Partition: %s\n", role.Partition)) + } if role.Namespace != "" { buffer.WriteString(fmt.Sprintf(" Namespace: %s\n", role.Namespace)) } diff --git a/command/acl/token/clone/token_clone_test.go b/command/acl/token/clone/token_clone_test.go index 4d5c86b37e..ec7c4ebcc5 100644 --- a/command/acl/token/clone/token_clone_test.go +++ b/command/acl/token/clone/token_clone_test.go @@ -7,18 +7,20 @@ import ( "strings" "testing" - "github.com/hashicorp/consul/agent" - "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/hashicorp/consul/agent" + "github.com/hashicorp/consul/api" + "github.com/hashicorp/consul/testrpc" ) func parseCloneOutput(t *testing.T, output string) *api.ACLToken { // This will only work for non-legacy tokens re := regexp.MustCompile("AccessorID: ([a-zA-Z0-9\\-]{36})\n" + "SecretID: ([a-zA-Z0-9\\-]{36})\n" + + "(?:Partition: default\n)?" + "(?:Namespace: default\n)?" + "Description: ([^\n]*)\n" + "Local: (true|false)\n" + diff --git a/command/acl/token/formatter.go b/command/acl/token/formatter.go index 6e5a5a059c..ad6d3ae797 100644 --- a/command/acl/token/formatter.go +++ b/command/acl/token/formatter.go @@ -52,6 +52,9 @@ func (f *prettyFormatter) FormatToken(token *api.ACLToken) (string, error) { buffer.WriteString(fmt.Sprintf("AccessorID: %s\n", token.AccessorID)) buffer.WriteString(fmt.Sprintf("SecretID: %s\n", token.SecretID)) + if token.Partition != "" { + buffer.WriteString(fmt.Sprintf("Partition: %s\n", token.Partition)) + } if token.Namespace != "" { buffer.WriteString(fmt.Sprintf("Namespace: %s\n", token.Namespace)) } @@ -126,6 +129,9 @@ func (f *prettyFormatter) formatTokenListEntry(token *api.ACLTokenListEntry) str buffer.WriteString(fmt.Sprintf("AccessorID: %s\n", token.AccessorID)) buffer.WriteString(fmt.Sprintf("SecretID: %s\n", token.SecretID)) + if token.Partition != "" { + buffer.WriteString(fmt.Sprintf("Partition: %s\n", token.Partition)) + } if token.Namespace != "" { buffer.WriteString(fmt.Sprintf("Namespace: %s\n", token.Namespace)) }