From 48ef28131495c3cab67cd1f92128efbdd9ed4600 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 28 Jan 2025 19:42:19 -0500 Subject: [PATCH] refinements to original add-verify-ext-jwt-oidc --- internal/cobra/cobra-utils.go | 3 ++ ziti/cmd/edge/ext-jwt-signer/oidc/oidc.go | 28 ++++--------------- .../ext-jwt-signer/verify-ext-jwt-signer.go | 2 +- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/internal/cobra/cobra-utils.go b/internal/cobra/cobra-utils.go index 10ca87584..4fb396b2b 100644 --- a/internal/cobra/cobra-utils.go +++ b/internal/cobra/cobra-utils.go @@ -119,4 +119,7 @@ Common flags for all commands: Use "{{.CommandPath}} [command] --help" for more information about a command. `) + cmd.SetUsageFunc(func(c *cobra.Command) error { + return cmd.Help() + }) } diff --git a/ziti/cmd/edge/ext-jwt-signer/oidc/oidc.go b/ziti/cmd/edge/ext-jwt-signer/oidc/oidc.go index 2d8819dd2..84714f02a 100644 --- a/ziti/cmd/edge/ext-jwt-signer/oidc/oidc.go +++ b/ziti/cmd/edge/ext-jwt-signer/oidc/oidc.go @@ -43,7 +43,6 @@ import ( "github.com/openziti/ziti/internal" ziticobra "github.com/openziti/ziti/internal/cobra" "github.com/openziti/ziti/internal/rest/client" - "github.com/openziti/ziti/ziti/cmd/api" "github.com/openziti/ziti/ziti/cmd/edge" ) @@ -277,6 +276,10 @@ func NewOidcVerificationCmd(out io.Writer, errOut io.Writer, initialContext cont Short: "test an external JWT signer for OIDC auth", Long: "tests and verifies an external JWT signer is configured correctly to authenticate using OIDC", Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Force display of the usage template + return cmd.Usage() + }, Run: func(cmd *cobra.Command, args []string) { logLvl := logrus.InfoLevel if opts.Verbose { @@ -396,28 +399,7 @@ func NewOidcVerificationCmd(out io.Writer, errOut io.Writer, initialContext cont cmd.Flags().StringVar(&opts.ControllerUrl, "controller-url", "", "The url of the controller") cmd.Flags().StringSliceVarP(&opts.additionalScopes, "additional-scopes", "s", []string{}, "List of additional scopes to add") - l := ziticobra.GetFlagsForAnnotation(cmd, edge.LoginFlagKey) - c := ziticobra.GetFlagsForAnnotation(cmd, api.CommonFlagKey) - u := ziticobra.GetFlagsWithoutAnnotations(cmd, edge.LoginFlagKey, api.CommonFlagKey) - cmd.SetHelpTemplate(`{{.Long}} - -Usage: - {{.UseLine}} - -Available Commands: -{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}} - {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}} - -Flags: -` + u + ` -Flags related to logging in: -` + l + ` -Common flags for all commands: -` + c + ` - -Use "{{.CommandPath}} [command] --help" for more information about a command. -`) - + ziticobra.SetHelpTemplate(cmd) return cmd } diff --git a/ziti/cmd/edge/ext-jwt-signer/verify-ext-jwt-signer.go b/ziti/cmd/edge/ext-jwt-signer/verify-ext-jwt-signer.go index db327437d..87344cc21 100644 --- a/ziti/cmd/edge/ext-jwt-signer/verify-ext-jwt-signer.go +++ b/ziti/cmd/edge/ext-jwt-signer/verify-ext-jwt-signer.go @@ -25,7 +25,7 @@ import ( func NewVerifyExtJwtSignerCmd(out io.Writer, errOut io.Writer, initialContext context.Context) *cobra.Command { cmd := &cobra.Command{ - Use: "verify-ext-auth", + Use: "verify-ext-jwt-signer", Short: "test if an external JWT signer is correctly configured", Long: "tests and verifies an external JWT signer is configured correctly", }