Skip to content

Commit

Permalink
Add some more error handling and fix verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dkerwin committed Nov 27, 2019
1 parent b83a8e9 commit 892fe65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 9 additions & 2 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,13 @@ func (d DexterOIDC) StartHTTPServer() error {

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)

d.httpServer.Shutdown(ctx)
err := d.httpServer.Shutdown(ctx)
cancel()

if err != nil {
log.Errorf("HTTP shutdown failed: %s", err)
}

log.Infof("Shutdown completed")
return nil
// OS signal was received
Expand Down Expand Up @@ -355,7 +360,9 @@ func (d *DexterOIDC) writeK8sConfig(token *oauth2.Token) error {
}

// write snipped to temporary file
clientcmd.WriteToFile(*config, tempKubeConfig.Name())
if err := clientcmd.WriteToFile(*config, tempKubeConfig.Name()); err != nil {
return fmt.Errorf("failed to write temporary file: %s", err)
}

// setup the order for the file load
loadingRules := clientcmd.ClientConfigLoadingRules{
Expand Down
17 changes: 10 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cmd

import (
"github.com/spf13/cobra"
"fmt"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

const (
Expand All @@ -17,26 +18,28 @@ const (
)

var (
Verbose bool
verbose bool

rootCmd = &cobra.Command{
Use: "dexter",
Short: "A OpenId connect authentication helper for Kubernetes",
Long: fmt.Sprintf(`%s
dexter is a authentication helper for Kubernetes that does the heavy
lifting for SSO (Single Sign On) for Kubernetes.`, BANNER),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if verbose {
log.SetLevel(log.DebugLevel)
}
return nil
},
}
)

func init() {
rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
}

// Execute executes the root command.
func Execute() error {
if Verbose {
log.SetLevel(log.DebugLevel)
}

return rootCmd.Execute()
}

0 comments on commit 892fe65

Please sign in to comment.