cli

package
v0.0.0-...-3b9fef2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoginCmd = &cobra.Command{
	Use:   "login",
	Short: "Login to HPCAdmin",
	Run: func(cmd *cobra.Command, args []string) {
		slog.Debug("running login command", "method", "LoginCmd.Run")
		cfg, err := config.GetCLIConfig()
		if err != nil {
			util.PrintAndExit(fmt.Sprintf("Error getting CLI config: %v\n", err), 1)
		}

		authInfo, err := GetAuthInfo(cfg)
		if err != nil {
			util.ErrorPrint(fmt.Sprintf("Error getting auth info: %v\n", err))
			os.Exit(1)
		}

		var accessToken string
		azureAuthOptions := auth.NewOauthHandlerOptions(auth.Azure, authInfo.TenantID, authInfo.ClientID)

		ah := auth.NewAuthHandler(cfg.ConfigDir, azureAuthOptions)
		accessToken, ok := ah.LoadAccessToken()
		if !ok {
			accessToken, err = ah.Authenticate()
			if err != nil {
				util.ErrorPrint(fmt.Sprintf("Error authenticating: %v\n", err))
				os.Exit(1)
			}
			ah.SaveAccessToken(accessToken)
		}

		fmt.Printf("token: %v\n", accessToken)
	},
}

Functions

func Execute

func Execute() error

Types

type AuthInfo

type AuthInfo struct {
	TenantID string `json:"tenant_id"`
	ClientID string `json:"client_id"`
}

func GetAuthInfo

func GetAuthInfo(config *config.CLIConfig) (*AuthInfo, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL