func askAuthMechanism()

in pkg/ecctl/init.go [453:480]


func askAuthMechanism(cfg *Config, scanner *input.Scanner, writer io.Writer, passFunc PassFunc) error {
	authChoiceRaw := scanner.Scan(authChoiceMsg)
	fmt.Fprintln(writer)
	authChoice, err := strconv.Atoi(authChoiceRaw)
	if err != nil {
		return err
	}

	switch authChoice {
	default:
		return errors.New("invalid authentication choice")
	case apiKeyChoice:
		if err := askAPIKey(cfg, writer, passFunc); err != nil {
			return err
		}
	case userPassChoice:
		cfg.User = scanner.Scan(userMsg)

		pass, err := ReadSecret(writer, passFunc, passMsg)
		if err != nil {
			return err
		}
		cfg.Pass = string(pass)
		cfg.APIKey = ""
	}

	return nil
}