Add partitions to prettyformatters (#11789)

This commit is contained in:
Chris S. Kim 2021-12-09 15:58:45 -05:00 committed by GitHub
parent ded49b3ab0
commit ead530bc48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 3 deletions

View File

@ -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"`

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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" +

View File

@ -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))
}