Beispiel #1
0
func CmdClear(privateKey, session, environments, defaultEnv, pods bool, settings *models.Settings) error {
	if defaultEnv {
		logrus.Warnln("The \"--default\" flag has been deprecated! It will be removed in a future version.")
	}
	if privateKey {
		settings.PrivateKeyPath = ""
	}
	if session {
		settings.SessionToken = ""
		settings.UsersID = ""
	}
	if environments {
		settings.Environments = map[string]models.AssociatedEnv{}
	}
	if defaultEnv {
		settings.Default = ""
	}
	if pods {
		settings.Pods = &[]models.Pod{}
	}
	config.SaveSettings(settings)
	if !privateKey && !session && !environments && !defaultEnv && !pods {
		logrus.Println("No settings were specified. To see available options, run \"catalyze clear --help\"")
	} else {
		logrus.Println("All specified settings have been cleared")
	}
	return nil
}
Beispiel #2
0
func CmdSet(path string, settings *models.Settings) error {
	fullPath, err := homedir.Expand(path)
	if err != nil {
		return err
	}

	// make sure both files exist
	_, err = os.Stat(fullPath + ".pub")
	if err != nil {
		if os.IsNotExist(err) {
			return fmt.Errorf("Public key file '%s' does not exist.", fullPath+".pub")
		}
		return err
	}

	_, err = os.Stat(fullPath)
	if err != nil {
		if os.IsNotExist(err) {
			return fmt.Errorf("Private key file '%s' does not exist.", fullPath)
		}
		return err
	}

	settings.PrivateKeyPath = fullPath
	settings.SessionToken = ""
	a := auth.New(settings, prompts.New())
	user, err := a.Signin()
	if err != nil {
		return err
	}
	logrus.Printf("Successfully added key and signed in as %s.", user.Email)
	return nil
}