Skip to content

Commit

Permalink
List available auth methods in command output (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
shakeelrao authored Oct 22, 2024
1 parent ed9abc1 commit 07a83d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion app/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ const (
AuthMethodAPIKeyOrMTLS = "api_key_or_mtls"
)

var (
AuthMethods = []string{
AuthMethodRestricted,
AuthMethodMTLS,
AuthMethodAPIKey,
AuthMethodAPIKeyOrMTLS,
}
)

var (
CaCertificateFlag = &cli.StringFlag{
Name: CaCertificateFlagName,
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 07a83d3

Please sign in to comment.