From 07a83d34b398631df3686793cd2dfd802049caad Mon Sep 17 00:00:00 2001 From: shakeelrao Date: Tue, 22 Oct 2024 16:28:40 -0400 Subject: [PATCH] List available auth methods in command output (#400) --- Makefile | 2 +- app/namespace.go | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a2c69e8..7258a08 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ release: $(call build,tcld,windows,amd64,.exe) tools: - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 @go install github.com/golang/mock/mockgen@latest lint: diff --git a/app/namespace.go b/app/namespace.go index f318ff1..ca1f781 100644 --- a/app/namespace.go +++ b/app/namespace.go @@ -48,6 +48,15 @@ const ( AuthMethodAPIKeyOrMTLS = "api_key_or_mtls" ) +var ( + AuthMethods = []string{ + AuthMethodRestricted, + AuthMethodMTLS, + AuthMethodAPIKey, + AuthMethodAPIKeyOrMTLS, + } +) + var ( CaCertificateFlag = &cli.StringFlag{ Name: CaCertificateFlagName, @@ -927,7 +936,8 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut, ResourceVersionFlag, &cli.StringFlag{ Name: authMethodFlagName, - Usage: "The authentication method used for the namespace (e.g. 'mtls', 'api_key')", + Aliases: []string{"am"}, + Usage: fmt.Sprintf("The authentication method used for the namespace (i.e. %s)", formatAuthMethods()), Required: true, }, }, @@ -1997,6 +2007,14 @@ func compareCodecSpec(existing, replacement *namespace.CodecServerPropertySpec) return diff.Diff(string(existingBytes), string(replacementBytes)), nil } +func formatAuthMethods() string { + var methods []string + for _, m := range AuthMethods { + methods = append(methods, fmt.Sprintf("'%s'", m)) + } + return strings.Join(methods, ", ") +} + func disruptiveChange(old namespace.AuthMethod, new namespace.AuthMethod) bool { return old != namespace.AUTH_METHOD_RESTRICTED && new != namespace.AUTH_METHOD_API_KEY_OR_MTLS }