github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/oauth/enable.go (about)

     1  package oauth
     2  
     3  import (
     4  	"github.com/spf13/cobra"
     5  
     6  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
     7  	"github.com/kubeshop/testkube/pkg/ui"
     8  )
     9  
    10  // NewEnableOAuthCmd is oauth enable command
    11  func NewEnableOAuthCmd() *cobra.Command {
    12  	cmd := &cobra.Command{
    13  		Use:   "oauth",
    14  		Short: "enable oauth authentication for direct api",
    15  		Run: func(cmd *cobra.Command, args []string) {
    16  			ui.NL()
    17  			ui.Print(ui.IconRocket + "  Enabling OAuth authentication for direct api")
    18  			cfg, err := config.Load()
    19  			if err == nil {
    20  				cfg.EnableOAuth()
    21  				err = config.Save(cfg)
    22  			}
    23  			if err != nil {
    24  				ui.PrintDisabled("OAuth", "failed")
    25  				ui.PrintConfigError(err)
    26  			} else {
    27  				ui.PrintEnabled("OAuth", "enabled")
    28  			}
    29  			ui.NL()
    30  		},
    31  	}
    32  
    33  	return cmd
    34  }