login

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:                        "login",
	Short:                      "login tcas",
	Long:                       "login tcas",
	SuggestionsMinimumDistance: 1,
	DisableSuggestions:         false,
	Run: func(cmd *cobra.Command, args []string) {
		url, _ := cmd.Flags().GetString("url")
		username, _ := cmd.Flags().GetString("username")
		password, _ := cmd.Flags().GetString("password")
		skipssl, _ := cmd.Flags().GetBool("skipssl")

		if username == "" {
			fmt.Print("Username: ")
			fmt.Scanln(&username)
		}

		if password == "" {
			fmt.Print("Password: ")
			bytePassword, err := terminal.ReadPassword(int(os.Stdin.Fd()))
			if err != nil {
				logrus.Errorf("read password failed, error: %s", err)
				return
			}
			password = string(bytePassword)
		} else {
			fmt.Println("WARNING! Using --password via the CLI is insecure")
		}

		var tcasConfig *manager.TCASInfo
		tcasConfig, err := initconfig.ReadTCASInfoFromConfig(url)
		if err != nil {

			tcasConfig = new(manager.TCASInfo)
			tcasConfig.APIEndpoint = url
		}
		tcasConfig.SkipVerify = skipssl
		m, err := manager.New(tcasConfig, tees.GetCollectors())
		if err != nil {
			logrus.Errorf("create attest manager failed, error: %s", err)
			return
		}

		config, err := m.Login(username, password)
		if err != nil {
			logrus.Errorf("%s", err)
			return
		}

		homedir, err := os.UserHomeDir()
		if err != nil {
			logrus.Errorf("home dir not find, error: %s", err)
			return
		}
		configPath := path.Join(homedir, initconfig.ConfigFile)
		configs := new(initconfig.TCASConfig)
		if file.IsFile(configPath) == false {
			logrus.Debugf("config file does not exist, generate new config file")
			err := os.MkdirAll(path.Dir(configPath), os.ModeDir)
			if err != nil {
				logrus.Errorf("creat config dir faile, error: %s", err)
				return
			}
			config.APIEndpoint = url
			configs.TCASInfos = map[string]*manager.TCASInfo{url: config}
		} else {
			configs, err = initconfig.ReadTCASConfigs(configPath)
			if err != nil {
				logrus.Errorf("read tcas confings failed, error: %s", err)
				return
			}
			configs.TCASInfos[url] = config
		}
		err = initconfig.WriteTCASConfigToFile(configs, configPath)
		if err != nil {
			logrus.Errorf("write config failed, error: %s", err)
			return
		}
		fmt.Println("login successful")
	},
}

Cmd represents the ca command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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