Esempio n. 1
0
func cmdRunMigrateAccounts() {
	if flagCmdMigrateAccounts {
		if len(flagFromAuth) == 0 || (flagFromAuth != "email" && flagFromAuth != "gitlab" && flagFromAuth != "saml") {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -from_auth")
			os.Exit(1)
		}

		if len(flagToAuth) == 0 || flagToAuth != "ldap" {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -from_auth")
			os.Exit(1)
		}

		// Email auth in Mattermost system is represented by ""
		if flagFromAuth == "email" {
			flagFromAuth = ""
		}

		if len(flagMatchField) == 0 || (flagMatchField != "email" && flagMatchField != "username") {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -match_field")
			os.Exit(1)
		}

		if migrate := einterfaces.GetAccountMigrationInterface(); migrate != nil {
			if err := migrate.MigrateToLdap(flagFromAuth, flagMatchField); err != nil {
				fmt.Println("ERROR: Account migration failed.")
				l4g.Error("%v", err.Error())
				flushLogAndExit(1)
			} else {
				fmt.Println("SUCCESS: Account migration complete.")
				flushLogAndExit(0)
			}
		}
	}
}
Esempio n. 2
0
func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
	initDBCommandContextCobra(cmd)
	if len(args) != 3 {
		return errors.New("Enter the correct number of arguments.")
	}

	fromAuth := args[0]
	toAuth := args[1]
	matchField := args[2]

	if len(fromAuth) == 0 || (fromAuth != "email" && fromAuth != "gitlab" && fromAuth != "saml") {
		return errors.New("Invalid from_auth argument")
	}

	if len(toAuth) == 0 || toAuth != "ldap" {
		return errors.New("Invalid to_auth argument")
	}

	// Email auth in Mattermost system is represented by ""
	if fromAuth == "email" {
		fromAuth = ""
	}

	if len(matchField) == 0 || (matchField != "email" && matchField != "username") {
		return errors.New("Invalid match_field argument")
	}

	if migrate := einterfaces.GetAccountMigrationInterface(); migrate != nil {
		if err := migrate.MigrateToLdap(fromAuth, matchField); err != nil {
			return errors.New("Error while migrating users: " + err.Error())
		} else {
			CommandPrettyPrintln("Sucessfully migrated accounts.")
		}
	}

	return nil
}