From 0f85ecb95eb15f7ed82d983676ca5c4cc42f884f Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 13 Oct 2023 16:47:33 +0200 Subject: [PATCH 1/2] Fix invite command's flag setup to always use PreRun --- cmd/invite.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/cmd/invite.go b/cmd/invite.go index 3d52d98e..7e9a3e1c 100644 --- a/cmd/invite.go +++ b/cmd/invite.go @@ -22,6 +22,13 @@ import ( var listCmd = &cobra.Command{ Use: "list-invites", Short: "List all invites", + PreRun: func(cmd *cobra.Command, args []string) { + // Bind these to viper + err := viper.BindPFlags(cmd.Flags()) + if err != nil { + log.WithError(err).Fatal("could not bind `list-invites` flags") + } + }, Run: func(cmd *cobra.Command, args []string) { sigs := make(chan os.Signal, 1) @@ -49,13 +56,14 @@ var listCmd = &cobra.Command{ var createCmd = &cobra.Command{ Use: "create-invite", Short: "Create a new invite", - Run: func(cmd *cobra.Command, args []string) { - // Bind flags to viper + PreRun: func(cmd *cobra.Command, args []string) { + // Bind these to viper err := viper.BindPFlags(cmd.Flags()) if err != nil { - log.WithError(err).Fatal("could not bind flags") + log.WithError(err).Fatal("could not bind `create-invite` flags") } - + }, + Run: func(cmd *cobra.Command, args []string) { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) @@ -82,13 +90,14 @@ var createCmd = &cobra.Command{ var revokeCmd = &cobra.Command{ Use: "revoke-invites", Short: "Revoke an existing invite", - Run: func(cmd *cobra.Command, args []string) { - // Bind flags to viper + PreRun: func(cmd *cobra.Command, args []string) { + // Bind these to viper err := viper.BindPFlags(cmd.Flags()) if err != nil { - log.WithError(err).Fatal("could not bind flags") + log.WithError(err).Fatal("could not bind `revoke-invites` flags") } - + }, + Run: func(cmd *cobra.Command, args []string) { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) From b9e0cbebd9fa6698a592fa8ff5d06ac816c2e7bc Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 17 Oct 2023 08:40:42 +0200 Subject: [PATCH 2/2] Use --url, instead of --gateway-url for determining auth scheme --- cmd/root.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index dec32ab4..f6361a21 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -186,15 +186,11 @@ func ensureToken(ctx context.Context, requiredScopes []string) (context.Context, } // Check to see if the URL is secure - gatewayUrl := viper.GetString("gateway-url") - if gatewayUrl == "" { - gatewayUrl = fmt.Sprintf("%v/api/gateway", viper.GetString("url")) - viper.Set("gateway-url", gatewayUrl) - } - parsed, err := url.Parse(gatewayUrl) + appurl := viper.GetString("url") + parsed, err := url.Parse(appurl) if err != nil { log.WithContext(ctx).WithError(err).Error("Failed to parse --url") - return ctx, fmt.Errorf("error parsing --gateway-url: %w", err) + return ctx, fmt.Errorf("error parsing --url: %w", err) } if parsed.Scheme == "wss" || parsed.Scheme == "https" || parsed.Hostname() == "localhost" { @@ -262,7 +258,6 @@ func ensureToken(ctx context.Context, requiredScopes []string) (context.Context, audienceOption := oauth2.SetAuthURLParam("audience", "https://api.overmind.tech") u := config.AuthCodeURL(oAuthStateString, oauth2.AccessTypeOnline, audienceOption) - log.WithContext(ctx).Infof("Follow this link to authenticate: %v", Underline.TextStyle(u)) // Start the webserver