Exemplo n.º 1
0
func resetPasswordCommand(c CommandLine) error {
	newPassword := c.Args().First()

	password := models.Password(newPassword)
	if password.IsWeak() {
		return fmt.Errorf("New password is too short")
	}

	userQuery := models.GetUserByIdQuery{Id: AdminUserId}

	if err := bus.Dispatch(&userQuery); err != nil {
		return fmt.Errorf("Could not read user from database. Error: %v", err)
	}

	passwordHashed := util.EncodePassword(newPassword, userQuery.Result.Salt)

	cmd := models.ChangeUserPasswordCommand{
		UserId:      AdminUserId,
		NewPassword: passwordHashed,
	}

	if err := bus.Dispatch(&cmd); err != nil {
		return fmt.Errorf("Failed to update user password")
	}

	logger.Infof("\n")
	logger.Infof("Admin password changed successfully %s", color.GreenString("✔"))

	return nil
}
Exemplo n.º 2
0
func upgradeAllCommand(c CommandLine) error {
	pluginsDir := c.PluginDirectory()

	localPlugins := s.GetLocalPlugins(pluginsDir)

	remotePlugins, err := s.ListAllPlugins(c.GlobalString("repo"))

	if err != nil {
		return err
	}

	pluginsToUpgrade := make([]m.InstalledPlugin, 0)

	for _, localPlugin := range localPlugins {
		for _, remotePlugin := range remotePlugins.Plugins {
			if localPlugin.Id == remotePlugin.Id {
				if ShouldUpgrade(localPlugin.Info.Version, remotePlugin) {
					pluginsToUpgrade = append(pluginsToUpgrade, localPlugin)
				}
			}
		}
	}

	for _, p := range pluginsToUpgrade {
		logger.Infof("Updating %v \n", p.Id)

		s.RemoveInstalledPlugin(pluginsDir, p.Id)
		InstallPlugin(p.Id, "", c)
	}

	return nil
}
Exemplo n.º 3
0
func InstallPlugin(pluginName, version string, c CommandLine) error {
	plugin, err := s.GetPlugin(pluginName, c.GlobalString("repo"))
	pluginFolder := c.GlobalString("pluginsDir")
	if err != nil {
		return err
	}

	v, err := SelectVersion(plugin, version)
	if err != nil {
		return err
	}

	if version == "" {
		version = v.Version
	}

	downloadURL := fmt.Sprintf("%s/%s/versions/%s/download",
		c.GlobalString("repo"),
		pluginName,
		version)

	logger.Infof("installing %v @ %v\n", plugin.Id, version)
	logger.Infof("from url: %v\n", downloadURL)
	logger.Infof("into: %v\n", pluginFolder)
	logger.Info("\n")

	err = downloadFile(plugin.Id, pluginFolder, downloadURL)
	if err != nil {
		return err
	}

	logger.Infof("%s Installed %s successfully \n", color.GreenString("✔"), plugin.Id)

	/* Enable once we need support for downloading depedencies
	res, _ := s.ReadPlugin(pluginFolder, pluginName)
	for _, v := range res.Dependency.Plugins {
		InstallPlugin(v.Id, version, c)
		log.Infof("Installed dependency: %v ✔\n", v.Id)
	}
	*/
	return err
}
Exemplo n.º 4
0
func RemoveInstalledPlugin(pluginPath, pluginName string) error {
	logger.Infof("Removing plugin: %v\n", pluginName)
	pluginDir := path.Join(pluginPath, pluginName)

	_, err := IoHelper.Stat(pluginDir)
	if err != nil {
		return err
	}

	return IoHelper.RemoveAll(pluginDir)
}
Exemplo n.º 5
0
func lsCommand(c CommandLine) error {
	pluginDir := c.GlobalString("pluginsDir")
	if err := validateLsCommand(pluginDir); err != nil {
		return err
	}

	plugins := ls_getPlugins(pluginDir)

	if len(plugins) > 0 {
		logger.Info("installed plugins:\n")
	}

	for _, plugin := range plugins {
		logger.Infof("%s %s %s \n", plugin.Id, color.YellowString("@"), plugin.Info.Version)
	}

	return nil
}
Exemplo n.º 6
0
func listversionsCommand(c CommandLine) error {
	if err := validateVersionInput(c); err != nil {
		return err
	}

	pluginToList := c.Args().First()

	plugin, err := s.GetPlugin(pluginToList, c.GlobalString("repo"))
	if err != nil {
		return err
	}

	for _, i := range plugin.Versions {
		logger.Infof("%v\n", i.Version)
	}

	return nil
}
Exemplo n.º 7
0
func listremoteCommand(c CommandLine) error {
	plugin, err := s.ListAllPlugins(c.GlobalString("repo"))

	if err != nil {
		return err
	}

	for _, i := range plugin.Plugins {
		pluginVersion := ""
		if len(i.Versions) > 0 {
			pluginVersion = i.Versions[0].Version
		}

		logger.Infof("id: %v version: %s\n", i.Id, pluginVersion)
	}

	return nil
}
Exemplo n.º 8
0
func upgradeCommand(c CommandLine) error {
	pluginsDir := c.PluginDirectory()
	pluginName := c.Args().First()

	localPlugin, err := s.ReadPlugin(pluginsDir, pluginName)

	if err != nil {
		return err
	}

	v, err2 := s.GetPlugin(localPlugin.Id, c.RepoDirectory())

	if err2 != nil {
		return err2
	}

	if ShouldUpgrade(localPlugin.Info.Version, v) {
		s.RemoveInstalledPlugin(pluginsDir, pluginName)
		return InstallPlugin(localPlugin.Id, "", c)
	}

	logger.Infof("%s %s is up to date \n", color.GreenString("✔"), localPlugin.Id)
	return nil
}
Exemplo n.º 9
0
func RemoveInstalledPlugin(pluginPath, id string) error {
	logger.Infof("Removing plugin: %v\n", id)
	return IoHelper.RemoveAll(path.Join(pluginPath, id))
}